use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class MethodParametersOrderCheck method visitNode.
@Override
public void visitNode(Tree tree) {
MethodInvocationTree methodInvTree = (MethodInvocationTree) tree;
MethodTree methodDeclaration = (MethodTree) methodInvTree.symbol().declaration();
if (methodDeclaration == null) {
return;
}
ParametersList formalParameterList = parametersByMethod.computeIfAbsent(methodInvTree.symbol(), m -> new ParametersList(methodDeclaration));
List<IdentifierTree> argumentsList = methodInvTree.arguments().stream().map(this::argumentToIdentifier).collect(Collectors.toList());
if (matchingNames(formalParameterList, argumentsList) && matchingTypesWrongOrder(formalParameterList, argumentsList)) {
List<JavaFileScannerContext.Location> flow = methodDeclaration.parameters().stream().map(param -> new JavaFileScannerContext.Location("Formal Parameters", param)).collect(Collectors.toList());
reportIssue(methodInvTree.arguments(), "Parameters to " + methodInvTree.symbol().name() + " have the same names but not the same order as the method arguments.", flow, null);
}
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class MethodOnlyCallsSuperCheck method isUselessSuperCall.
private static boolean isUselessSuperCall(MethodTree methodTree) {
ExpressionTree callToSuper = null;
StatementTree statementTree = methodTree.block().body().get(0);
if (returnsVoid(methodTree) && statementTree.is(Tree.Kind.EXPRESSION_STATEMENT)) {
callToSuper = ((ExpressionStatementTree) statementTree).expression();
} else if (statementTree.is(Tree.Kind.RETURN_STATEMENT)) {
callToSuper = ((ReturnStatementTree) statementTree).expression();
}
return callToSuper != null && isCallToSuper(methodTree, callToSuper) && sameVisibility(methodTree.symbol(), ((MethodInvocationTree) callToSuper).symbol());
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class InvalidDateValuesCheck method getThresholdToCheck.
@CheckForNull
private static String getThresholdToCheck(ExpressionTree tree) {
if (tree.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) tree;
String name = getMethodName(mit);
for (MethodMatcher methodInvocationMatcher : DATE_METHODS_COMPARISON) {
if (methodInvocationMatcher.matches(mit)) {
return getName(mit, name);
}
}
}
return null;
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class ObjectFinalizeCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (tree.is(Tree.Kind.METHOD)) {
isInFinalizeMethod = isFinalizeMethodMember((MethodTree) tree);
} else {
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) tree;
IdentifierTree methodName = ExpressionUtils.methodName(methodInvocationTree);
if (!isInFinalizeMethod && "finalize".equals(methodName.name()) && methodInvocationTree.arguments().isEmpty()) {
reportIssue(methodName, "Remove this call to finalize().");
}
}
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class ModulusEqualityCheck method isSizeAccessor.
private static boolean isSizeAccessor(ExpressionTree expressionTree) {
if (expressionTree.is(Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) expressionTree;
Type type = memberSelectExpressionTree.expression().symbolType();
String memberName = memberSelectExpressionTree.identifier().name();
return isCollectionSize(type, memberName) || isStringLength(type, memberName) || isArrayLength(type, memberName);
} else if (expressionTree.is(Kind.METHOD_INVOCATION)) {
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) expressionTree;
return isSizeAccessor(methodInvocationTree.methodSelect());
}
return false;
}
Aggregations