boolean (@NotNull PsiElement place) { if (place instanceof PsiCodeBlock) return true; boolean java20plus = PsiUtil.getLanguageLevel(place).isAtLeast(LanguageLevel.JDK_20_PREVIEW); final AtomicBoolean thisSwitchLabelIsImmediate = new AtomicBoolean(); PsiTreeUtil.treeWalkUp(place, getParent(), (currentScope, __) -> { PsiSwitchLabelStatementBase immediateSwitchLabel; if (currentScope instanceof PsiSwitchLabelStatementBase) { immediateSwitchLabel = (PsiSwitchLabelStatementBase)currentScope; } else { immediateSwitchLabel = PsiTreeUtil.getPrevSiblingOfType(currentScope, PsiSwitchLabelStatementBase.class); } while (immediateSwitchLabel != null && !java20plus && (PsiTreeUtil.getPrevSiblingOfType(immediateSwitchLabel, PsiStatement.class) instanceof PsiSwitchLabelStatementBase && isCaseNull(immediateSwitchLabel))) { /* Example 1: case null: System.out.println("null"); case String s: // illegal fall-through to a pattern in any version of Java System.out.println("String " + s); break; Example 2: case null: case String s: // legal in Java 17-19 Preview, illegal in Java 20 Preview System.out.println("String " + s); break; */ immediateSwitchLabel = PsiTreeUtil.getPrevSiblingOfType(immediateSwitchLabel, PsiSwitchLabelStatementBase.class); } if (immediateSwitchLabel == this) { thisSwitchLabelIsImmediate.set(true); return false; } return true; }); return thisSwitchLabelIsImmediate.get(); }