use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class CollectionCallingItselfCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (hasSemantic()) {
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) tree;
Symbol symbolReference = null;
Symbol method = null;
String reportedName = "";
if (methodInvocationTree.methodSelect().is(Tree.Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree mse = (MemberSelectExpressionTree) methodInvocationTree.methodSelect();
IdentifierTree identifier = mse.identifier();
reportedName = identifier.name();
method = identifier.symbol();
if (mse.expression().is(Tree.Kind.IDENTIFIER)) {
symbolReference = ((IdentifierTree) mse.expression()).symbol();
}
}
if (symbolReference != null && isMethodFromCollection(method)) {
reportIssueForParameters(methodInvocationTree, symbolReference, reportedName);
}
}
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class ClassWithoutHashCodeInHashStructureCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
Type type = ((NewClassTree) tree).symbolType();
if (type instanceof ParametrizedTypeJavaType && useHashDataStructure(type)) {
ParametrizedTypeJavaType ptt = (ParametrizedTypeJavaType) type;
Symbol.TypeSymbol symbol = ptt.substitution(ptt.typeParameters().get(0)).symbol();
if (implementsEquals(symbol) && !implementsHashCode(symbol)) {
reportIssue(tree, "Add a \"hashCode()\" method to \"" + symbol.name() + "\" or remove it from this hash.");
}
}
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class CallToDeprecatedMethodCheck method checkIdentifierIssue.
private void checkIdentifierIssue(IdentifierTree identifierTree) {
if (isSimpleNameOfVariableTreeOrVariableIsDeprecated(identifierTree)) {
return;
}
Symbol symbol = identifierTree.symbol();
if (isDeprecated(symbol)) {
String name;
if (isConstructor(symbol)) {
name = symbol.owner().name();
} else {
name = symbol.name();
}
reportIssue(identifierTree, "Remove this use of \"" + name + "\"; it is deprecated.");
}
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class AssertsOnParametersOfPublicMethodCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
MethodTree methodTree = (MethodTree) tree;
if (!methodTree.symbol().isPublic()) {
return;
}
methodTree.parameters().stream().map(VariableTree::symbol).map(Symbol::usages).flatMap(List::stream).forEach(parameter -> checkUsage(parameter, methodTree));
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class ChildClassShadowFieldCheck method visitNode.
@Override
public void visitNode(Tree tree) {
TypeTree superClass = ((ClassTree) tree).superClass();
if (superClass != null) {
Symbol.TypeSymbol superclassSymbol = superClass.symbolType().symbol();
((ClassTree) tree).members().stream().filter(m -> m.is(Kind.VARIABLE)).map(VariableTree.class::cast).map(VariableTree::simpleName).forEach(fieldSimpleName -> {
if (!IGNORED_FIELDS.contains(fieldSimpleName.name())) {
checkForIssue(superclassSymbol, fieldSimpleName);
}
});
}
}
Aggregations