From 1baaa93702f47d4f937dd60c8d5b660b42886571 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 4 Jul 2019 22:05:30 +0200 Subject: [PATCH] [java] drops value break keyword completion GitOrigin-RevId: b713ae661f06245ae400d6aa20ec14d2fa2f20ef --- .../completion/JavaKeywordCompletion.java | 10 +++------- .../normal/BreakDeepInsideSwitchExpression.java | 12 ++++++++++++ .../BreakDeepInsideSwitchExpression_after.java | 12 ++++++++++++ .../completion/Normal13CompletionTest.groovy | 1 + 4 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/normal/BreakDeepInsideSwitchExpression.java create mode 100644 java/java-tests/testData/codeInsight/completion/normal/BreakDeepInsideSwitchExpression_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 feddd32ccc4f..e879ccb24991 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaKeywordCompletion.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaKeywordCompletion.java @@ -773,13 +773,9 @@ public class JavaKeywordCompletion { if (psiElement().inside(PsiSwitchStatement.class).accepts(myPosition)) { addKeyword(br); } - else if (psiElement().inside(PsiSwitchExpression.class).accepts(myPosition)) { - if (PsiUtil.getLanguageLevel(myPosition) == LanguageLevel.JDK_12_PREVIEW) { - addKeyword(TailTypeDecorator.withTail(createKeyword(PsiKeyword.BREAK), TailType.INSERT_SPACE)); - } - else if (PsiUtil.getLanguageLevel(myPosition).isAtLeast(LanguageLevel.JDK_13_PREVIEW)) { - addKeyword(TailTypeDecorator.withTail(createKeyword(PsiKeyword.YIELD), TailType.INSERT_SPACE)); - } + else if (psiElement().inside(PsiSwitchExpression.class).accepts(myPosition) && + PsiUtil.getLanguageLevel(myPosition).isAtLeast(LanguageLevel.JDK_13_PREVIEW)) { + addKeyword(TailTypeDecorator.withTail(createKeyword(PsiKeyword.YIELD), TailType.INSERT_SPACE)); } for (PsiLabeledStatement labeled : psiApi().parents(myPosition).takeWhile(notInstanceOf(PsiMember.class)).filter(PsiLabeledStatement.class)) { diff --git a/java/java-tests/testData/codeInsight/completion/normal/BreakDeepInsideSwitchExpression.java b/java/java-tests/testData/codeInsight/completion/normal/BreakDeepInsideSwitchExpression.java new file mode 100644 index 000000000000..83c52e866543 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/BreakDeepInsideSwitchExpression.java @@ -0,0 +1,12 @@ +class BreakDeepInsideSwitchExpression { + int test(int i) { + return switch (i) { + default -> { + while (true) { + if (--i < 8) br + } + yield i; + }; + }; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normal/BreakDeepInsideSwitchExpression_after.java b/java/java-tests/testData/codeInsight/completion/normal/BreakDeepInsideSwitchExpression_after.java new file mode 100644 index 000000000000..45e3abaf93bc --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/BreakDeepInsideSwitchExpression_after.java @@ -0,0 +1,12 @@ +class BreakDeepInsideSwitchExpression { + int test(int i) { + return switch (i) { + default -> { + while (true) { + if (--i < 8) break; + } + yield i; + }; + }; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/Normal13CompletionTest.groovy b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/Normal13CompletionTest.groovy index 55576f2f1434..3507e8f095b2 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/Normal13CompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/Normal13CompletionTest.groovy @@ -21,4 +21,5 @@ class Normal13CompletionTest extends NormalCompletionTestCase { void testYieldInSwitchExpression() { doTest() } void testInsideYieldInSwitchExpression() { doTest() } void testInsideRuleInSwitchExpression() { doTest() } + void testBreakDeepInsideSwitchExpression() { doTest() } } \ No newline at end of file