IDEA-134433 (Reports any classes declared as implementing or extending an annotation interface inspection could sometimes be missleading)

This commit is contained in:
Bas Leijdekkers
2014-12-17 15:27:08 +01:00
parent 9f366d8b6a
commit 96b1acb481
4 changed files with 34 additions and 3 deletions
@@ -16,6 +16,7 @@
package com.siyeh.ig.inheritance;
import com.intellij.psi.*;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiUtil;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -66,7 +67,7 @@ public class ExtendsAnnotationInspection extends BaseInspection {
@Override
public void visitClass(@NotNull PsiClass aClass) {
if (aClass.isAnnotationType()) {
if (aClass.isAnnotationType() || InheritanceUtil.isInheritor(aClass, "javax.enterprise.util.AnnotationLiteral")) {
return;
}
checkReferenceList(aClass.getExtendsList(), aClass);
@@ -1,8 +1,8 @@
<html>
<body>
Reports any classes declared as implementing or extending an annotation
interface. While it is legal to extend an annotation interface, it is nearly meaningless,
and discouraged.
interface. While it is legal to extend an annotation interface, it is often done by accident,
and the result won't be usable as an annotation.
<!-- tooltip end -->
<p>
@@ -1,5 +1,20 @@
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.enterprise.util.AnnotationLiteral;
public abstract class ExtendsAnnotation implements <warning descr="Class 'ExtendsAnnotation' implements annotation interface 'Override'">Override</warning> {
interface J extends <warning descr="Interface 'J' extends annotation interface 'Override'">Override</warning> {}
}
class One extends AnnotationLiteral<Contains> implements Contains {
@Override
public String value() {
return "test";
}
}
@Documented
@Retention(value= RetentionPolicy.RUNTIME)
@interface Contains {
String value() default "";
}
@@ -33,4 +33,19 @@ public class ExtendsAnnotationInspectionTest extends LightInspectionTestCase {
protected InspectionProfileEntry getInspection() {
return new ExtendsAnnotationInspection();
}
@Override
protected String[] getEnvironmentClasses() {
return new String[] {
"package javax.enterprise.util;\n" +
"import java.lang.annotation.Annotation;\n" +
"public abstract class AnnotationLiteral<T extends Annotation> implements Annotation {\n" +
" protected AnnotationLiteral() {}\n" +
" public Class<? extends Annotation> annotationType() { return null; }\n" +
" @Override public boolean equals(Object other) { return false; }\n" +
" @Override public int hashCode() { return 0; }\n" +
" @Override public String toString() { return \"\"; }\n" +
"}"
};
}
}