[java-highlighting] IDEA-324641 Allow fallthrough for empty block

GitOrigin-RevId: e60d99c7c4e142d0df91601e9bcee02f4ff4cd7e
This commit is contained in:
Mikhail Pyltsin
2023-07-11 13:31:09 +00:00
committed by intellij-monorepo-bot
parent 51ab1f234c
commit aeb1714a62
3 changed files with 15 additions and 1 deletions
@@ -925,6 +925,12 @@ public class SwitchBlockHighlightingModel {
addIllegalFallThroughError(problem.element(), problem.message(), holder, alreadyFallThroughElements);
}
else if (JavaPsiPatternUtil.containsPatternVariable(first)) {
PsiElement nextNotLabel = PsiTreeUtil.skipSiblingsForward(switchLabelElement, PsiWhiteSpace.class, PsiComment.class,
PsiSwitchLabelStatement.class);
//there is no statement, it is allowed to go through (14.11.1 JEP 440-441)
if (!(nextNotLabel instanceof PsiStatement)) {
continue;
}
if (PsiTreeUtil.skipWhitespacesAndCommentsForward(switchLabelElement) instanceof PsiSwitchLabelStatement) {
addIllegalFallThroughError(first, "multiple.switch.labels", holder, alreadyFallThroughElements);
}
@@ -187,4 +187,11 @@ class IllegalFallthroughIn21Java {
}
}
void emptyCase(Object o) {
switch (o) {
case Integer a1:
case Object a222:
// System.out.println("1");
}
}
}
@@ -52,7 +52,8 @@ public class LightPatternsForSwitchHighlightingTest extends LightJavaCodeInsight
}
public void testIllegalFallthroughIn20Java() {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_20_PREVIEW, this::doTest);
//there are no changes in 20->21
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, this::doTest);
}
public void testIllegalFallthroughIn21Java() {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, this::doTest);