@Override public void visitWhileStatement(WhileStatementTree tree) { // do not scan the condition addLines(tree.whileKeyword(), tree.closeParenToken()); addLineOfCloseBrace(tree.whileKeyword(), tree.statement()); scan(tree.statement()); }
@Override public void visitWhileStatement(WhileStatementTree tree) { blame.add(tree.firstToken()); super.visitWhileStatement(tree); }
@Override public void visitWhileStatement(WhileStatementTree tree) { checkBlock(tree.closeParenToken(), tree.statement()); super.visitWhileStatement(tree); }
@Override public void visitWhileStatement(WhileStatementTree tree) { scan(tree.statement()); }
@Override public void visitWhileStatement(WhileStatementTree tree) { if (LiteralUtils.isTrue(tree.condition())) { checkLoopWithAlwaysTrueCondition(context, tree); } }
@Override public void visitNode(Tree tree) { switch (tree.kind()) { case WHILE_STATEMENT: WhileStatementTree whileStatementTree = (WhileStatementTree) tree; checkStatement(whileStatementTree.whileKeyword(), whileStatementTree.statement()); break; case DO_STATEMENT: DoWhileStatementTree doWhileStatementTree = (DoWhileStatementTree) tree; checkStatement(doWhileStatementTree.doKeyword(), doWhileStatementTree.statement()); break; case FOR_STATEMENT: ForStatementTree forStatementTree = (ForStatementTree) tree; checkStatement(forStatementTree.forKeyword(), forStatementTree.statement()); break; case FOR_EACH_STATEMENT: ForEachStatement forEachStatement = (ForEachStatement) tree; checkStatement(forEachStatement.forKeyword(), forEachStatement.statement()); break; case IF_STATEMENT: checkIfStatement((IfStatementTree) tree); break; default: break; } }
@Override public void visitWhileStatement(WhileStatementTree tree) { SyntaxToken whileKeyword = tree.whileKeyword(); checkNesting(whileKeyword); nestingLevel.push(whileKeyword); super.visitWhileStatement(tree); nestingLevel.pop(); }
@Override public void visitWhileStatement(WhileStatementTree tree) { scan(tree.statement()); }
@Override public void visitWhileStatement(WhileStatementTree tree) { if (LiteralUtils.isTrue(tree.condition())) { checkLoopWithAlwaysTrueCondition(context, tree); } }
@Override public void visitNode(Tree tree) { switch (tree.kind()) { case WHILE_STATEMENT: WhileStatementTree whileStatementTree = (WhileStatementTree) tree; checkStatement(whileStatementTree.whileKeyword(), whileStatementTree.statement()); break; case DO_STATEMENT: DoWhileStatementTree doWhileStatementTree = (DoWhileStatementTree) tree; checkStatement(doWhileStatementTree.doKeyword(), doWhileStatementTree.statement()); break; case FOR_STATEMENT: ForStatementTree forStatementTree = (ForStatementTree) tree; checkStatement(forStatementTree.forKeyword(), forStatementTree.statement()); break; case FOR_EACH_STATEMENT: ForEachStatement forEachStatement = (ForEachStatement) tree; checkStatement(forEachStatement.forKeyword(), forEachStatement.statement()); break; case IF_STATEMENT: checkIfStatement((IfStatementTree) tree); break; default: break; } }
@Override public void visitWhileStatement(WhileStatementTree tree) { checkBlock(tree.closeParenToken(), tree.statement()); super.visitWhileStatement(tree); }
@Override public void visitWhileStatement(WhileStatementTree tree) { SyntaxToken whileKeyword = tree.whileKeyword(); checkNesting(whileKeyword); nestingLevel.push(whileKeyword); super.visitWhileStatement(tree); nestingLevel.pop(); }
@Override public void visitWhileStatement(WhileStatementTree tree) { // do not scan the condition addLines(tree.whileKeyword(), tree.closeParenToken()); addLineOfCloseBrace(tree.whileKeyword(), tree.statement()); scan(tree.statement()); }
private static Tree loopStatement(Tree loopTree) { if (loopTree.is(Tree.Kind.FOR_STATEMENT)) { return ((ForStatementTree) loopTree).statement(); } else if (loopTree.is(Tree.Kind.DO_STATEMENT)) { return ((DoWhileStatementTree) loopTree).statement(); } else if (loopTree.is(Tree.Kind.WHILE_STATEMENT)) { return ((WhileStatementTree) loopTree).statement(); } else if (loopTree.is(Tree.Kind.FOR_EACH_STATEMENT)) { return ((ForEachStatement) loopTree).statement(); } return null; }
/** * While loops are sometimes used to get only the first element of an enumeration/collection, using code similar to: * <code> * while(myIterator.hasNext()) { * // ... * return myIterator.next(); // unconditional jump * } * </code> */ private static boolean isWhileNextElementLoop(Tree loopTree) { if (loopTree.is(Tree.Kind.WHILE_STATEMENT)) { ExpressionTree condition = ExpressionUtils.skipParentheses(((WhileStatementTree) loopTree).condition()); return condition.is(Tree.Kind.METHOD_INVOCATION) && NEXT_ELEMENT.anyMatch((MethodInvocationTree) condition); } return false; }
@Override public void visitNode(Tree tree) { switch (tree.kind()) { case WHILE_STATEMENT: WhileStatementTree whileStatementTree = (WhileStatementTree) tree; checkStatement(whileStatementTree.whileKeyword(), whileStatementTree.statement()); break; case DO_STATEMENT: DoWhileStatementTree doWhileStatementTree = (DoWhileStatementTree) tree; checkStatement(doWhileStatementTree.doKeyword(), doWhileStatementTree.statement()); break; case FOR_STATEMENT: ForStatementTree forStatementTree = (ForStatementTree) tree; checkStatement(forStatementTree.forKeyword(), forStatementTree.statement()); break; case FOR_EACH_STATEMENT: ForEachStatement forEachStatement = (ForEachStatement) tree; checkStatement(forEachStatement.forKeyword(), forEachStatement.statement()); break; case IF_STATEMENT: checkIfStatement((IfStatementTree) tree); break; default: break; } }
@Override public void visitWhileStatement(WhileStatementTree tree) { increaseComplexityByNesting(tree.whileKeyword()); nesting++; super.visitWhileStatement(tree); nesting--; }
@Override public void visitWhileStatement(WhileStatementTree tree) { blame.add(tree.firstToken()); super.visitWhileStatement(tree); }