[java-highlighting] IDEA-289314 Missing highlighting for nested type annotations on static types

- annotations are checked recursively

GitOrigin-RevId: a8343f6bbfbf2dd39b29dad8ce1e989e71a0e549
This commit is contained in:
Mikhail Pyltsin
2023-11-13 17:04:49 +00:00
committed by intellij-monorepo-bot
parent 8adeaf3193
commit 87dc3f3fbf
2 changed files with 24 additions and 1 deletions
@@ -511,13 +511,19 @@ public final class AnnotationsHighlightUtil {
}
PsiElement parent = ref.getParent();
if (parent instanceof PsiJavaCodeReferenceElement) {
while (parent instanceof PsiJavaCodeReferenceElement) {
PsiElement qualified = ((PsiJavaCodeReferenceElement)parent).resolve();
if (qualified instanceof PsiMember && ((PsiMember)qualified).hasModifierProperty(PsiModifier.STATIC)) {
return createAnnotationError(annotation,
JavaErrorBundle.message("annotation.not.allowed.static"),
new MoveAnnotationOnStaticMemberQualifyingTypeFix(annotation).asIntention());
}
if (qualified instanceof PsiClass) {
parent = parent.getParent();
}
else {
break;
}
}
return null;
}
@@ -133,4 +133,21 @@ class Outer {
IntFunction<Super> f = Outer.<error descr="Annotations are not allowed here">@TA</error> This.super::getField;
}
}
void testAnnotation() {
<error descr="Static member qualifying type may not be annotated">@TA</error> T.Y.U.I.O o2;
T.<error descr="Static member qualifying type may not be annotated">@TA</error> Y.U.I.O o;
T.Y.<error descr="Static member qualifying type may not be annotated">@TA</error> U.I.O o3;
T.Y.U.<error descr="Static member qualifying type may not be annotated">@TA</error> I.O o4;
}
public class T {
public static class Y {
public class U {
public class I {
public static class O { }
}
}
}
}
}