use of org.sonar.plugins.java.api.tree.ConditionalExpressionTree in project sonar-java by SonarSource.
the class AllBranchesAreIdenticalCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (tree.is(Tree.Kind.SWITCH_STATEMENT)) {
SwitchStatementTree switchStatement = (SwitchStatementTree) tree;
Multimap<CaseGroupTree, CaseGroupTree> identicalBranches = checkSwitchStatement(switchStatement);
if (hasDefaultClause(switchStatement) && allBranchesSame(identicalBranches, switchStatement.cases().size())) {
reportIssue(switchStatement.switchKeyword(), IF_SWITCH_MSG);
}
} else if (tree.is(Tree.Kind.IF_STATEMENT)) {
IfStatementTree ifStatementTree = (IfStatementTree) tree;
if (hasElseClause(ifStatementTree) && !tree.parent().is(Tree.Kind.IF_STATEMENT)) {
IfElseChain ifElseChain = checkIfStatement(ifStatementTree);
if (allBranchesSame(ifElseChain.branches, ifElseChain.totalBranchCount)) {
reportIssue(ifStatementTree.ifKeyword(), IF_SWITCH_MSG);
}
}
} else {
checkConditionalExpression((ConditionalExpressionTree) tree);
}
}
use of org.sonar.plugins.java.api.tree.ConditionalExpressionTree in project sonar-java by SonarSource.
the class PrimitiveWrappersInTernaryOperatorCheck method visitNode.
@Override
public void visitNode(Tree tree) {
ConditionalExpressionTree cet = (ConditionalExpressionTree) tree;
Type trueExpressionType = cet.trueExpression().symbolType();
Type falseExpressionType = cet.falseExpression().symbolType();
if (dissimilarPrimitiveTypeWrappers(trueExpressionType, falseExpressionType)) {
reportIssue(cet.questionToken(), "Add an explicit cast to match types of operands.");
}
}
use of org.sonar.plugins.java.api.tree.ConditionalExpressionTree in project sonar-java by SonarSource.
the class CFG method buildConditionalExpression.
private void buildConditionalExpression(ConditionalExpressionTree cond) {
Block next = currentBlock;
// process else-branch
ExpressionTree elseStatement = cond.falseExpression();
currentBlock = createBlock(next);
build(elseStatement);
Block elseBlock = currentBlock;
// process then-branch
currentBlock = createBlock(next);
build(cond.trueExpression());
Block thenBlock = currentBlock;
// process condition
currentBlock = createBranch(cond, thenBlock, elseBlock);
buildCondition(cond.condition(), thenBlock, elseBlock);
}
Aggregations