From 424001aef52825cf062f9567b6db936512440c9e Mon Sep 17 00:00:00 2001 From: Mikhail Pyltsin Date: Fri, 7 Jul 2023 14:27:18 +0200 Subject: [PATCH] [java-highlighting] IDEA-324445 IJ-CR-110332 offer `when` after TypePattern GitOrigin-RevId: e83a11865b073e51f26361121a739d4977abf17b --- .../codeInsight/completion/JavaKeywordCompletion.java | 3 +-- .../codeInsight/completion/normal/WhenInSwitchRule.java | 7 +++++++ .../completion/normal/WhenInSwitchRule_after.java | 7 +++++++ .../codeInsight/completion/NormalSwitchCompletionTest.java | 3 ++- 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/normal/WhenInSwitchRule.java create mode 100644 java/java-tests/testData/codeInsight/completion/normal/WhenInSwitchRule_after.java diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaKeywordCompletion.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaKeywordCompletion.java index 5bcda425e707..a18b6c4c0b05 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaKeywordCompletion.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaKeywordCompletion.java @@ -318,8 +318,7 @@ public class JavaKeywordCompletion { } private void addWhen() { - LanguageLevel level = PsiUtil.getLanguageLevel(myPosition); - if (!(level == LanguageLevel.JDK_20_PREVIEW || level.isAtLeast(LanguageLevel.JDK_21))) { + if (!HighlightingFeature.PATTERN_GUARDS_AND_RECORD_PATTERNS.isAvailable(myPosition)) { return; } PsiElement element = PsiTreeUtil.skipWhitespacesAndCommentsForward(myPrevLeaf); diff --git a/java/java-tests/testData/codeInsight/completion/normal/WhenInSwitchRule.java b/java/java-tests/testData/codeInsight/completion/normal/WhenInSwitchRule.java new file mode 100644 index 000000000000..df0656cbe3d3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/WhenInSwitchRule.java @@ -0,0 +1,7 @@ +class Main { + void f(Object o) { + switch (o) { + case String s whe + } + } +} diff --git a/java/java-tests/testData/codeInsight/completion/normal/WhenInSwitchRule_after.java b/java/java-tests/testData/codeInsight/completion/normal/WhenInSwitchRule_after.java new file mode 100644 index 000000000000..e7f6adb865fb --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/WhenInSwitchRule_after.java @@ -0,0 +1,7 @@ +class Main { + void f(Object o) { + switch (o) { + case String s when + } + } +} 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 37d4538c4a4a..0d965433f558 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 @@ -10,7 +10,7 @@ public class NormalSwitchCompletionTest extends NormalCompletionTestCase { @NotNull @Override protected LightProjectDescriptor getProjectDescriptor() { - return JAVA_20; + return JAVA_21; } public void testDefaultInRuleSwitch() { doTest(); } @@ -81,6 +81,7 @@ public class NormalSwitchCompletionTest extends NormalCompletionTestCase { public void testCompleteFinalInsideSwitch() { doTest("\n"); } public void testCompleteYieldInsideSwitch() { doTest(); } + public void testWhenInSwitchRule() { doTest(); } private void doTestPostfixCompletion() { LiveTemplateCompletionContributor.setShowTemplatesInTests(true, myFixture.getTestRootDisposable());