private static boolean isForStatementUpdate(Tree lastElement, Tree loop) { return loop.is(Tree.Kind.FOR_STATEMENT) && isDescendant(lastElement, ((ForStatementTree) loop).update()); }
private static Collection<Symbol> symbolsFromConditionsNotUpdated(ForStatementTree forStatementTree) { Collection<Symbol> symbols = getConditionSymbols(forStatementTree.condition()); symbols.removeAll(getUpdatedSymbols(forStatementTree.update())); return symbols; }
@Override public void visitNode(Tree tree) { if (tree.is(Tree.Kind.METHOD_INVOCATION)) { super.visitNode(tree); } else if(tree.is(Tree.Kind.FOR_STATEMENT)) { ForStatementTree fst = (ForStatementTree) tree; inWhileLoop.push(fst.initializer().isEmpty() && fst.condition()==null && fst.update().isEmpty()); } else { inWhileLoop.push(true); } }
private static Collection<Symbol> symbolsFromConditionsNotUpdated(ForStatementTree forStatementTree) { Collection<Symbol> symbols = getConditionSymbols(forStatementTree.condition()); symbols.removeAll(getUpdatedSymbols(forStatementTree.update())); return symbols; }
@Override public void visitNode(Tree tree) { if (tree.is(Tree.Kind.METHOD_INVOCATION)) { super.visitNode(tree); } else if (tree.is(Tree.Kind.FOR_STATEMENT)) { ForStatementTree fst = (ForStatementTree) tree; inWhileLoop.push(fst.initializer().isEmpty() && fst.condition() == null && fst.update().isEmpty()); } else { inWhileLoop.push(true); } }
@Override public void visitForStatement(ForStatementTree tree) { statements++; super.visitForStatement(tree); removeVariable(tree.initializer()); removeVariable(tree.update()); }
@Override public void visitForStatement(ForStatementTree tree) { statements++; super.visitForStatement(tree); removeVariable(tree.initializer()); removeVariable(tree.update()); }
@Override public void visitForStatement(ForStatementTree tree) { statements++; super.visitForStatement(tree); removeVariable(tree.initializer()); removeVariable(tree.update()); }
@Override public void visitForStatement(ForStatementTree tree) { Set<String> pendingLoopCounters = Sets.newHashSet(); for (StatementTree statementTree : tree.initializer()) { if (statementTree.is(Tree.Kind.VARIABLE)) { pendingLoopCounters.add(((VariableTree) statementTree).simpleName().name()); } } scan(tree.initializer()); scan(tree.condition()); scan(tree.update()); loopCounters.addAll(pendingLoopCounters); scan(tree.statement()); loopCounters.removeAll(pendingLoopCounters); }
@Override public void visitForStatement(ForStatementTree tree) { // Updates in initializer are not of interest scan(tree.condition()); scan(tree.update()); scan(tree.statement()); }
private void checkIncrement(ForStatementTree forStatement, IdentifierTree loopIdentifier, boolean positiveIncrement) { if (forStatement.update().size() <= 1) { ForLoopIncrement loopIncrement = ForLoopIncrement.findInUpdates(forStatement); if (loopIncrement == null || !loopIncrement.hasSameIdentifier(loopIdentifier)) { addIssue(forStatement); } else if (loopIncrement.hasValue()) { int requiredIncrement = positiveIncrement ? 1 : -1; if (loopIncrement.value() != requiredIncrement || forBodyUpdatesLoopIdentifier(forStatement, loopIdentifier)) { addIssue(forStatement); } } } }
@Override public void visitForStatement(ForStatementTree tree) { // Updates in initializer are not of interest scan(tree.condition()); scan(tree.update()); scan(tree.statement()); }
@Override public void visitNode(Tree tree) { ForStatementTree forStatementTree = (ForStatementTree) tree; if (forStatementTree.initializer().isEmpty() && forStatementTree.update().isEmpty() && forStatementTree.condition() != null) { context.reportIssue(this, forStatementTree.forKeyword(), "Replace this \"for\" loop with a \"while\" loop."); } } }
@Override public void visitNode(Tree tree) { ForStatementTree forStatementTree = (ForStatementTree) tree; if (forStatementTree.initializer().isEmpty() && forStatementTree.update().isEmpty() && forStatementTree.condition() != null) { context.reportIssue(this, forStatementTree.forKeyword(), "Replace this \"for\" loop with a \"while\" loop."); } } }
@Override public void visitForStatement(ForStatementTree tree) { scan(tree.initializer()); scan(tree.condition()); scan(tree.update()); scan(tree.statement()); }
@Override public void visitForStatement(ForStatementTree tree) { scan(tree.condition()); scan(tree.initializer()); scan(tree.update()); visitStatement(tree.statement()); }
@Override public void visitForStatement(ForStatementTree tree) { scan(tree.initializer()); scan(tree.condition()); scan(tree.update()); scan(tree.statement()); }
@Override public void visitForStatement(ForStatementTree tree) { scan(tree.initializer()); scan(tree.condition()); scan(tree.update()); scan(tree.statement()); }
@Override public void visitForStatement(ForStatementTree tree) { addKind(tree.forKeyword(), UastNode.Kind.FOR_KEYWORD); addKind(tree.initializer(), UastNode.Kind.FOR_INIT); addKind(tree.update(), UastNode.Kind.FOR_UPDATE); addKind(tree.statement(), UastNode.Kind.BODY); super.visitForStatement(tree); }
private void checkIncrement(ForStatementTree forStatement, IdentifierTree loopIdentifier, boolean positiveIncrement) { if (forStatement.update().size() <= 1) { ForLoopIncrement loopIncrement = ForLoopIncrement.findInUpdates(forStatement); if (loopIncrement == null || !loopIncrement.hasSameIdentifier(loopIdentifier)) { addIssue(forStatement); } else if (loopIncrement.hasValue()) { int requiredIncrement = positiveIncrement ? 1 : -1; if (loopIncrement.value() != requiredIncrement || forBodyUpdatesLoopIdentifier(forStatement, loopIdentifier)) { addIssue(forStatement); } } } }