use of org.sonar.plugins.java.api.tree.BinaryExpressionTree in project sonar-java by SonarSource.
the class ModulusEqualityCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (tree.is(Tree.Kind.EQUAL_TO)) {
BinaryExpressionTree equality = (BinaryExpressionTree) tree;
checkModulusAndIntLiteral(equality.leftOperand(), equality.rightOperand());
checkModulusAndIntLiteral(equality.rightOperand(), equality.leftOperand());
} else {
MethodTree methodTree = (MethodTree) tree;
for (VariableTree variableTree : methodTree.parameters()) {
methodParams.add(variableTree.symbol());
}
}
}
use of org.sonar.plugins.java.api.tree.BinaryExpressionTree 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.BinaryExpressionTree in project sonar-java by SonarSource.
the class RawByteBitwiseOperationsCheck method visitBinaryExpression.
@Override
public void visitBinaryExpression(BinaryExpressionTree tree) {
super.visitBinaryExpression(tree);
if (isShifting(tree)) {
shifts.add(tree);
return;
}
if (isSecuringByte(tree)) {
byteContainments.add(tree);
return;
}
if (isIntegerOrLongExpected(tree.symbolType())) {
ExpressionTree leftOperand = ExpressionUtils.skipParentheses(tree.leftOperand());
ExpressionTree rightOperand = ExpressionUtils.skipParentheses(tree.rightOperand());
checkShiftWithoutByteSecuring(leftOperand, rightOperand);
checkShiftWithoutByteSecuring(rightOperand, leftOperand);
}
}
use of org.sonar.plugins.java.api.tree.BinaryExpressionTree in project sonar-java by SonarSource.
the class NonShortCircuitLogicCheck method visitNode.
@Override
public void visitNode(Tree tree) {
BinaryExpressionTree binaryExpressionTree = (BinaryExpressionTree) tree;
if (isBoolean(binaryExpressionTree.leftOperand().symbolType())) {
String operator = binaryExpressionTree.operatorToken().text();
String replacement = REPLACEMENTS.get(operator);
reportIssue(binaryExpressionTree.operatorToken(), "Correct this \"" + operator + "\" to \"" + replacement + "\".");
}
}
use of org.sonar.plugins.java.api.tree.BinaryExpressionTree in project sonar-java by SonarSource.
the class CollectionSizeAndArrayLengthCheck method checkArrayLength.
private void checkArrayLength(MemberSelectExpressionTree testedValue, BinaryExpressionTree bet, boolean leftIsZero) {
if (!"length".equals(testedValue.identifier().name())) {
return;
}
ExpressionTree expression = testedValue.expression();
if (!expression.symbolType().isArray()) {
return;
}
reportIssue(bet, leftIsZero, ARRAY_ISSUE_MSG, arrayName(expression));
}
Aggregations