Search in sources :

Example 11 with AnnotationTree

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);
    }
}
Also used : AnnotationTree(org.sonar.plugins.java.api.tree.AnnotationTree)

Example 12 with AnnotationTree

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");
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) AnnotationTree(org.sonar.plugins.java.api.tree.AnnotationTree) Test(org.junit.Test)

Example 13 with AnnotationTree

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()));
    }
}
Also used : AnnotationTree(org.sonar.plugins.java.api.tree.AnnotationTree)

Aggregations

AnnotationTree (org.sonar.plugins.java.api.tree.AnnotationTree)13 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)5 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)5 Symbol (org.sonar.plugins.java.api.semantic.Symbol)3 AssignmentExpressionTree (org.sonar.plugins.java.api.tree.AssignmentExpressionTree)3 MemberSelectExpressionTree (org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 Rule (org.sonar.check.Rule)2 LiteralUtils (org.sonar.java.model.LiteralUtils)2 JavaSymbol (org.sonar.java.resolve.JavaSymbol)2 IssuableSubscriptionVisitor (org.sonar.plugins.java.api.IssuableSubscriptionVisitor)2 TypeSymbol (org.sonar.plugins.java.api.semantic.Symbol.TypeSymbol)2 LiteralTree (org.sonar.plugins.java.api.tree.LiteralTree)2 NewArrayTree (org.sonar.plugins.java.api.tree.NewArrayTree)2 Tree (org.sonar.plugins.java.api.tree.Tree)2 VariableTree (org.sonar.plugins.java.api.tree.VariableTree)2 Joiner (com.google.common.base.Joiner)1