org.eclipse.jdt.core.dom.DoStatement Java Examples
The following examples show how to use
org.eclipse.jdt.core.dom.DoStatement.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractLoop.java From JDeodorant with MIT License | 6 votes |
public Statement getLoopBody() { if (loopStatement instanceof WhileStatement) { return ((WhileStatement)loopStatement).getBody(); } else if (loopStatement instanceof ForStatement) { return ((ForStatement)loopStatement).getBody(); } else if (loopStatement instanceof DoStatement) { return ((DoStatement)loopStatement).getBody(); } else if (loopStatement instanceof EnhancedForStatement) { return ((EnhancedForStatement)loopStatement).getBody(); } return null; }
Example #2
Source File: ASTNodeMatcher.java From JDeodorant with MIT License | 6 votes |
private static AbstractLoop generateAbstractLoop(Object object) { if (object instanceof ForStatement) { return new ConditionalLoop((ForStatement) object); } else if (object instanceof WhileStatement) { return new ConditionalLoop((WhileStatement) object); } else if (object instanceof DoStatement) { return new ConditionalLoop((DoStatement) object); } else if (object instanceof EnhancedForStatement) { return new EnhancedForLoop((EnhancedForStatement) object); } return null; }
Example #3
Source File: LoopFragmentExporter.java From txtUML with Eclipse Public License 1.0 | 6 votes |
@Override public boolean preNext(Statement curElement) { switch (curElement.getNodeType()) { case ASTNode.WHILE_STATEMENT: exportWhile((WhileStatement) curElement); break; case ASTNode.FOR_STATEMENT: exportFor((ForStatement) curElement); break; case ASTNode.ENHANCED_FOR_STATEMENT: exportForEach((EnhancedForStatement) curElement); break; case ASTNode.DO_STATEMENT: exportDoWhileStatement((DoStatement) curElement); break; } return true; }
Example #4
Source File: AdvancedQuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static boolean isLastStatementInEnclosingMethodOrLambda(Statement statement) { ASTNode currentStructure= statement; ASTNode currentParent= statement.getParent(); while (!(currentParent instanceof MethodDeclaration || currentParent instanceof LambdaExpression)) { // should not be in a loop if (currentParent instanceof ForStatement || currentParent instanceof EnhancedForStatement || currentParent instanceof WhileStatement || currentParent instanceof DoStatement) { return false; } if (currentParent instanceof Block) { Block parentBlock= (Block) currentParent; if (parentBlock.statements().indexOf(currentStructure) != parentBlock.statements().size() - 1) { // not last statement in the block return false; } } currentStructure= currentParent; currentParent= currentParent.getParent(); } return true; }
Example #5
Source File: ExtractMethodAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private Statement getParentLoopBody(ASTNode node) { Statement stmt = null; ASTNode start = node; while (start != null && !(start instanceof ForStatement) && !(start instanceof DoStatement) && !(start instanceof WhileStatement) && !(start instanceof EnhancedForStatement) && !(start instanceof SwitchStatement)) { start = start.getParent(); } if (start instanceof ForStatement) { stmt = ((ForStatement) start).getBody(); } else if (start instanceof DoStatement) { stmt = ((DoStatement) start).getBody(); } else if (start instanceof WhileStatement) { stmt = ((WhileStatement) start).getBody(); } else if (start instanceof EnhancedForStatement) { stmt = ((EnhancedForStatement) start).getBody(); } if (start != null && start.getParent() instanceof LabeledStatement) { LabeledStatement labeledStatement = (LabeledStatement) start.getParent(); fEnclosingLoopLabel = labeledStatement.getLabel(); } return stmt; }
Example #6
Source File: ExtractMethodAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public boolean visit(DoStatement node) { boolean result = super.visit(node); try { int actionStart = getTokenScanner().getTokenEndOffset(ITerminalSymbols.TokenNamedo, node.getStartPosition()); if (getSelection().getOffset() == actionStart) { invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_after_do_keyword, JavaStatusContext.create(fCUnit, getSelection())); return false; } } catch (CoreException e) { // ignore } return result; }
Example #7
Source File: NecessaryParenthesesChecker.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) { if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) { // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ... return false; } if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY || locationInParent == ReturnStatement.EXPRESSION_PROPERTY || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY || locationInParent == ForStatement.EXPRESSION_PROPERTY || locationInParent == WhileStatement.EXPRESSION_PROPERTY || locationInParent == DoStatement.EXPRESSION_PROPERTY || locationInParent == AssertStatement.EXPRESSION_PROPERTY || locationInParent == AssertStatement.MESSAGE_PROPERTY || locationInParent == IfStatement.EXPRESSION_PROPERTY || locationInParent == SwitchStatement.EXPRESSION_PROPERTY || locationInParent == SwitchCase.EXPRESSION_PROPERTY || locationInParent == ArrayAccess.INDEX_PROPERTY || locationInParent == ThrowStatement.EXPRESSION_PROPERTY || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) { return false; } return true; }
Example #8
Source File: SequenceDiagramVisitor.java From txtUML with Eclipse Public License 1.0 | 6 votes |
private void checkSendInLoopNode(Statement loopNode) { Statement body; if (loopNode instanceof WhileStatement) { WhileStatement whileLoop = (WhileStatement) loopNode; body = whileLoop.getBody(); } else if (loopNode instanceof ForStatement) { ForStatement forLoop = (ForStatement) loopNode; body = forLoop.getBody(); } else { DoStatement doWhileLoop = (DoStatement) loopNode; body = doWhileLoop.getBody(); } boolean showErrorHere = placeOfError == loopNode; if (showErrorHere) { placeOfError = body; } if (body instanceof Block) { checkSendInBlock((Block) body, showErrorHere); } else { checkSendInStatement(body); } }
Example #9
Source File: ExtractMethodAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private Statement getParentLoopBody(ASTNode node) { Statement stmt= null; ASTNode start= node; while (start != null && !(start instanceof ForStatement) && !(start instanceof DoStatement) && !(start instanceof WhileStatement) && !(start instanceof EnhancedForStatement) && !(start instanceof SwitchStatement)) { start= start.getParent(); } if (start instanceof ForStatement) { stmt= ((ForStatement)start).getBody(); } else if (start instanceof DoStatement) { stmt= ((DoStatement)start).getBody(); } else if (start instanceof WhileStatement) { stmt= ((WhileStatement)start).getBody(); } else if (start instanceof EnhancedForStatement) { stmt= ((EnhancedForStatement)start).getBody(); } if (start != null && start.getParent() instanceof LabeledStatement) { LabeledStatement labeledStatement= (LabeledStatement)start.getParent(); fEnclosingLoopLabel= labeledStatement.getLabel(); } return stmt; }
Example #10
Source File: ExtractMethodAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public boolean visit(DoStatement node) { boolean result= super.visit(node); try { int actionStart= getTokenScanner().getTokenEndOffset(ITerminalSymbols.TokenNamedo, node.getStartPosition()); if (getSelection().getOffset() == actionStart) { invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_after_do_keyword, JavaStatusContext.create(fCUnit, getSelection())); return false; } } catch (CoreException e) { // ignore } return result; }
Example #11
Source File: SourceProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public boolean isDangligIf() { List<Statement> statements= fDeclaration.getBody().statements(); if (statements.size() != 1) return false; ASTNode p= statements.get(0); while (true) { if (p instanceof IfStatement) { return ((IfStatement) p).getElseStatement() == null; } else { ChildPropertyDescriptor childD; if (p instanceof WhileStatement) { childD= WhileStatement.BODY_PROPERTY; } else if (p instanceof ForStatement) { childD= ForStatement.BODY_PROPERTY; } else if (p instanceof EnhancedForStatement) { childD= EnhancedForStatement.BODY_PROPERTY; } else if (p instanceof DoStatement) { childD= DoStatement.BODY_PROPERTY; } else if (p instanceof LabeledStatement) { childD= LabeledStatement.BODY_PROPERTY; } else { return false; } Statement body= (Statement) p.getStructuralProperty(childD); if (body instanceof Block) { return false; } else { p= body; } } } }
Example #12
Source File: CodeSearch.java From SimFix with GNU General Public License v2.0 | 5 votes |
public boolean visit(DoStatement node) { int start = _unit.getLineNumber(node.getExpression().getStartPosition()); if(start == _extendedLine){ _extendedStatement = node; return false; } return true; }
Example #13
Source File: InputFlowAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void endVisit(DoStatement node) { if (skipNode(node)) return; DoWhileFlowInfo info= createDoWhile(); setFlowInfo(node, info); info.mergeAction(getFlowInfo(node.getBody()), fFlowContext); // No need to merge the condition. It was already considered by the InputFlowAnalyzer. info.removeLabel(null); }
Example #14
Source File: FlowAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void endVisit(DoStatement node) { if (skipNode(node)) return; DoWhileFlowInfo info= createDoWhile(); setFlowInfo(node, info); info.mergeAction(getFlowInfo(node.getBody()), fFlowContext); info.mergeCondition(getFlowInfo(node.getExpression()), fFlowContext); info.removeLabel(null); }
Example #15
Source File: ExtractTempRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void insertAt(ASTNode target, Statement declaration) { ASTRewrite rewrite= fCURewrite.getASTRewrite(); TextEditGroup groupDescription= fCURewrite.createGroupDescription(RefactoringCoreMessages.ExtractTempRefactoring_declare_local_variable); ASTNode parent= target.getParent(); StructuralPropertyDescriptor locationInParent= target.getLocationInParent(); while (locationInParent != Block.STATEMENTS_PROPERTY && locationInParent != SwitchStatement.STATEMENTS_PROPERTY) { if (locationInParent == IfStatement.THEN_STATEMENT_PROPERTY || locationInParent == IfStatement.ELSE_STATEMENT_PROPERTY || locationInParent == ForStatement.BODY_PROPERTY || locationInParent == EnhancedForStatement.BODY_PROPERTY || locationInParent == DoStatement.BODY_PROPERTY || locationInParent == WhileStatement.BODY_PROPERTY) { // create intermediate block if target was the body property of a control statement: Block replacement= rewrite.getAST().newBlock(); ListRewrite replacementRewrite= rewrite.getListRewrite(replacement, Block.STATEMENTS_PROPERTY); replacementRewrite.insertFirst(declaration, null); replacementRewrite.insertLast(rewrite.createMoveTarget(target), null); rewrite.replace(target, replacement, groupDescription); return; } target= parent; parent= parent.getParent(); locationInParent= target.getLocationInParent(); } ListRewrite listRewrite= rewrite.getListRewrite(parent, (ChildListPropertyDescriptor)locationInParent); listRewrite.insertBefore(declaration, target, groupDescription); }
Example #16
Source File: StatementAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void endVisit(DoStatement node) { ASTNode[] selectedNodes= getSelectedNodes(); if (doAfterValidation(node, selectedNodes)) { if (contains(selectedNodes, node.getBody()) && contains(selectedNodes, node.getExpression())) { invalidSelection(RefactoringCoreMessages.StatementAnalyzer_do_body_expression); } } super.endVisit(node); }
Example #17
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns true if a node at a given location is a body of a control statement. Such body nodes are * interesting as when replacing them, it has to be evaluates if a Block is needed instead. * E.g. <code> if (x) do(); -> if (x) { do1(); do2() } </code> * * @param locationInParent Location of the body node * @return Returns true if the location is a body node location of a control statement. */ public static boolean isControlStatementBody(StructuralPropertyDescriptor locationInParent) { return locationInParent == IfStatement.THEN_STATEMENT_PROPERTY || locationInParent == IfStatement.ELSE_STATEMENT_PROPERTY || locationInParent == ForStatement.BODY_PROPERTY || locationInParent == EnhancedForStatement.BODY_PROPERTY || locationInParent == WhileStatement.BODY_PROPERTY || locationInParent == DoStatement.BODY_PROPERTY; }
Example #18
Source File: AdvancedQuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static Expression getBooleanExpression(ASTNode node) { if (!(node instanceof Expression)) { return null; } // check if the node is a location where it can be negated StructuralPropertyDescriptor locationInParent= node.getLocationInParent(); if (locationInParent == QualifiedName.NAME_PROPERTY) { node= node.getParent(); locationInParent= node.getLocationInParent(); } while (locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) { node= node.getParent(); locationInParent= node.getLocationInParent(); } Expression expression= (Expression) node; if (!isBoolean(expression)) { return null; } if (expression.getParent() instanceof InfixExpression) { return expression; } if (locationInParent == Assignment.RIGHT_HAND_SIDE_PROPERTY || locationInParent == IfStatement.EXPRESSION_PROPERTY || locationInParent == WhileStatement.EXPRESSION_PROPERTY || locationInParent == DoStatement.EXPRESSION_PROPERTY || locationInParent == ReturnStatement.EXPRESSION_PROPERTY || locationInParent == ForStatement.EXPRESSION_PROPERTY || locationInParent == AssertStatement.EXPRESSION_PROPERTY || locationInParent == MethodInvocation.ARGUMENTS_PROPERTY || locationInParent == ConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == SuperMethodInvocation.ARGUMENTS_PROPERTY || locationInParent == EnumConstantDeclaration.ARGUMENTS_PROPERTY || locationInParent == SuperConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == ClassInstanceCreation.ARGUMENTS_PROPERTY || locationInParent == ConditionalExpression.EXPRESSION_PROPERTY || locationInParent == PrefixExpression.OPERAND_PROPERTY) { return expression; } return null; }
Example #19
Source File: ASTNodeMatcher.java From JDeodorant with MIT License | 5 votes |
protected boolean isInfixExpressionWithCompositeParent(ASTNode node) { if(node instanceof InfixExpression && (node.getParent() instanceof IfStatement || node.getParent() instanceof InfixExpression || node.getParent() instanceof WhileStatement || node.getParent() instanceof DoStatement || node.getParent() instanceof ForStatement)) { return true; } return false; }
Example #20
Source File: ASTNodeMatcher.java From JDeodorant with MIT License | 5 votes |
public boolean match(DoStatement node, Object other) { if (other instanceof DoStatement) { DoStatement o = (DoStatement) other; if(isNestedUnderAnonymousClassDeclaration(node) && isNestedUnderAnonymousClassDeclaration(o)) { return super.match(node, o); } if (safeSubtreeMatch(node.getExpression(), o.getExpression())) { return true; } } ConditionalLoop nodeConditionalLoop = new ConditionalLoop(node); return loopMatch(nodeConditionalLoop, other); }
Example #21
Source File: ConditionalLoop.java From JDeodorant with MIT License | 5 votes |
public ConditionalLoop(DoStatement doStatement) { super(doStatement); this.condition = doStatement.getExpression(); Statement loopBody = doStatement.getBody(); List<Expression> forUpdaters = new ArrayList<Expression>(); this.conditionControlVariables = generateConditionControlVariables(this.condition, loopBody, forUpdaters); }
Example #22
Source File: StyledStringVisitor.java From JDeodorant with MIT License | 5 votes |
public boolean visit(DoStatement stmnt){ /* * do Statement while ( Expression ) ; */ styledString.append("do", new StyledStringStyler(keywordStyle)); appendSpace(); styledString.append("while", new StyledStringStyler(keywordStyle)); appendOpenParenthesis(); handleExpression((Expression) stmnt.getExpression()); appendClosedParenthesis(); return false; }
Example #23
Source File: InputFlowAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public void endVisit(DoStatement node) { if (skipNode(node)) { return; } DoWhileFlowInfo info = createDoWhile(); setFlowInfo(node, info); info.mergeAction(getFlowInfo(node.getBody()), fFlowContext); // No need to merge the condition. It was already considered by the InputFlowAnalyzer. info.removeLabel(null); }
Example #24
Source File: FlowAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public void endVisit(DoStatement node) { if (skipNode(node)) { return; } DoWhileFlowInfo info = createDoWhile(); setFlowInfo(node, info); info.mergeAction(getFlowInfo(node.getBody()), fFlowContext); info.mergeCondition(getFlowInfo(node.getExpression()), fFlowContext); info.removeLabel(null); }
Example #25
Source File: InvertBooleanUtility.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static Expression getBooleanExpression(ASTNode node) { if (!(node instanceof Expression)) { return null; } // check if the node is a location where it can be negated StructuralPropertyDescriptor locationInParent = node.getLocationInParent(); if (locationInParent == QualifiedName.NAME_PROPERTY) { node = node.getParent(); locationInParent = node.getLocationInParent(); } while (locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) { node = node.getParent(); locationInParent = node.getLocationInParent(); } Expression expression = (Expression) node; if (!isBoolean(expression)) { return null; } if (expression.getParent() instanceof InfixExpression) { return expression; } if (locationInParent == Assignment.RIGHT_HAND_SIDE_PROPERTY || locationInParent == IfStatement.EXPRESSION_PROPERTY || locationInParent == WhileStatement.EXPRESSION_PROPERTY || locationInParent == DoStatement.EXPRESSION_PROPERTY || locationInParent == ReturnStatement.EXPRESSION_PROPERTY || locationInParent == ForStatement.EXPRESSION_PROPERTY || locationInParent == AssertStatement.EXPRESSION_PROPERTY || locationInParent == MethodInvocation.ARGUMENTS_PROPERTY || locationInParent == ConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == SuperMethodInvocation.ARGUMENTS_PROPERTY || locationInParent == EnumConstantDeclaration.ARGUMENTS_PROPERTY || locationInParent == SuperConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == ClassInstanceCreation.ARGUMENTS_PROPERTY || locationInParent == ConditionalExpression.EXPRESSION_PROPERTY || locationInParent == PrefixExpression.OPERAND_PROPERTY) { return expression; } return null; }
Example #26
Source File: JavaASTFlattener.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public boolean visit(final DoStatement node) { this.appendToBuffer("do "); node.getBody().accept(this); this.appendToBuffer(" while ("); node.getExpression().accept(this); this.appendToBuffer(")"); return false; }
Example #27
Source File: CodeBlock.java From SimFix with GNU General Public License v2.0 | 5 votes |
private DoStmt visit(DoStatement node) { int startLine = _cunit.getLineNumber(node.getStartPosition()); int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength()); DoStmt doStmt = new DoStmt(startLine, endLine, node); Expr expression = (Expr) process(node.getExpression()); expression.setParent(doStmt); doStmt.setExpression(expression); Stmt stmt = (Stmt) process(node.getBody()); stmt.setParent(doStmt); doStmt.setBody(stmt); return doStmt; }
Example #28
Source File: AstVisitor.java From jdt2famix with Eclipse Public License 1.0 | 5 votes |
/** * We create this access explicitly to catch a boolean variable used in * condition. Complicated expressions are handled in * {@link #visit(InfixExpression)} */ @Override public boolean visit(DoStatement node) { if (importer.topFromContainerStack(Method.class) != null) { importer.topFromContainerStack(Method.class).incCyclomaticComplexity(); importer.createAccessFromExpression((Expression) node.getExpression()); } return true; }
Example #29
Source File: BuggyCode.java From SimFix with GNU General Public License v2.0 | 4 votes |
public boolean process(Statement statement) { // TODO : wait for completing ... int start = _unit.getLineNumber(statement.getStartPosition()); int end = _unit.getLineNumber(statement.getStartPosition() + statement.getLength()); if (start <= _buggyLine && _buggyLine <= end) { if (statement instanceof IfStatement || statement instanceof ForStatement || statement instanceof WhileStatement || statement instanceof DoStatement || statement instanceof EnhancedForStatement) { _nodes.add(statement); return false; } else if(statement instanceof Block){ if(statement.getParent() instanceof IfStatement && (end - start) < Constant.MAX_BLOCK_LINE){ _nodes.add(statement.getParent()); return true; } Block block = (Block) statement; for(Object object : block.statements()){ process((Statement)object); } } else if(statement instanceof SwitchStatement){ SwitchStatement switchStmt = (SwitchStatement) statement; for(int i = 0; i < switchStmt.statements().size(); i++){ Statement stmt = (Statement) switchStmt.statements().get(i); int s = _unit.getLineNumber(stmt.getStartPosition()); int e = _unit.getLineNumber(stmt.getStartPosition() + stmt.getLength()); if(s <= _buggyLine && _buggyLine <= e){ _nodes.add(stmt); if(stmt instanceof SwitchCase){ for(int j = i + 1 ; j < switchStmt.statements().size(); j++){ Statement SC = (Statement) switchStmt.statements().get(j); if(SC instanceof SwitchCase){ return false; } else { _nodes.add(SC); } } } else { _nodes.add(stmt); return false; } } } } else { _nodes.add(statement); return false; } } return true; }
Example #30
Source File: ControlVariable.java From JDeodorant with MIT License | 4 votes |
private static List<ASTNode> getValueContributingModifiers(SimpleName variable) { List<ASTNode> allVariableModifiers = getAllVariableModifiersInParentMethod(variable); List<ASTNode> contributingModifiers = new ArrayList<ASTNode>(); boolean noModifierInLowerScope = true; MethodDeclaration parentMethod = AbstractLoopUtilities.findParentMethodDeclaration(variable); // create a list of all parents of the specified variable until the root method List<ASTNode> variableParents = new ArrayList<ASTNode>(); ASTNode currentVariableParent = variable.getParent(); while (currentVariableParent != null && currentVariableParent != parentMethod) { variableParents.add(currentVariableParent); currentVariableParent = currentVariableParent.getParent(); } variableParents.add(parentMethod); // we traverse allVariableModifiers and build a list of nodes that will influence the final value Iterator<ASTNode> it = allVariableModifiers.iterator(); while (it.hasNext()) { ASTNode currentNode = it.next(); boolean currentNodeAdded = false; // if the current node is the declaration or an assignment, the list restarts the modifiers. if it is a plus, minus, times, or divide equals, then it adds to the modifiers if (currentNode instanceof VariableDeclaration) { contributingModifiers = new ArrayList<ASTNode>(); contributingModifiers.add(currentNode); currentNodeAdded = true; noModifierInLowerScope = true; } else if (currentNode instanceof Assignment) { Assignment assignment = (Assignment) currentNode; Assignment.Operator operator = assignment.getOperator(); if (operator == Assignment.Operator.ASSIGN) { contributingModifiers = new ArrayList<ASTNode>(); contributingModifiers.add(currentNode); currentNodeAdded = true; noModifierInLowerScope = true; } else if (operator == Assignment.Operator.PLUS_ASSIGN || operator == Assignment.Operator.MINUS_ASSIGN || operator == Assignment.Operator.TIMES_ASSIGN || operator == Assignment.Operator.DIVIDE_ASSIGN) { contributingModifiers.add(currentNode); currentNodeAdded = true; } } else if (currentNode instanceof PrefixExpression || currentNode instanceof PostfixExpression) { contributingModifiers.add(currentNode); currentNodeAdded = true; } else if (currentNode instanceof MethodInvocation) { MethodInvocation currentMethodInvocation = (MethodInvocation) currentNode; AbstractLoopBindingInformation bindingInformation = AbstractLoopBindingInformation.getInstance(); String currentMethodBindingKey = currentMethodInvocation.resolveMethodBinding().getMethodDeclaration().getKey(); if (bindingInformation.updateMethodValuesContains(currentMethodBindingKey)) { contributingModifiers.add(currentNode); currentNodeAdded = true; } } // if currentNode was added, move up through it's parents until the first block or conditional parent and check if it is in the variableParents list, if not, it is in a lower scope if (currentNodeAdded) { ASTNode currentNodeParent = currentNode.getParent(); while (currentNodeParent != null) { if ((currentNodeParent instanceof MethodDeclaration || currentNodeParent instanceof IfStatement || currentNodeParent instanceof ForStatement || currentNodeParent instanceof WhileStatement || currentNodeParent instanceof DoStatement || currentNodeParent instanceof EnhancedForStatement || currentNodeParent instanceof SwitchStatement || currentNodeParent instanceof TryStatement)) { if (!variableParents.contains(currentNodeParent)) { noModifierInLowerScope = false; } break; } currentNodeParent = currentNodeParent.getParent(); } } } // return constructed list if all modifiers are in same or higher scope if (noModifierInLowerScope) { return contributingModifiers; } return new ArrayList<ASTNode>(); }