mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-134433 (Reports any classes declared as implementing or extending an annotation interface inspection could sometimes be missleading)
This commit is contained in:
+2
-1
@@ -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>
|
||||
|
||||
|
||||
+15
@@ -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 "";
|
||||
}
|
||||
+15
@@ -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" +
|
||||
"}"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user