mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
annotation interfaces: highlight methods which override public/protected methods of Object/Annotation (9.6.1. Annotation Type Elements)
This commit is contained in:
@@ -465,6 +465,24 @@ public class AnnotationsHighlightUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static HighlightInfo checkClashesWithSuperMethods(@NotNull PsiAnnotationMethod psiMethod) {
|
||||
final PsiIdentifier nameIdentifier = psiMethod.getNameIdentifier();
|
||||
if (nameIdentifier != null) {
|
||||
final PsiMethod[] methods = psiMethod.findDeepestSuperMethods();
|
||||
for (PsiMethod method : methods) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
final String qualifiedName = containingClass.getQualifiedName();
|
||||
if (CommonClassNames.JAVA_LANG_OBJECT.equals(qualifiedName) || CommonClassNames.JAVA_LANG_ANNOTATION_ANNOTATION.equals(qualifiedName)) {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(nameIdentifier).descriptionAndTooltip(
|
||||
"@interface member clashes with '" + HighlightUtil.formatMethod(method) + "' in " + HighlightUtil.formatClass(containingClass)).create();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static HighlightInfo checkAnnotationDeclaration(final PsiElement parent, final PsiReferenceList list) {
|
||||
if (PsiUtil.isAnnotationMethod(parent)) {
|
||||
|
||||
@@ -217,6 +217,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
|
||||
myHolder.add(AnnotationsHighlightUtil.checkValidAnnotationType(method.getReturnTypeElement()));
|
||||
myHolder.add(AnnotationsHighlightUtil.checkCyclicMemberType(method.getReturnTypeElement(), method.getContainingClass()));
|
||||
myHolder.add(AnnotationsHighlightUtil.checkClashesWithSuperMethods(method));
|
||||
}
|
||||
|
||||
@Override public void visitArrayInitializerExpression(PsiArrayInitializerExpression expression) {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@interface A1 {
|
||||
String <error descr="@interface member clashes with 'toString()' in java.lang.Object">toString</error>();
|
||||
Class <error descr="@interface member clashes with 'annotationType()' in java.lang.annotation.Annotation">annotationType</error>();
|
||||
int value();
|
||||
boolean equals();
|
||||
<error descr="Invalid type for annotation member">void</error> <error descr="@interface member clashes with 'finalize()' in java.lang.Object">finalize</error>();
|
||||
<error descr="Invalid type for annotation member">void</error> registerNatives();
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ public class AnnotationsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testRepeatable() { doTest8(false); }
|
||||
|
||||
public void testPingPongAnnotationTypesDependencies() { doTest(false);}
|
||||
public void testClashMethods() { doTest(false);}
|
||||
|
||||
private void doTest(boolean checkWarnings) {
|
||||
setLanguageLevel(LanguageLevel.JDK_1_7);
|
||||
|
||||
Reference in New Issue
Block a user