use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.
the class ThreadAsRunnableArgumentCheck method checkArgumentsTypes.
private void checkArgumentsTypes(List<ExpressionTree> arguments, MethodJavaSymbol methodSymbol) {
List<Type> parametersTypes = methodSymbol.parameterTypes();
// FIXME As arguments are not handled for method resolution using static imports, the provided methodSymbol may not match.
if (!parametersTypes.isEmpty()) {
for (int index = 0; index < arguments.size(); index++) {
ExpressionTree argument = arguments.get(index);
Type providedType = argument.symbolType();
if (!argument.is(Kind.NULL_LITERAL) && isThreadAsRunnable(providedType, parametersTypes, index, methodSymbol.isVarArgs())) {
reportIssue(argument, getMessage(argument, providedType, index));
}
}
}
}
use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.
the class ThreadAsRunnableArgumentCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
List<ExpressionTree> arguments;
Symbol methodSymbol;
if (tree.is(Kind.NEW_CLASS)) {
NewClassTree nct = (NewClassTree) tree;
methodSymbol = nct.constructorSymbol();
arguments = nct.arguments();
} else {
MethodInvocationTree mit = (MethodInvocationTree) tree;
methodSymbol = mit.symbol();
arguments = mit.arguments();
}
if (!arguments.isEmpty() && methodSymbol.isMethodSymbol()) {
checkArgumentsTypes(arguments, (MethodJavaSymbol) methodSymbol);
}
}
use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.
the class SecureCookieCheck method isSetSecureCall.
private static boolean isSetSecureCall(MethodInvocationTree mit) {
Symbol methodSymbol = mit.symbol();
boolean hasArityOne = mit.arguments().size() == 1;
if (hasArityOne && isCallSiteCookie(methodSymbol)) {
ExpressionTree expressionTree = mit.arguments().get(0);
if (expressionTree.is(Tree.Kind.BOOLEAN_LITERAL) && "false".equals(((LiteralTree) expressionTree).value())) {
return false;
}
return "setSecure".equals(getIdentifier(mit).name());
}
return false;
}
use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.
the class ShiftOnIntOrLongCheck method checkShiftTree.
private void checkShiftTree(Tree tree, int treeIndex) {
String identifier;
ExpressionTree shift;
SyntaxToken operatorToken;
if (tree.is(Kind.LEFT_SHIFT, Kind.RIGHT_SHIFT)) {
BinaryExpressionTree binaryExpressionTree = (BinaryExpressionTree) tree;
if (isZeroMaskShift(binaryExpressionTree)) {
// No issue should be reported for "1 << 0" or "1 >> 0"
return;
}
identifier = getIdentifierName(binaryExpressionTree.leftOperand());
shift = binaryExpressionTree.rightOperand();
operatorToken = binaryExpressionTree.operatorToken();
} else {
AssignmentExpressionTree assignmentExpressionTree = (AssignmentExpressionTree) tree;
identifier = getIdentifierName(assignmentExpressionTree.variable());
shift = assignmentExpressionTree.expression();
operatorToken = assignmentExpressionTree.operatorToken();
}
checkShift((ExpressionTree) tree, shift, identifier, operatorToken, treeIndex);
}
use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.
the class SillyEqualsCheck method onMethodInvocationFound.
@Override
protected void onMethodInvocationFound(MethodInvocationTree tree) {
ExpressionTree firstArgument = Iterables.getOnlyElement(tree.arguments());
Type argumentType = firstArgument.symbolType().erasure();
if (argumentType.isPrimitive()) {
argumentType = ((JavaType) argumentType).primitiveWrapperType();
}
Type ownerType = getMethodOwnerType(tree).erasure();
IdentifierTree methodInvocationName = ExpressionUtils.methodName(tree);
if (isLiteralNull(firstArgument)) {
reportIssue(methodInvocationName, "Remove this call to \"equals\"; comparisons against null always return false; consider using '== null' to check for nullity.");
} else if (ownerType.isArray()) {
checkWhenOwnerIsArray(methodInvocationName, (Type.ArrayType) ownerType, argumentType);
} else {
checkWhenOwnerIsNotArray(methodInvocationName, ownerType, argumentType);
}
}
Aggregations