private void visitObjectIterationStatement(IterationStatementTree tree, Tree counterBlock) { currentLoopCounters = new HashSet<>(); scanCounterBlock(counterBlock); enterLoopBody(); scan(tree.statement()); leaveLoopBody(); }
private static boolean canExecuteMoreThanOnce(IterationStatementTree loopTree) { ControlFlowGraph cfg = CheckUtils.buildControlFlowGraph(loopTree); for (CfgBranchingBlock block : Iterables.filter(cfg.blocks(), CfgBranchingBlock.class)) { if (loopTree.equals(block.branchingTree()) && hasPredecessorInsideLoopBody(block, loopTree)) { return true; } } return false; }
private static boolean hasPredecessorInsideLoopBody( CfgBranchingBlock conditionBlock, IterationStatementTree loopTree) { for (CfgBlock loopPredecessor : conditionBlock.predecessors()) { List<Tree> predecessorElements = loopPredecessor.elements(); Tree predecessorLastElement = predecessorElements.get(predecessorElements.size() - 1); if (loopTree.is(Kind.FOR_STATEMENT)) { ForStatementTree forTree = (ForStatementTree) loopTree; if (forTree.update() != null && forTree.update().equals(predecessorLastElement)) { return !loopPredecessor.predecessors().isEmpty(); } } StatementTree loopBody = loopTree.statement(); if (isDescendant(predecessorLastElement, loopBody)) { return true; } } return false; }