use of org.sonar.java.matcher.MethodMatcher in project sonar-java by SonarSource.
the class UnusedReturnedDataCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (tree.is(Tree.Kind.EXPRESSION_STATEMENT)) {
CHECKED_METHODS.stream().map(matcher -> isTreeMethodInvocation(((ExpressionStatementTree) tree).expression(), matcher)).filter(Objects::nonNull).forEach(mit -> raiseIssue(ExpressionUtils.methodName(mit)));
} else {
BinaryExpressionTree expressionTree = (BinaryExpressionTree) tree;
ExpressionTree leftOperand = expressionTree.leftOperand();
ExpressionTree rightOperand = expressionTree.rightOperand();
for (MethodMatcher matcher : CHECKED_METHODS) {
MethodInvocationTree leftMit = isTreeMethodInvocation(leftOperand, matcher);
if (leftMit != null && isTreeLiteralNull(rightOperand)) {
raiseIssue(ExpressionUtils.methodName(leftMit));
}
MethodInvocationTree rightMit = isTreeMethodInvocation(rightOperand, matcher);
if (rightMit != null && isTreeLiteralNull(leftOperand)) {
raiseIssue(ExpressionUtils.methodName(rightMit));
}
}
}
}
Aggregations