@Override public void visitSwitchStatement(SwitchStatementTree tree) { scan(tree.expression()); ExecutionState resultingES = new ExecutionState(executionState); executionState = new ExecutionState(executionState); for (CaseGroupTree caseGroupTree : tree.cases()) { for (StatementTree statement : caseGroupTree.body()) { if (isBreakOrReturnStatement(statement)) { resultingES = executionState.merge(resultingES); executionState = new ExecutionState(resultingES.parent); } else { scan(statement); } } } if (!lastStatementIsBreakOrReturn(tree)) { // merge the last execution state resultingES = executionState.merge(resultingES); } if (switchContainsDefaultLabel(tree)) { // the default block guarantees that we will cover all the paths executionState = resultingES.parent.overrideBy(resultingES); } else { executionState = resultingES.parent.merge(resultingES); } }
@Override public void visitTryStatement(TryStatementTree tree) { for (VariableTree resource : tree.resources()) { executionState.markAsIgnored(resource.symbol()); } ExecutionState blockES = new ExecutionState(executionState); executionState = blockES; scan(tree.block()); for (CatchTree catchTree : tree.catches()) { executionState = new ExecutionState(blockES.parent); scan(catchTree.block()); blockES.merge(executionState); } if (tree.finallyBlock() != null) { executionState = new ExecutionState(blockES.parent); scan(tree.finallyBlock()); executionState = blockES.parent.overrideBy(blockES.overrideBy(executionState)); } else { executionState = blockES.parent.merge(blockES); } }
@Override public void visitIfStatement(IfStatementTree tree) { scan(tree.condition()); ExecutionState thenES = new ExecutionState(executionState); executionState = thenES; scan(tree.thenStatement()); if (tree.elseStatement() == null) { executionState = thenES.parent.merge(thenES); } else { ExecutionState elseES = new ExecutionState(thenES.parent); executionState = elseES; scan(tree.elseStatement()); executionState = thenES.parent.overrideBy(thenES.merge(elseES)); } }
private void visitStatement(StatementTree tree) { executionState = new ExecutionState(executionState); scan(tree); executionState = executionState.restoreParent(); }
@Override public void visitDoWhileStatement(DoWhileStatementTree tree) { visitStatement(tree.statement()); scan(tree.condition()); }
@Override public void visitWhileStatement(WhileStatementTree tree) { scan(tree.condition()); visitStatement(tree.statement()); }