From dd15d0e6df2773ecf4c0a270faf01c721862c8e4 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 20 Jun 2012 15:43:40 +0200 Subject: [PATCH] IDEA-83969 code completion in switch/case: auto/unboxing not checked with code completion --- .../completion/JavaCompletionContributor.java | 4 ++-- .../completion/normal/UnboxedConstantsInCase.java | 11 +++++++++++ .../normal/UnboxedConstantsInCase_after.java | 11 +++++++++++ .../completion/NormalCompletionTest.groovy | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/normal/UnboxedConstantsInCase.java create mode 100644 java/java-tests/testData/codeInsight/completion/normal/UnboxedConstantsInCase_after.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 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");