diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateSwitchIntention.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateSwitchIntention.java index 1a308ae21b25..1b10c08ec56c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateSwitchIntention.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateSwitchIntention.java @@ -60,18 +60,22 @@ public class CreateSwitchIntention extends BaseElementAtCaretIntentionAction imp } private static boolean isValidTypeForSwitch(@Nullable PsiType type, PsiElement context) { - if (type == null) { - return false; - } - if (type instanceof PsiClassType) { PsiClass resolvedClass = ((PsiClassType)type).resolve(); if (resolvedClass == null) { return false; } - return (PsiUtil.isLanguageLevel5OrHigher(context) && resolvedClass.isEnum()) + return (PsiUtil.isLanguageLevel5OrHigher(context) && + (resolvedClass.isEnum() || isSuitablePrimitiveType(PsiPrimitiveType.getUnboxedType(type)))) || (PsiUtil.isLanguageLevel7OrHigher(context) && CommonClassNames.JAVA_LANG_STRING.equals(resolvedClass.getQualifiedName())); } + return isSuitablePrimitiveType(type); + } + + private static boolean isSuitablePrimitiveType(@Nullable PsiType type) { + if (type == null) { + return false; + } return type.equals(PsiType.INT) || type.equals(PsiType.BYTE) || type.equals(PsiType.SHORT) || type.equals(PsiType.CHAR); } diff --git a/java/java-tests/testData/codeInsight/createSwitch/boxedType.java b/java/java-tests/testData/codeInsight/createSwitch/boxedType.java new file mode 100644 index 000000000000..d65840c3a1aa --- /dev/null +++ b/java/java-tests/testData/codeInsight/createSwitch/boxedType.java @@ -0,0 +1,10 @@ +class X { + + void m() { + + Byte foo = 10; + foo + + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/createSwitch/boxedType_after.java b/java/java-tests/testData/codeInsight/createSwitch/boxedType_after.java new file mode 100644 index 000000000000..b6b4a6782129 --- /dev/null +++ b/java/java-tests/testData/codeInsight/createSwitch/boxedType_after.java @@ -0,0 +1,11 @@ +class X { + + void m() { + + Byte foo = 10; + switch (foo) { + } + + } + +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/intention/CreateSwitchTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/intention/CreateSwitchTest.java index 62677d9caa08..bb0a258a3b4a 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/intention/CreateSwitchTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/intention/CreateSwitchTest.java @@ -47,6 +47,10 @@ public class CreateSwitchTest extends JavaCodeInsightFixtureTestCase { doTest(); } + public void testBoxedType() { + doTest(); + } + public void testNotAvailable() { doTestNotAvailable(); }