use of org.sonar.plugins.java.api.tree.DoWhileStatementTree in project sonar-java by SonarSource.
the class JavaTreeModelTest method do_statement.
/**
* 14.13. The do Statement
*/
@Test
public void do_statement() {
DoWhileStatementTree tree = (DoWhileStatementTree) firstMethodFirstStatement("class T { void m() { do ; while (true); } }");
assertThat(tree.is(Tree.Kind.DO_STATEMENT)).isTrue();
assertThat(tree.doKeyword().text()).isEqualTo("do");
assertThat(tree.statement()).isNotNull();
assertThat(tree.whileKeyword().text()).isEqualTo("while");
assertThat(tree.openParenToken().text()).isEqualTo("(");
assertThat(tree.condition()).isNotNull();
assertThat(tree.closeParenToken().text()).isEqualTo(")");
assertThat(tree.semicolonToken().text()).isEqualTo(";");
assertThatChildrenIteratorHasSize(tree, 7);
}
use of org.sonar.plugins.java.api.tree.DoWhileStatementTree in project sonar-java by SonarSource.
the class ExplodedGraphWalker method handleBlockExit.
private void handleBlockExit(ProgramPoint programPosition) {
CFG.Block block = (CFG.Block) programPosition.block;
Tree terminator = block.terminator();
cleanUpProgramState(block);
boolean exitPath = node.exitPath;
if (terminator != null) {
switch(terminator.kind()) {
case IF_STATEMENT:
ExpressionTree ifCondition = ((IfStatementTree) terminator).condition();
handleBranch(block, cleanupCondition(ifCondition), verifyCondition(ifCondition));
return;
case CONDITIONAL_OR:
case CONDITIONAL_AND:
handleBranch(block, ((BinaryExpressionTree) terminator).leftOperand());
return;
case CONDITIONAL_EXPRESSION:
handleBranch(block, ((ConditionalExpressionTree) terminator).condition());
return;
case FOR_STATEMENT:
ExpressionTree condition = ((ForStatementTree) terminator).condition();
if (condition != null) {
handleBranch(block, condition, false);
return;
}
break;
case WHILE_STATEMENT:
ExpressionTree whileCondition = ((WhileStatementTree) terminator).condition();
handleBranch(block, cleanupCondition(whileCondition), verifyCondition(whileCondition));
return;
case DO_STATEMENT:
ExpressionTree doCondition = ((DoWhileStatementTree) terminator).condition();
handleBranch(block, cleanupCondition(doCondition), verifyCondition(doCondition));
return;
case SYNCHRONIZED_STATEMENT:
resetFieldValues(false);
break;
case RETURN_STATEMENT:
ExpressionTree returnExpression = ((ReturnStatementTree) terminator).expression();
if (returnExpression != null) {
programState.storeExitValue();
}
break;
case THROW_STATEMENT:
ProgramState.Pop unstack = programState.unstackValue(1);
SymbolicValue sv = unstack.values.get(0);
if (sv instanceof SymbolicValue.CaughtExceptionSymbolicValue) {
// retrowing the exception from a catch block
sv = ((SymbolicValue.CaughtExceptionSymbolicValue) sv).exception();
} else {
sv = constraintManager.createExceptionalSymbolicValue(((ThrowStatementTree) terminator).expression().symbolType());
}
programState = unstack.state.stackValue(sv);
programState.storeExitValue();
break;
default:
}
}
// unconditional jumps, for-statement, switch-statement, synchronized:
if (exitPath) {
if (block.exitBlock() != null) {
enqueue(new ProgramPoint(block.exitBlock()), programState, true);
} else {
for (CFG.Block successor : block.successors()) {
enqueue(new ProgramPoint(successor), programState, true);
}
}
} else {
for (CFG.Block successor : block.successors()) {
if (!block.isFinallyBlock() || isDirectFlowSuccessorOf(successor, block)) {
enqueue(new ProgramPoint(successor), programState, successor == block.exitBlock());
}
}
}
}
use of org.sonar.plugins.java.api.tree.DoWhileStatementTree in project sonar-java by SonarSource.
the class MissingCurlyBracesCheck method visitNode.
@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;
}
}
Aggregations