diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SwitchStatementPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SwitchStatementPostfixTemplate.java index 084bd18d9f50..d7ae5480c4e6 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SwitchStatementPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SwitchStatementPostfixTemplate.java @@ -19,6 +19,7 @@ import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; +import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.Function; import org.jetbrains.annotations.NotNull; @@ -48,6 +49,9 @@ public class SwitchStatementPostfixTemplate extends SurroundPostfixTemplateBase if (PsiUtil.isAvailable(JavaFeature.STRING_SWITCH, javaFile)) return true; } + if (PsiUtil.isAvailable(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, expression) && + TypeConversionUtil.isPrimitiveAndNotNull(type)) return true; + return false; }); }; diff --git a/java/java-tests/testData/codeInsight/completion/normal/CompleteSwitchPrimitiveSelectorPostfix.java b/java/java-tests/testData/codeInsight/completion/normal/CompleteSwitchPrimitiveSelectorPostfix.java new file mode 100644 index 000000000000..abd8d7106976 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/CompleteSwitchPrimitiveSelectorPostfix.java @@ -0,0 +1,6 @@ + +class Main { + int g(long o) { + o.swit + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normal/CompleteSwitchPrimitiveSelectorPostfixLowerLanguageLevel.java b/java/java-tests/testData/codeInsight/completion/normal/CompleteSwitchPrimitiveSelectorPostfixLowerLanguageLevel.java new file mode 100644 index 000000000000..abd8d7106976 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/CompleteSwitchPrimitiveSelectorPostfixLowerLanguageLevel.java @@ -0,0 +1,6 @@ + +class Main { + int g(long o) { + o.swit + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normal/CompleteSwitchPrimitiveSelectorPostfixLowerLanguageLevel_after.java b/java/java-tests/testData/codeInsight/completion/normal/CompleteSwitchPrimitiveSelectorPostfixLowerLanguageLevel_after.java new file mode 100644 index 000000000000..82067a785ae0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/CompleteSwitchPrimitiveSelectorPostfixLowerLanguageLevel_after.java @@ -0,0 +1,6 @@ + +class Main { + int g(long o) { + o.swit + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normal/CompleteSwitchPrimitiveSelectorPostfix_after.java b/java/java-tests/testData/codeInsight/completion/normal/CompleteSwitchPrimitiveSelectorPostfix_after.java new file mode 100644 index 000000000000..c2dc2d31c048 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/CompleteSwitchPrimitiveSelectorPostfix_after.java @@ -0,0 +1,8 @@ + +class Main { + int g(long o) { + switch (o) { + + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalSwitchCompletionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalSwitchCompletionTest.java index e15096585f42..8f87dae958cf 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalSwitchCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalSwitchCompletionTest.java @@ -3,6 +3,7 @@ package com.intellij.java.codeInsight.completion; import com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor; import com.intellij.openapi.application.impl.NonBlockingReadActionImpl; +import com.intellij.pom.java.JavaFeature; import com.intellij.pom.java.LanguageLevel; import com.intellij.testFramework.IdeaTestUtil; import com.intellij.testFramework.LightProjectDescriptor; @@ -69,6 +70,16 @@ public class NormalSwitchCompletionTest extends NormalCompletionTestCase { public void testCompleteSwitchObjectSelectorPostfix() { doTestPostfixCompletion(); } + public void testCompleteSwitchPrimitiveSelectorPostfix() { + IdeaTestUtil.withLevel(myFixture.getModule(), JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.getMinimumLevel(), + () -> doTestPostfixCompletion()); + } + + public void testCompleteSwitchPrimitiveSelectorPostfixLowerLanguageLevel() { + IdeaTestUtil.withLevel(myFixture.getModule(), LanguageLevel.JDK_11, + () -> doTestPostfixCompletion()); + } + public void testCompleteSwitchSealedSelectorPostfix() { doTestPostfixCompletion(); } @NeedsIndex.ForStandardLibrary