[java-highlighting] IDEA-368498 Errors about incorrect TYPE_USE annotations are not reported by IntelliJ IDEA

GitOrigin-RevId: 05b017fe457e4efaf0685d429bfd6c2e743936cb
This commit is contained in:
Tagir Valeev
2025-03-04 09:52:12 +01:00
committed by intellij-monorepo-bot
parent 7e3a48e6ad
commit bca1a631f8
3 changed files with 21 additions and 1 deletions

View File

@@ -466,7 +466,7 @@ final class AnnotationChecker {
if (applicable == null) {
if (targets.length == 1 && targets[0] == PsiAnnotation.TargetType.TYPE_USE) {
PsiElement parent = annotation.getParent();
if (parent instanceof PsiTypeElement) {
if (parent instanceof PsiTypeElement && !(annotation.getOwner() instanceof PsiArrayType)) {
PsiElement modifierList =
PsiTreeUtil.skipSiblingsBackward(parent, PsiWhiteSpace.class, PsiComment.class, PsiTypeParameterList.class);
if (modifierList instanceof PsiModifierList psiModifierList) {

View File

@@ -0,0 +1,19 @@
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
class Jaba {
public static void accept(String <error descr="'@Ann' not applicable to type use">@Ann</error> [] s) {
}
public static void accept2(@Ann String[] s) {
}
public static void accept3(Jaba.<error descr="'@Ann' not applicable to type use">@Ann</error> Inner s) {
}
public static void accept4(@Ann Jaba.Inner s) {
}
class Inner {}
}
@Target({ElementType.PARAMETER})
@interface Ann {
}

View File

@@ -39,6 +39,7 @@ public class AnnotationsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testAnnotationOverIncompleteCode() { doTest(); }
public void testDeclarations() { doTest(); }
public void testErrorRecovery() { doTest(); }
public void testWrongTargetTypeUse() { doTest(); }
private void doTest() { doTest(getTestName(true) + ".java"); }
private void doTest(String name) { doTest(BASE_PATH + "/" + name, false, false); }