use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.
the class NullDereferenceInConditionalCheck method visitBinaryExpression.
@Override
public void visitBinaryExpression(BinaryExpressionTree tree) {
if (isAndWithNullComparison(tree) || isOrWithNullExclusion(tree)) {
ExpressionTree nonNullOperand = getNonNullOperand(tree.leftOperand());
IdentifierTree identifierTree = getIdentifier(nonNullOperand);
if (identifierTree != null) {
IdentifierVisitor visitor = new IdentifierVisitor(identifierTree);
tree.rightOperand().accept(visitor);
if (visitor.raiseIssue) {
context.reportIssue(this, tree, "Either reverse the equality operator in the \"" + identifierTree.name() + "\" null test, or reverse the logical operator that follows it.");
}
}
}
super.visitBinaryExpression(tree);
}
use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.
the class ModulusEqualityCheck method checkModulusAndIntLiteral.
private void checkModulusAndIntLiteral(ExpressionTree operand1, ExpressionTree operand2) {
if (operand1.is(Tree.Kind.REMAINDER)) {
BinaryExpressionTree modulusExp = (BinaryExpressionTree) operand1;
Integer intValue = LiteralUtils.intLiteralValue(operand2);
ExpressionTree leftOperand = modulusExp.leftOperand();
ExpressionTree rightOperand = modulusExp.rightOperand();
boolean usesMethodParam = isMethodParameter(leftOperand) || isMethodParameter(rightOperand);
boolean usesSize = isSizeAccessor(leftOperand) || isSizeAccessor(rightOperand);
if (intValue != null && intValue != 0 && usesMethodParam && !usesSize) {
String sign = intValue > 0 ? "positive" : "negative";
reportIssue(modulusExp.operatorToken(), "The results of this modulus operation may not be " + sign + ".");
}
}
}
use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.
the class MutableMembersUsageCheck method visitAssignmentExpression.
@Override
public void visitAssignmentExpression(AssignmentExpressionTree tree) {
super.visitAssignmentExpression(tree);
if (!isMutableType(tree.expression())) {
return;
}
ExpressionTree variable = tree.variable();
Symbol leftSymbol = null;
if (variable.is(Tree.Kind.IDENTIFIER)) {
IdentifierTree identifierTree = (IdentifierTree) variable;
leftSymbol = identifierTree.symbol();
} else if (variable.is(Tree.Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree mit = (MemberSelectExpressionTree) variable;
leftSymbol = mit.identifier().symbol();
}
if (leftSymbol != null && leftSymbol.isPrivate()) {
checkStore(tree.expression());
}
}
use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.
the class MutableMembersUsageCheck method visitVariable.
@Override
public void visitVariable(VariableTree tree) {
super.visitVariable(tree);
ExpressionTree initializer = tree.initializer();
if (initializer == null || !isMutableType(initializer)) {
return;
}
checkStore(initializer);
}
use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.
the class MutableMembersUsageCheck method visitReturnStatement.
@Override
public void visitReturnStatement(ReturnStatementTree tree) {
super.visitReturnStatement(tree);
ExpressionTree expressionTree = tree.expression();
if (expressionTree == null || !isMutableType(expressionTree)) {
return;
}
checkReturnedExpression(expressionTree);
}
Aggregations