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 c6c77dfc3878..f090725bc856 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java @@ -96,8 +96,8 @@ public class JavaCompletionContributor extends CompletionContributor { public boolean accepts(@NotNull PsiSwitchStatement psiSwitchStatement, ProcessingContext context) { final PsiExpression expression = psiSwitchStatement.getExpression(); if(expression == null) return false; - final PsiType type = expression.getType(); - return type instanceof PsiClassType; + PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(expression.getType()); + return aClass != null && aClass.isEnum(); } }))); private static final ElementPattern AFTER_NUMBER_LITERAL = diff --git a/java/java-tests/testData/codeInsight/completion/normal/UnboxedConstantsInCase.java b/java/java-tests/testData/codeInsight/completion/normal/UnboxedConstantsInCase.java new file mode 100644 index 000000000000..7da6075c725c --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/UnboxedConstantsInCase.java @@ -0,0 +1,11 @@ +public class Demo { + void foo(Integer i){ + switch(i) { + case Types.CH + } + } +} + +interface Types { + int CHAR = 2; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normal/UnboxedConstantsInCase_after.java b/java/java-tests/testData/codeInsight/completion/normal/UnboxedConstantsInCase_after.java new file mode 100644 index 000000000000..851926336c8e --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/UnboxedConstantsInCase_after.java @@ -0,0 +1,11 @@ +public class Demo { + void foo(Integer i){ + switch(i) { + case Types.CHAR + } + } +} + +interface Types { + int CHAR = 2; +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index ebd317969196..0ba44f53b878 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -773,6 +773,7 @@ public class ListUtils { public void testSecondMethodParameter() throws Throwable { doTest(); } public void testReturnInCase() throws Throwable { doTest(); } + public void testUnboxedConstantsInCase() throws Throwable { doTest(); } public void testAnnotationWithoutValueMethod() throws Throwable { configureByFile(getTestName(false) + ".java");