private static boolean isInfiniteFor(IterationStatementTree loopTree) { if (loopTree.is(Kind.FOR_STATEMENT)) { ForStatementTree forLoop = (ForStatementTree) loopTree; return forLoop.update() == null && forLoop.init() == null && forLoop.condition() == null; } return false; }
@Override public void visitForStatement(ForStatementTree tree) { if (tree.init() == null && tree.update() == null) { getContext().addIssue(this, tree, "Replace this \"for\" loop with a \"while\" loop"); } super.visitForStatement(tree); } }
@Override public void visitForStatement(ForStatementTree tree) { Tree init = tree.init(); if (init != null && init.is(Tree.Kind.LET_DECLARATION)) { List<IdentifierTree> identifiers = ((VariableDeclarationTreeImpl) init).variableIdentifiers(); ignore(identifiers); } super.visitForStatement(tree); }
private static boolean isTrivialIteratorException(ForStatementTree forStatement) { // todo(Lena): SONARJS-383 consider usage of counter inside the loop. Do it with symbol table. ExpressionTree condition = forStatement.condition(); if (condition != null && condition.is(NOT_EQUAL_TO)) { ExpressionTree update = forStatement.update(); Tree init = forStatement.init(); if (init != null && update != null) { return checkForTrivialIteratorException(init, condition, update); } } return false; }
private boolean isTrivialIteratorException(ForStatementTree forStatement) { // todo(Lena): SONARJS-383 consider usage of counter inside the loop. Do it with symbol table. ExpressionTree condition = forStatement.condition(); if (condition != null && condition.is(Tree.Kind.NOT_EQUAL_TO)) { ExpressionTree update = forStatement.update(); Tree init = forStatement.init(); if (init != null && update != null) { return checkForTrivialIteratorException(init, condition, update); } } return false; }
@Override public void visitForStatement(ForStatementTree tree) { visitCommaOperatorExpression(tree.init()); scan(tree.condition()); scan(tree.statement()); }
@Override public void visitForStatement(ForStatementTree tree) { scan(tree.init()); scan(tree.condition()); currentLoopCounters = new HashSet<>(); inUpdate = true; scan(tree.update()); inUpdate = false; enterLoopBody(); scan(tree.statement()); leaveLoopBody(); }
@Override public void visitForStatement(ForStatementTree tree) { scan(tree.init()); scan(tree.condition()); scan(tree.update()); scan(tree.statement()); }
@Override public void visitForStatement(ForStatementTree tree) { scan(tree.init()); scan(tree.condition()); scanUpdateClause(tree.update()); scan(tree.statement()); }
@Override public void visitForStatement(ForStatementTree tree) { visitPossibleException(tree.init()); super.scan(tree.condition()); visitPossibleException(tree.update()); super.scan(tree.statement()); }
@Override public void visitForStatement(ForStatementTree tree) { visitPossibleException(tree.init()); super.scan(tree.condition()); visitPossibleException(tree.update()); super.scan(tree.statement()); }