IDEA-248001 Annotation parameter completion in generics doesn't work correctly
authorPeter Gromov <peter@jetbrains.com>
Wed, 12 Aug 2020 07:38:31 +0000 (09:38 +0200)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 12 Aug 2020 07:39:00 +0000 (07:39 +0000)
GitOrigin-RevId: e723f01752834d2545b3d26a46693436d35fb6fb

java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java
java/java-tests/testData/codeInsight/completion/normal/EnumInTypeAnnotation.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/completion/normal/EnumInTypeAnnotation_after.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy

index 9600dded415114487e35544db42df4bf6ed29f98..624acf15e374b667e23ca1ea1ccc9324f0529a79 100644 (file)
@@ -117,7 +117,7 @@ public class JavaCompletionContributor extends CompletionContributor implements
     if (JavaKeywordCompletion.isDeclarationStart(position) ||
         JavaKeywordCompletion.isInsideParameterList(position) ||
         isInsideAnnotationName(position) ||
     if (JavaKeywordCompletion.isDeclarationStart(position) ||
         JavaKeywordCompletion.isInsideParameterList(position) ||
         isInsideAnnotationName(position) ||
-        psiElement().inside(PsiReferenceParameterList.class).accepts(position) ||
+        PsiTreeUtil.getParentOfType(position, PsiReferenceParameterList.class, false, PsiAnnotation.class) != null ||
         isDefinitelyVariableType(position)) {
       return new OrFilter(ElementClassFilter.CLASS, ElementClassFilter.PACKAGE);
     }
         isDefinitelyVariableType(position)) {
       return new OrFilter(ElementClassFilter.CLASS, ElementClassFilter.PACKAGE);
     }
diff --git a/java/java-tests/testData/codeInsight/completion/normal/EnumInTypeAnnotation.java b/java/java-tests/testData/codeInsight/completion/normal/EnumInTypeAnnotation.java
new file mode 100644 (file)
index 0000000..ceddb1d
--- /dev/null
@@ -0,0 +1,14 @@
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.List;
+
+class A {
+  List<@Anno(value = Anno.MyEnum.f<caret>) String> l;
+
+}
+
+@Target(ElementType.TYPE_USE)
+@interface Anno {
+  enum MyEnum {foo,bar}
+  MyEnum value();
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/completion/normal/EnumInTypeAnnotation_after.java b/java/java-tests/testData/codeInsight/completion/normal/EnumInTypeAnnotation_after.java
new file mode 100644 (file)
index 0000000..a6a8294
--- /dev/null
@@ -0,0 +1,14 @@
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.List;
+
+class A {
+  List<@Anno(value = Anno.MyEnum.foo<caret>) String> l;
+
+}
+
+@Target(ElementType.TYPE_USE)
+@interface Anno {
+  enum MyEnum {foo,bar}
+  MyEnum value();
+}
\ No newline at end of file
index e14ee12ebec4fd91c1f81290a6600a4752b4c765..937aebd9c166866b61df06c23fd64cc0b99b7ac6 100644 (file)
@@ -328,6 +328,8 @@ class NormalCompletionTest extends NormalCompletionTestCase {
     checkResultByFile("Annotation4_after.java")
   }
 
     checkResultByFile("Annotation4_after.java")
   }
 
+  void testEnumInTypeAnnotation() { doTest() }
+
   void testSecondAttribute() throws Exception {
     configureByFile("Annotation6.java")
     checkResultByFile("Annotation6_after.java")
   void testSecondAttribute() throws Exception {
     configureByFile("Annotation6.java")
     checkResultByFile("Annotation6_after.java")