[java] type annotation highlighting on type parameters (IDEA-174317)

This commit is contained in:
Roman Shevchenko
2017-06-30 14:38:56 +02:00
parent 4e00a8b542
commit 80bd33fc56
2 changed files with 13 additions and 11 deletions
@@ -376,9 +376,10 @@ public class AnnotationsHighlightUtil {
HighlightInfo info = checkReferenceTarget(annotation, ref);
if (info != null) return info;
}
else if (owner instanceof PsiModifierList) {
PsiElement nextElement = PsiTreeUtil.skipSiblingsForward((PsiModifierList)owner,
PsiComment.class, PsiWhiteSpace.class, PsiTypeParameterList.class);
else if (owner instanceof PsiModifierList || owner instanceof PsiTypeElement) {
PsiElement nextElement = owner instanceof PsiTypeElement
? (PsiTypeElement)owner
: PsiTreeUtil.skipSiblingsForward((PsiModifierList)owner, PsiComment.class, PsiWhiteSpace.class, PsiTypeParameterList.class);
if (nextElement instanceof PsiTypeElement) {
PsiTypeElement typeElement = (PsiTypeElement)nextElement;
PsiType type = typeElement.getType();
@@ -391,13 +392,11 @@ public class AnnotationsHighlightUtil {
HighlightInfo info = checkReferenceTarget(annotation, ref);
if (info != null) return info;
}
}
}
else if (owner instanceof PsiTypeElement) {
PsiElement context = PsiTreeUtil.skipParentsOfType((PsiTypeElement)owner, PsiTypeElement.class);
if (context instanceof PsiClassObjectAccessExpression) {
String message = JavaErrorMessages.message("annotation.not.allowed.class");
return annotationError(annotation, message);
PsiElement context = PsiTreeUtil.skipParentsOfType(typeElement, PsiTypeElement.class);
if (context instanceof PsiClassObjectAccessExpression) {
String message = JavaErrorMessages.message("annotation.not.allowed.class");
return annotationError(annotation, message);
}
}
}
}
@@ -51,7 +51,8 @@ class Outer {
@TA StaticInner v1;
<error descr="Static member qualifying type may not be annotated">@TA</error> StaticMiddle.@TA StaticInner v2;
<error descr="Static member qualifying type may not be annotated">@TA</error> Outer.<error descr="Static member qualifying type may not be annotated">@TA</error> StaticMiddle.@TA StaticInner v3;
List<@TA Outer.<error descr="Static member qualifying type may not be annotated">@TA</error> StaticMiddle.@TA StaticInner> l;
List<Outer.<error descr="Static member qualifying type may not be annotated">@TA</error> StaticMiddle.@TA StaticInner> l1;
List<<error descr="Static member qualifying type may not be annotated">@TA</error> Outer.StaticMiddle.@TA StaticInner> l2;
}
}
}
@@ -67,7 +68,9 @@ class Outer {
@A Map.@TA Entry e1;
@A <error descr="Static member qualifying type may not be annotated">@TA</error> Map.@TA Entry e2;
@A java.<error descr="Annotation not applicable to this kind of reference">@TA</error> util.Map.@TA Entry e3;
@A <error descr="Annotation not applicable to this kind of reference">@TA</error> java.util.Map.@TA Entry e4;
@A List<java.<error descr="Annotation not applicable to this kind of reference">@TA</error> lang.@TA String> l1;
@A List<<error descr="Annotation not applicable to this kind of reference">@TA</error> java.lang.String> l2;
Object obj = "str";
@TA String str = (@TA String)obj;