use of org.sonar.plugins.java.api.tree.AnnotationTree in project sonar-java by SonarSource.
the class MissingDeprecatedCheck method visitNode.
@Override
public void visitNode(Tree tree) {
boolean isLocalVar = false;
if (tree.is(Tree.Kind.VARIABLE)) {
isLocalVar = currentParent.peek().is(METHOD_KINDS);
} else {
currentParent.push(tree);
}
AnnotationTree deprecatedAnnotation = deprecatedAnnotation(tree);
boolean hasDeprecatedAnnotation = deprecatedAnnotation != null;
boolean hasJavadocDeprecatedTag = hasJavadocDeprecatedTag(tree);
if (currentClassNotDeprecated() && !isLocalVar) {
if (hasDeprecatedAnnotation) {
if (!hasJavadocDeprecatedTag) {
reportIssue(getReportTree(tree), "Add the missing @deprecated Javadoc tag.");
} else if (isJava9 && deprecatedAnnotation.arguments().isEmpty()) {
reportIssue(getReportTree(deprecatedAnnotation), "Add 'since' and/or 'forRemoval' arguments to the @Deprecated annotation.");
}
} else if (hasJavadocDeprecatedTag) {
reportIssue(getReportTree(tree), "Add the missing @Deprecated annotation.");
}
}
if (tree.is(CLASS_KINDS)) {
classOrInterfaceIsDeprecated.push(hasDeprecatedAnnotation || hasJavadocDeprecatedTag);
}
}
use of org.sonar.plugins.java.api.tree.AnnotationTree in project sonar-java by SonarSource.
the class ModuleDeclarationTreeImplTest method test_BaseTreeVisitor.
@Test
public void test_BaseTreeVisitor() {
CompilationUnitTree cut = createTree("import org.foo.Bar;", "", "@Bar", "open module com.greetings {", "}");
ModuleDeclarationVisitor moduleDeclarationVisitor = new ModuleDeclarationVisitor();
cut.accept(moduleDeclarationVisitor);
assertThat(moduleDeclarationVisitor.visited).isTrue();
assertThat(moduleDeclarationVisitor.annotations).hasSize(1);
AnnotationTree annotation = moduleDeclarationVisitor.annotations.iterator().next();
assertThat(((IdentifierTree) annotation.annotationType()).name()).isEqualTo("Bar");
}
use of org.sonar.plugins.java.api.tree.AnnotationTree in project sonar-java by SonarSource.
the class SyntaxHighlighterVisitor method visitNode.
@Override
public void visitNode(Tree tree) {
if (tree.is(Tree.Kind.MODULE)) {
withinModule = true;
return;
}
if (tree.is(Tree.Kind.ANNOTATION)) {
AnnotationTree annotationTree = (AnnotationTree) tree;
highlight(annotationTree.atToken(), annotationTree.annotationType(), typesByKind.get(Tree.Kind.ANNOTATION));
} else {
highlight(tree, typesByKind.get(tree.kind()));
}
}
Aggregations