use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class ReplaceLambdaByMethodRefCheck method isMethodInvocation.
private static boolean isMethodInvocation(@Nullable Tree tree, LambdaExpressionTree lambdaTree) {
if (tree != null && tree.is(Tree.Kind.METHOD_INVOCATION, Tree.Kind.NEW_CLASS)) {
Arguments arguments;
if (tree.is(Tree.Kind.NEW_CLASS)) {
if (((NewClassTree) tree).classBody() != null) {
return false;
}
arguments = ((NewClassTree) tree).arguments();
} else {
MethodInvocationTree mit = (MethodInvocationTree) tree;
if (hasMethodInvocationInMethodSelect(mit) || hasNonFinalFieldInMethodSelect(mit)) {
return false;
}
arguments = mit.arguments();
}
List<VariableTree> parameters = lambdaTree.parameters();
return matchingParameters(parameters, arguments) || (arguments.isEmpty() && isNoArgMethodInvocationFromLambdaParam(tree, parameters));
}
return false;
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class SwitchInsteadOfIfSequenceCheck method getEqualMethodInvocationOperands.
private static Optional<EqualsOperands> getEqualMethodInvocationOperands(ExpressionTree expressionTree) {
ExpressionTree arg = null;
ExpressionTree expression = null;
if (expressionTree.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) expressionTree;
Symbol symbol = mit.symbol();
ExpressionTree methodSelect = mit.methodSelect();
if (mit.arguments().size() == 1) {
arg = mit.arguments().get(0);
if ("equals".equals(symbol.name()) && arg.symbolType().is("java.lang.String") && methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
expression = ((MemberSelectExpressionTree) methodSelect).expression();
}
}
} else if (expressionTree.is(Tree.Kind.EQUAL_TO)) {
BinaryExpressionTree equalTo = (BinaryExpressionTree) expressionTree;
arg = equalTo.leftOperand();
expression = equalTo.rightOperand();
}
if (arg != null && expression != null) {
if (arg.is(Tree.Kind.STRING_LITERAL) && expression.is(Tree.Kind.IDENTIFIER)) {
return Optional.of(new EqualsOperands((LiteralTree) arg, (IdentifierTree) expression));
} else if (arg.is(Tree.Kind.IDENTIFIER) && expression.is(Tree.Kind.STRING_LITERAL)) {
return Optional.of(new EqualsOperands((LiteralTree) expression, (IdentifierTree) arg));
}
}
return Optional.empty();
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class ToStringUsingBoxingCheck method visitNode.
@Override
public void visitNode(Tree tree) {
MethodInvocationTree mit = (MethodInvocationTree) tree;
String callingToStringOrCompareTo = isCallingToStringOrCompareTo(mit.methodSelect());
if (callingToStringOrCompareTo != null) {
String newlyCreatedClassName = getNewlyCreatedClassName(mit);
if (PRIMITIVE_WRAPPERS.contains(newlyCreatedClassName)) {
reportIssue(((MemberSelectExpressionTree) mit.methodSelect()).expression(), "Call the static method " + newlyCreatedClassName + "." + callingToStringOrCompareTo + "(...) instead of instantiating a temporary object to perform this to string conversion.");
}
}
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree 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.MethodInvocationTree in project sonar-java by SonarSource.
the class SecureCookieCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (hasSemantic()) {
if (tree.is(Tree.Kind.VARIABLE)) {
VariableTree variableTree = (VariableTree) tree;
addToUnsecuredCookies(variableTree);
} else if (tree.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) tree;
checkSecureCall(mit);
}
}
}
Aggregations