use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class DITCheck method visitClass.
@Override
public void visitClass(ClassTree tree) {
if (!isBodyOfEnumConstantTree(tree)) {
Type superClass = tree.symbol().superClass();
int dit = 0;
while (superClass != null) {
String fullyQualifiedName = superClass.fullyQualifiedName();
if (getPatterns().stream().anyMatch(wp -> wp.match(fullyQualifiedName))) {
break;
}
dit++;
superClass = superClass.symbol().superClass();
}
if (dit > max) {
Tree reportTree = tree.simpleName();
if (tree.parent().is(Tree.Kind.NEW_CLASS)) {
reportTree = ((NewClassTree) tree.parent()).newKeyword();
}
context.reportIssue(this, reportTree, "This class has " + dit + " parents which is greater than " + max + " authorized.", new ArrayList<>(), dit - max);
}
}
super.visitClass(tree);
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class EnumMutableFieldCheck method visitNode.
@Override
public void visitNode(Tree tree) {
ClassTree enumTree = (ClassTree) tree;
for (Tree member : enumTree.members()) {
if (member.is(Tree.Kind.VARIABLE)) {
VariableTree variableTree = (VariableTree) member;
ModifiersTree modifiers = variableTree.modifiers();
ModifierKeywordTree publicModifier = ModifiersUtils.getModifier(modifiers, Modifier.PUBLIC);
if (publicModifier != null && (isNotStaticOrFinal(variableTree.modifiers()) || isMutableFinalMember(variableTree))) {
reportIssue(publicModifier, "Lower the visibility of this field.");
}
} else if (member.is(Tree.Kind.METHOD)) {
MethodTree methodTree = (MethodTree) member;
ModifierKeywordTree publicModifier = ModifiersUtils.getModifier(methodTree.modifiers(), Modifier.PUBLIC);
if (publicModifier != null && isSetter(methodTree)) {
reportIssue(publicModifier, "Lower the visibility of this setter or remove it altogether.");
}
}
}
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class ExceptionsShouldBeImmutableCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
ClassTree classTree = (ClassTree) tree;
if (isException(classTree)) {
for (Tree member : classTree.members()) {
if (member.is(Tree.Kind.VARIABLE) && !isFinal((VariableTree) member)) {
IdentifierTree simpleName = ((VariableTree) member).simpleName();
reportIssue(simpleName, "Make this \"" + simpleName.name() + "\" field final.");
}
}
}
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class CallOuterPrivateMethodCheck method visitNode.
@Override
public void visitNode(Tree tree) {
ClassTree classTree = (ClassTree) tree;
Symbol.TypeSymbol classSymbol = classTree.symbol();
if (isInnerClass(classSymbol)) {
methodInvocationVisitor.setClassSymbol(classSymbol);
classTree.accept(methodInvocationVisitor);
}
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class LeastUpperBoundTest method declaredTypes.
private static List<Type> declaredTypes(String... lines) {
CompilationUnitTree tree = treeOf(lines);
List<Type> results = Lists.newLinkedList();
for (Tree classTree : tree.types()) {
Type type = ((ClassTree) classTree).symbol().type();
results.add(type);
}
return results;
}
Aggregations