List of usage examples for org.eclipse.jdt.core.dom Statement getStartPosition
public final int getStartPosition()
From source file:br.uff.ic.gems.resources.ast.Visitor.java
@Override public boolean visit(DoStatement node) { int beginLine = cu.getLineNumber(node.getStartPosition()); int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength()); int beginColumn = cu.getColumnNumber(node.getStartPosition()); int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength()); Statement body = node.getBody(); if (body != null) { int beginLineBody = cu.getLineNumber(body.getStartPosition()); int endLineBody = cu.getLineNumber(body.getStartPosition() + body.getLength()); int beginColumnBody = cu.getColumnNumber(body.getStartPosition()); int endColumnBody = cu.getColumnNumber(body.getStartPosition() + body.getLength()); languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn, beginLineBody, endLineBody, beginColumnBody, endColumnBody, null)); } else {//from w w w.j a v a 2 s. c o m languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn)); } return true; }
From source file:br.uff.ic.gems.resources.ast.Visitor.java
@Override public boolean visit(EnhancedForStatement node) { int beginLine = cu.getLineNumber(node.getStartPosition()); int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength()); int beginColumn = cu.getColumnNumber(node.getStartPosition()); int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength()); Statement body = node.getBody(); if (body != null) { int beginLineBody = cu.getLineNumber(body.getStartPosition()); int endLineBody = cu.getLineNumber(body.getStartPosition() + body.getLength()); int beginColumnBody = cu.getColumnNumber(body.getStartPosition()); int endColumnBody = cu.getColumnNumber(body.getStartPosition() + body.getLength()); languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn, beginLineBody, endLineBody, beginColumnBody, endColumnBody, null)); } else {/*from w ww. j a v a 2 s . co m*/ languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn)); } return true; }
From source file:br.uff.ic.gems.resources.ast.Visitor.java
@Override public boolean visit(ForStatement node) { int beginLine = cu.getLineNumber(node.getStartPosition()); int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength()); int beginColumn = cu.getColumnNumber(node.getStartPosition()); int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength()); Statement body = node.getBody(); if (body != null) { int beginLineBody = cu.getLineNumber(body.getStartPosition()); int endLineBody = cu.getLineNumber(body.getStartPosition() + body.getLength()); int beginColumnBody = cu.getColumnNumber(body.getStartPosition()); int endColumnBody = cu.getColumnNumber(body.getStartPosition() + body.getLength()); languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn, beginLineBody, endLineBody, beginColumnBody, endColumnBody, null)); } else {/* w ww.j a va2 s .c o m*/ languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn)); } return true; }
From source file:br.uff.ic.gems.resources.ast.Visitor.java
@Override public boolean visit(WhileStatement node) { int beginLine = cu.getLineNumber(node.getStartPosition()); int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength()); int beginColumn = cu.getColumnNumber(node.getStartPosition()); int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength()); Statement body = node.getBody(); if (body != null) { int beginLineBody = cu.getLineNumber(body.getStartPosition()); int endLineBody = cu.getLineNumber(body.getStartPosition() + body.getLength()); int beginColumnBody = cu.getColumnNumber(body.getStartPosition()); int endColumnBody = cu.getColumnNumber(body.getStartPosition() + body.getLength()); languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn, beginLineBody, endLineBody, beginColumnBody, endColumnBody, null)); } else {//from ww w.j av a2 s . co m languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn)); } return true; }
From source file:br.uff.ic.gems.resources.ast.Visitor.java
public boolean visit(Statement node) { int beginLine = cu.getLineNumber(node.getStartPosition()); int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength()); int beginColumn = cu.getColumnNumber(node.getStartPosition()); int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength()); languageConstructs.add(/* w ww.j ava 2 s .c om*/ new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn)); return true; }
From source file:com.architexa.diagrams.relo.jdt.ParseUtilities.java
License:Open Source License
/** * @param method/* w w w.jav a 2s . c o m*/ * @return SourceRange * @throws JavaModelException */ public static ISourceRange getBodyRange(IMethod method) throws JavaModelException { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(method.getCompilationUnit()); CompilationUnit cu = (CompilationUnit) parser.createAST(null); TypeDeclaration td = findTypeDeclaration(cu, method); MethodDeclaration md = findMethodDeclaration(td, method); Block body = md.getBody(); final int startPos; final int length; List<?> bodyStatements = body.statements(); int stmnts = bodyStatements.size(); if (stmnts > 0) { startPos = ((Statement) bodyStatements.get(0)).getStartPosition(); Statement lastStmnt = (Statement) bodyStatements.get(stmnts - 1); length = lastStmnt.getStartPosition() + lastStmnt.getLength() - startPos; } else { startPos = body.getStartPosition(); length = body.getLength(); } return new ISourceRange() { public int getLength() { return length; } public int getOffset() { return startPos; } }; }
From source file:com.chookapp.org.bracketeer.jdt.ClosingBracketHintVisitor.java
License:Open Source License
private boolean visitBreak(Statement node) { try {/*from www . j a v a 2 s . co m*/ if (_scopeStack.isEmpty()) throw new ScopeTraceException("break without scope: " + node); //$NON-NLS-1$ ScopeInfo scope = _scopeStack.peek(); if (node instanceof BreakStatement) { // ignoring break with labels on them if (((BreakStatement) node).getLabel() != null) return shouldContinue(); } String hintType; if (scope._statement instanceof ForStatement) hintType = "break-for"; //$NON-NLS-1$ else if (scope._statement instanceof EnhancedForStatement) hintType = "break-foreach"; //$NON-NLS-1$ else if (scope._statement instanceof WhileStatement) hintType = "break-while"; //$NON-NLS-1$ else if (scope._statement instanceof DoStatement) hintType = "break-do"; //$NON-NLS-1$ else if (scope._statement instanceof SwitchCase) hintType = "break-case"; //$NON-NLS-1$ else throw new ScopeTraceException( "Unexpect scope (" + scope._statement + ") on break/continue:" + node); //$NON-NLS-1$ //$NON-NLS-2$ int endLoc = node.getStartPosition() + node.getLength() - 1; _container.add(new Hint(hintType, scope._offset, endLoc, scope._str)); } catch (ScopeTraceException e) { if (Activator.DEBUG) Activator.log(e); } catch (BadLocationException e) { _cancelProcessing.set(true); } return shouldContinue(); }
From source file:com.chookapp.org.bracketeer.jdt.ClosingBracketHintVisitor.java
License:Open Source License
@Override public boolean visit(IfStatement node) { Statement thenStmt = node.getThenStatement(); Statement elseStmt = node.getElseStatement(); String hint = GetNodeText(node.getExpression()); boolean showIfHint = (elseStmt == null); int endLoc = -1; try {//from ww w . j a v a 2 s . com if (!showIfHint) { if (_doc.getLineOfOffset(elseStmt.getStartPosition()) != _doc .getLineOfOffset(thenStmt.getStartPosition() + thenStmt.getLength())) { showIfHint = true; } // if the else looks like this "} else {", then show the hint on the "{" if (!showIfHint && !(elseStmt instanceof IfStatement)) { endLoc = elseStmt.getStartPosition(); showIfHint = true; } } if (showIfHint && !(thenStmt instanceof Block)) showIfHint = false; if (showIfHint) { if (endLoc == -1) endLoc = thenStmt.getStartPosition() + thenStmt.getLength() - 1; int startLoc = node.getStartPosition(); _container.add(new Hint("if", startLoc, endLoc, "if( " + hint + " )")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } if (elseStmt != null && !(elseStmt instanceof IfStatement) && (elseStmt instanceof Block)) { endLoc = elseStmt.getStartPosition() + elseStmt.getLength() - 1; int startLoc = elseStmt.getStartPosition(); _container.add(new Hint("if", startLoc, endLoc, "else_of_if( " + hint + " )")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } catch (BadLocationException e) { _cancelProcessing.set(true); } return shouldContinue(); }
From source file:com.google.gdt.eclipse.designer.gxt.model.widgets.GridInfo.java
License:Open Source License
private ColumnsBinder createColumnAsListBinder() { return new ColumnsBinder() { @Override/*from w w w . ja v a2s . c o m*/ void bindColumnObjects() throws Exception { // Adds <code>ColumnConfig</code> objects into <code>ColumnModel</code>. Object grid = getObject(); Object model = ReflectionUtils.getFieldObject(grid, "cm"); Object modelColumns = ReflectionUtils.getFieldObject(model, "configs"); for (ColumnConfigInfo column : getColumns()) { ReflectionUtils.invokeMethod(modelColumns, "add(java.lang.Object)", column.getObject()); } } @Override void create(ColumnConfigInfo column, ColumnConfigInfo nextColumn) throws Exception { SimpleName columnsList = ensureColumnsList(); ColumnConfigAssociation association = new ColumnConfigAssociation(columnsList); AssociationObject associationObject = new AssociationObject(association, true); if (nextColumn == null) { Statement columnsListUsageStatement = AstNodeUtils.getEnclosingStatement(columnsList); StatementTarget target = new StatementTarget(columnsListUsageStatement, true); JavaInfoUtils.addTarget(column, associationObject, GridInfo.this, target); } else { JavaInfoUtils.add(column, associationObject, GridInfo.this, nextColumn); } } @Override void move(ColumnConfigInfo column, ColumnConfigInfo nextColumn) throws Exception { SimpleName columnsList = ensureColumnsList(); ColumnConfigAssociation association = new ColumnConfigAssociation(columnsList); AssociationObject associationObject = new AssociationObject(association, true); if (nextColumn == null) { Statement columnsListUsageStatement = AstNodeUtils.getEnclosingStatement(columnsList); StatementTarget target = new StatementTarget(columnsListUsageStatement, true); JavaInfoUtils.moveTarget(column, associationObject, GridInfo.this, null, target); } else { JavaInfoUtils.move(column, associationObject, GridInfo.this, nextColumn); } } SimpleName ensureColumnsList() throws Exception { ClassInstanceCreation columnModelCreation = getColumnModelCreation(true); // "columns" List usage in "ColumnModel" creation List<Expression> columnModelArguments = DomGenerics.arguments(columnModelCreation); Expression columnsList = columnModelArguments.get(0); if (columnsList instanceof SimpleName) { return (SimpleName) columnsList; } // if no columns then generate new ArrayList Statement columnModelStatement = AstNodeUtils.getEnclosingStatement(columnModelCreation); StatementTarget target = new StatementTarget(columnModelStatement, true); String configsName = getEditor().getUniqueVariableName(columnModelStatement.getStartPosition(), "configs", null); getEditor().addStatement( MessageFormat.format("java.util.List<{0}> {1} = new java.util.ArrayList<{0}>();", "com.extjs.gxt.ui.client.widget.grid.ColumnConfig", configsName), target); return (SimpleName) getEditor().replaceExpression(columnsList, configsName); } }; }
From source file:edu.illinois.jflow.core.transformations.code.ExtractClosureRefactoring.java
License:Open Source License
List<Integer> getEnclosingLoopLines() { List<Integer> lines = new ArrayList<Integer>(); Statement forLoop = locateEnclosingLoopStatement(); // IDocument starts counting from 0 but we want to follow what the user sees in the editor // that starts from 1. try {//from ww w . j a v a 2s. c om if (forLoop instanceof ForStatement) { ForStatement forStmt = (ForStatement) forLoop; int start = fDoc.getLineOfOffset(forLoop.getStartPosition()) + 1; int end = fDoc.getLineOfOffset(forStmt.getBody().getStartPosition()) + 1; for (int line = start; line <= end; line++) { lines.add(line); } } if (forLoop instanceof EnhancedForStatement) { EnhancedForStatement forStmt = (EnhancedForStatement) forLoop; int start = fDoc.getLineOfOffset(forStmt.getStartPosition()) + 1; int end = fDoc.getLineOfOffset(forStmt.getBody().getStartPosition()) + 1; for (int line = start; line <= end; line++) { lines.add(line); } } } catch (BadLocationException e) { e.printStackTrace(); } return lines; }