void (@NotNull SwitchBranch branch, @NotNull List<? extends PsiCaseLabelElement> caseExpressions, @NotNull List<SwitchBranch> result) { List<PsiCaseLabelElement> previousExpressions = new ArrayList<>(); for (PsiCaseLabelElement expression : caseExpressions) { PsiCaseLabelElement external = findNullLabel(List.of(expression)); if (external == null && expression instanceof PsiPattern) { external = expression; } if (external == null) { previousExpressions.add(expression); } else { if (!previousExpressions.isEmpty()) { SwitchBranch otherBranch = branch.withLabels(new ArrayList<>(previousExpressions)); result.add(otherBranch); previousExpressions.clear(); } SwitchBranch specialBranch = branch.withLabels(List.of(external)); result.add(specialBranch); } } if (!previousExpressions.isEmpty()) { SwitchBranch otherBranch = branch.withLabels(previousExpressions); result.add(otherBranch); } }