aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PublicApiVisitor.java22
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/MethodsWithOverrideAnnotation.java2
2 files changed, 7 insertions, 17 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PublicApiVisitor.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PublicApiVisitor.java
index a3ef8fa608e..add29bd7b06 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PublicApiVisitor.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PublicApiVisitor.java
@@ -19,20 +19,19 @@
*/
package org.sonar.java.ast.visitor;
+import java.util.Arrays;
+import java.util.List;
+
import org.sonar.java.ast.check.UndocumentedApiCheck;
import org.sonar.squid.api.SourceCode;
import org.sonar.squid.measures.Metric;
-import antlr.collections.AST;
-
+import com.puppycrawl.tools.checkstyle.api.AnnotationUtility;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FileContents;
import com.puppycrawl.tools.checkstyle.api.Scope;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
-import java.util.Arrays;
-import java.util.List;
-
public class PublicApiVisitor extends JavaAstVisitor {
final static String OVERRIDE_ANNOTATION_KEYWORD = "Override";
@@ -69,21 +68,12 @@ public class PublicApiVisitor extends JavaAstVisitor {
private static boolean isMethodWithOverrideAnnotation(DetailAST ast) {
if (isMethod(ast)) {
- DetailAST modifier = ast.findFirstToken(TokenTypes.MODIFIERS);
- for (AST annotation = modifier.getFirstChild(); annotation != null; annotation = annotation.getNextSibling()) {
- if (isAnnotation(annotation) && ((DetailAST) annotation).findFirstToken(TokenTypes.IDENT) != null) {
- String name = ((DetailAST) annotation).findFirstToken(TokenTypes.IDENT).getText();
- return OVERRIDE_ANNOTATION_KEYWORD.equals(name);
- }
- }
+ return AnnotationUtility.containsAnnotation(ast, OVERRIDE_ANNOTATION_KEYWORD)
+ || AnnotationUtility.containsAnnotation(ast, "java.lang." + OVERRIDE_ANNOTATION_KEYWORD);
}
return false;
}
- private static boolean isAnnotation(AST annotation) {
- return annotation.getType() == TokenTypes.ANNOTATION;
- }
-
private static boolean isMethod(DetailAST ast) {
return ast.getType() == TokenTypes.METHOD_DEF;
}
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/MethodsWithOverrideAnnotation.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/MethodsWithOverrideAnnotation.java
index 3d1281be0fb..a0dba5ed7bd 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/MethodsWithOverrideAnnotation.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/MethodsWithOverrideAnnotation.java
@@ -12,7 +12,7 @@ public class MethodsWithOverrideAnnotation {
}
- @Override
+ @java.lang.Override
public void doSomethingElse(){
}