annotation highlighting: skip unresolved attribute highlighting for non-annotation types

GitOrigin-RevId: 4b705957a414cc90f2b952595f6d6dfbb880f876
This commit is contained in:
Anna Kozlova
2019-05-23 22:05:32 +03:00
committed by intellij-monorepo-bot
parent 893413de5a
commit 5d96e5d9f0
3 changed files with 10 additions and 0 deletions
@@ -47,6 +47,12 @@ public class AnnotationsHighlightUtil {
@Nullable
static HighlightInfo checkNameValuePair(@NotNull PsiNameValuePair pair,
RefCountHolder refCountHolder) {
PsiAnnotation annotation = PsiTreeUtil.getParentOfType(pair, PsiAnnotation.class);
if (annotation == null) return null;
PsiJavaCodeReferenceElement annotationNameReferenceElement = annotation.getNameReferenceElement();
if (annotationNameReferenceElement == null) return null;
PsiElement annotationClass = annotationNameReferenceElement.resolve();
if (!(annotationClass instanceof PsiClass && ((PsiClass)annotationClass).isAnnotationType())) return null;
PsiReference ref = pair.getReference();
if (ref == null) return null;
PsiMethod method = (PsiMethod)ref.resolve();
@@ -0,0 +1,3 @@
class Foo<T> {
@<error descr="Annotation type expected">T</error>(value =2) void foo() {}
}
@@ -32,6 +32,7 @@ public class AnnotationsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIncompatibleType3() { doTest(); }
public void testIncompatibleType4() { doTest(); }
public void testIncompatibleType5() { doTest(); }
public void testIncompatibleWithUnresolvedAttribute() { doTest(); }
public void testMissingAttribute() { doTest(); }
public void testDuplicateAnnotation() { setLanguageLevel(LanguageLevel.JDK_1_7); doTest(); }
public void testNonConstantInitializer() { doTest(); }