From 03fd1b00f571e76014ccf291a90ca51e4e70a2ec Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 5 Oct 2018 18:10:21 +0200 Subject: [PATCH] disable completion after enum constant (IDEA-199935) --- .../completion/JavaCompletionContributor.java | 10 ++++++++-- .../normal/NoSuggestionsAfterEnumConstant.java | 5 +++++ .../codeInsight/completion/NormalCompletionTest.groovy | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/normal/NoSuggestionsAfterEnumConstant.java diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java index 07b0682bfa85..f7447f4e2c14 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java @@ -98,6 +98,8 @@ public class JavaCompletionContributor extends CompletionContributor { psiElement().withText("}").withParent( psiElement(PsiCodeBlock.class).afterLeaf(PsiKeyword.TRY))); private static final ElementPattern INSIDE_CONSTRUCTOR = psiElement().inside(psiMethod().constructor(true)); + private static final ElementPattern AFTER_ENUM_CONSTANT = + psiElement().inside(PsiTypeElement.class).afterLeaf(psiElement().inside(true, psiElement(PsiEnumConstant.class), psiClass())); @Nullable public static ElementFilter getReferenceFilter(PsiElement position) { @@ -219,7 +221,9 @@ public class JavaCompletionContributor extends CompletionContributor { return; } - if (AFTER_NUMBER_LITERAL.accepts(position) || UNEXPECTED_REFERENCE_AFTER_DOT.accepts(position)) { + if (AFTER_NUMBER_LITERAL.accepts(position) || + UNEXPECTED_REFERENCE_AFTER_DOT.accepts(position) || + AFTER_ENUM_CONSTANT.accepts(position)) { _result.stopHere(); return; } @@ -512,7 +516,9 @@ public class JavaCompletionContributor extends CompletionContributor { boolean isSecondCompletion = parameters.getInvocationCount() >= 2; PsiElement position = parameters.getPosition(); - if (JavaKeywordCompletion.isInstanceofPlace(position) || JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN.accepts(position)) { + if (JavaKeywordCompletion.isInstanceofPlace(position) || + JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN.accepts(position) || + AFTER_ENUM_CONSTANT.accepts(position)) { return false; } diff --git a/java/java-tests/testData/codeInsight/completion/normal/NoSuggestionsAfterEnumConstant.java b/java/java-tests/testData/codeInsight/completion/normal/NoSuggestionsAfterEnumConstant.java new file mode 100644 index 000000000000..c2f13d487512 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/NoSuggestionsAfterEnumConstant.java @@ -0,0 +1,5 @@ +enum MarkerType { + QUERY, SYNONYM, CLASS_ALIAS, NAMED_QUERY + + s +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy index 071a63631fd7..015d5e09ef1d 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy @@ -1869,4 +1869,6 @@ class Abc { myFixture.checkResult 'class Foo { Foo> }' } + void testNoSuggestionsAfterEnumConstant() { doAntiTest() } + }