use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class ConfusingOverloadCheck method checkMethod.
private boolean checkMethod(Tree reportTree, Symbol.MethodSymbol methodSymbol, Type superClass) {
boolean reportStaticIssue = false;
for (Symbol methodWithSameName : superClass.symbol().lookupSymbols(methodSymbol.name())) {
if (methodWithSameName.isMethodSymbol()) {
if (hideStaticMethod(methodSymbol, superClass, methodWithSameName)) {
reportIssue(reportTree, "Rename this method or make it \"static\".");
reportStaticIssue = true;
} else if (confusingOverload(methodSymbol, (Symbol.MethodSymbol) methodWithSameName)) {
reportIssue(reportTree, getMessage(methodWithSameName));
}
}
}
return reportStaticIssue;
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class CollectionMethodsWithLinearComplexityCheck method findAssignedTypes.
private static Set<String> findAssignedTypes(Symbol symbol) {
Set<String> types = new HashSet<>();
Tree declaration = symbol.declaration();
if (declaration != null && declaration.is(Tree.Kind.VARIABLE)) {
ExpressionTree initializer = ((VariableTree) declaration).initializer();
if (initializer != null) {
types.add(initializer.symbolType().fullyQualifiedName());
}
}
symbol.usages().stream().flatMap(CollectionMethodsWithLinearComplexityCheck::usageInAssignment).map(assignment -> assignment.expression().symbolType().fullyQualifiedName()).forEach(types::add);
return types;
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class CollectionMethodsWithLinearComplexityCheck method visitNode.
@Override
public void visitNode(Tree tree) {
MethodInvocationTree mit = (MethodInvocationTree) tree;
matcherActualTypeMap.forEach((methodMatcher, actualTypes) -> {
if (methodMatcher.matches(mit) && invocationInMethod(mit)) {
Symbol target = invocationTarget(mit);
if (target != null && isField(target) && matchesActualType(target, actualTypes)) {
IdentifierTree methodName = ExpressionUtils.methodName(mit);
reportIssue(methodName, "This call to \"" + methodName.name() + "()\" may be a performance hot spot if the collection is large.");
}
}
});
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class ChangeMethodContractCheck method checkContractChange.
private void checkContractChange(MethodTreeImpl methodTree, Symbol.MethodSymbol overridee) {
if (methodTree.isEqualsMethod() && methodTree.parameters().get(0).symbol().metadata().isAnnotatedWith(JAVAX_ANNOTATION_NONNULL)) {
reportIssue(methodTree.parameters().get(0), "Equals method should accept null parameters and return false.");
return;
}
for (int i = 0; i < methodTree.parameters().size(); i++) {
VariableTree parameter = methodTree.parameters().get(i);
Symbol overrideeParamSymbol = ((JavaSymbol.MethodJavaSymbol) overridee).getParameters().scopeSymbols().get(i);
checkParameter(parameter, overrideeParamSymbol);
}
if (nonNullVsNull(overridee, methodTree.symbol())) {
for (AnnotationTree annotationTree : methodTree.modifiers().annotations()) {
if (annotationTree.symbolType().is(JAVAX_ANNOTATION_NULLABLE) || annotationTree.symbolType().is(JAVAX_ANNOTATION_CHECK_FOR_NULL)) {
reportIssue(annotationTree, "Remove this \"" + annotationTree.symbolType().name() + "\" annotation to honor the overridden method's contract.");
}
}
}
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class CallSuperInTestCaseCheck method requiresSuperCall.
private static boolean requiresSuperCall(Symbol.MethodSymbol methodSymbol) {
Type superType = methodSymbol.owner().type().symbol().superClass();
Collection<Symbol> symbols = Lists.newArrayList();
while (superType != null && !superType.is(JUNIT_FRAMEWORK_TEST_CASE) && symbols.isEmpty()) {
symbols = superType.symbol().lookupSymbols(methodSymbol.name());
superType = superType.symbol().superClass();
}
return !symbols.isEmpty() && !symbols.iterator().next().owner().type().is(JUNIT_FRAMEWORK_TEST_CASE);
}
Aggregations