annotation interfaces: highlight methods which override public/protected methods of Object/Annotation (9.6.1. Annotation Type Elements)

This commit is contained in:
anna
2013-04-11 13:14:41 +02:00
parent 2eb25bff4e
commit f622b3c704
4 changed files with 29 additions and 0 deletions

View File

@@ -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)) {

View File

@@ -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) {

View File

@@ -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();
}

View File

@@ -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);