mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Java: fix incorrect "Static member qualifying type may not be annotated" (IDEA-210876)
GitOrigin-RevId: 48d08a4d0d3db72fa458d7d67f6ccd72a435b4c8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
17f1796f15
commit
288342ddfc
+7
-16
@@ -461,24 +461,16 @@ final class AnnotationChecker {
|
||||
if (myVisitor.hasErrorResults()) return;
|
||||
}
|
||||
|
||||
if (!(annotation.getOwner() instanceof PsiArrayType) && annotation.getParent() instanceof PsiTypeElement typeElement) {
|
||||
PsiElement element = PsiTreeUtil.skipParentsOfType(typeElement, PsiTypeElement.class);
|
||||
if (element instanceof PsiModifierListOwner modifierListOwner) {
|
||||
targets = AnnotationTargetUtil.getTargetsForLocation(modifierListOwner.getModifierList());
|
||||
}
|
||||
}
|
||||
PsiAnnotation.TargetType applicable = AnnotationTargetUtil.findAnnotationTarget(annotation, targets);
|
||||
if (applicable == PsiAnnotation.TargetType.UNKNOWN) return;
|
||||
|
||||
if (applicable == null) {
|
||||
if (targets.length == 1 && targets[0] == PsiAnnotation.TargetType.TYPE_USE) {
|
||||
PsiElement parent = annotation.getParent();
|
||||
if (parent instanceof PsiTypeElement && !(annotation.getOwner() instanceof PsiArrayType)) {
|
||||
PsiElement modifierList =
|
||||
PsiTreeUtil.skipSiblingsBackward(parent, PsiWhiteSpace.class, PsiComment.class, PsiTypeParameterList.class);
|
||||
if (modifierList instanceof PsiModifierList psiModifierList) {
|
||||
targets = AnnotationTargetUtil.getTargetsForLocation(psiModifierList);
|
||||
if (AnnotationTargetUtil.findAnnotationTarget(annotation, targets) == null) {
|
||||
myVisitor.report(JavaErrorKinds.ANNOTATION_NOT_APPLICABLE.create(annotation, Arrays.asList(targets)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
myVisitor.report(JavaErrorKinds.ANNOTATION_NOT_APPLICABLE.create(annotation, Arrays.asList(targets)));
|
||||
return;
|
||||
}
|
||||
@@ -489,8 +481,7 @@ final class AnnotationChecker {
|
||||
return;
|
||||
}
|
||||
if (owner instanceof PsiClassReferenceType referenceType) {
|
||||
PsiJavaCodeReferenceElement ref = referenceType.getReference();
|
||||
checkReferenceTarget(annotation, ref);
|
||||
checkReferenceTarget(annotation, referenceType.getReference());
|
||||
}
|
||||
else if (owner instanceof PsiModifierList || owner instanceof PsiTypeElement) {
|
||||
PsiElement nextElement = owner instanceof PsiTypeElement typeElementOwner
|
||||
|
||||
+17
-1
@@ -1,3 +1,4 @@
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@interface Ann { }
|
||||
|
||||
@@ -5,4 +6,19 @@ class Foo {
|
||||
<K> @Ann String getFoo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
class Example {
|
||||
|
||||
public static class Foo {
|
||||
public interface Bar<T> {}
|
||||
}
|
||||
|
||||
public static <T> @One Foo.Bar<T> test1(T t) { return null; }
|
||||
public static <T> <error descr="Static member qualifying type may not be annotated">@Two</error> Foo.Bar<T> test2(T t) { return null; }
|
||||
|
||||
}
|
||||
@Target(ElementType.METHOD)
|
||||
@interface One {}
|
||||
|
||||
@Target(ElementType.TYPE_USE)
|
||||
@interface Two {}
|
||||
Reference in New Issue
Block a user