use of org.sonar.plugins.java.api.tree.ModifiersTree 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.ModifiersTree in project sonar-java by SonarSource.
the class ClassVariableVisibilityCheck method visitVariable.
@Override
public void visitVariable(VariableTree tree) {
ModifiersTree modifiers = tree.modifiers();
List<AnnotationTree> annotations = modifiers.annotations();
if (isClass() && isPublic(modifiers) && !(isFinal(modifiers) || !annotations.isEmpty())) {
context.reportIssue(this, tree.simpleName(), "Make " + tree.simpleName() + " a static final constant or non-public and provide accessors if needed.");
}
super.visitVariable(tree);
}
use of org.sonar.plugins.java.api.tree.ModifiersTree in project sonar-java by SonarSource.
the class RedundantModifierCheck method visitNode.
@Override
public void visitNode(Tree tree) {
ClassTree classTree = (ClassTree) tree;
for (Tree member : classTree.members()) {
if (member.is(Tree.Kind.METHOD)) {
MethodTree methodTree = (MethodTree) member;
ModifiersTree modifiers = methodTree.modifiers();
if (isInterfaceOrAnnotation(tree)) {
checkRedundantModifier(modifiers, Modifier.ABSTRACT);
checkRedundantModifier(modifiers, Modifier.PUBLIC);
} else if (ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.FINAL)) {
checkRedundantModifier(modifiers, Modifier.FINAL);
}
} else if (member.is(Tree.Kind.VARIABLE) && isInterfaceOrAnnotation(tree)) {
VariableTree variableTree = (VariableTree) member;
ModifiersTree modifiers = variableTree.modifiers();
checkRedundantModifier(modifiers, Modifier.PUBLIC);
checkRedundantModifier(modifiers, Modifier.STATIC);
checkRedundantModifier(modifiers, Modifier.FINAL);
} else if (member.is(Kind.CONSTRUCTOR) && tree.is(Kind.ENUM)) {
checkRedundantModifier(((MethodTree) member).modifiers(), Modifier.PRIVATE);
}
}
}
Aggregations