void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { PsiCaseLabelElement label = ObjectUtils.tryCast(element, PsiCaseLabelElement.class); if (label == null) return; PsiSwitchLabelStatementBase labelStatement = PsiImplUtil.getSwitchLabel(label); if (labelStatement == null) return; PsiSwitchBlock block = labelStatement.getEnclosingSwitchBlock(); if (block == null) return; List<PsiSwitchLabelStatementBase> labels = PsiTreeUtil.getChildrenOfTypeAsList(block.getBody(), PsiSwitchLabelStatementBase.class); boolean shouldKeepDefault = block instanceof PsiSwitchExpression && !(labelStatement instanceof PsiSwitchLabeledRuleStatement ruleStatement && ruleStatement.getBody() instanceof PsiExpressionStatement); Set<PsiCaseLabelElement> removableUnreachableBranches = new HashSet<>(SwitchUtils.findRemovableUnreachableBranches(label, block)); for (PsiSwitchLabelStatementBase otherLabel : labels) { if (otherLabel == labelStatement) continue; boolean isDefault = SwitchUtils.isDefaultLabel(otherLabel); PsiCaseLabelElementList otherElementList = otherLabel.getCaseLabelElementList(); if (otherElementList != null) { PsiCaseLabelElement[] otherElements = otherElementList.getElements(); if(!removableUnreachableBranches.containsAll(Set.of(otherElements)) && !isDefault) continue; } if (!shouldKeepDefault || !isDefault) { DeleteSwitchLabelFix.deleteLabel(otherLabel); } else { deleteLabelsExceptDefault(otherLabel); } } for (PsiCaseLabelElement labelElement : Objects.requireNonNull(labelStatement.getCaseLabelElementList()).getElements()) { boolean isDefault = labelElement instanceof PsiDefaultCaseLabelElement; if(!removableUnreachableBranches.contains(labelElement) && !isDefault) continue; if (labelElement != label && !(shouldKeepDefault && isDefault)) { new CommentTracker().deleteAndRestoreComments(labelElement); } } tryUnwrap(labelStatement, label, block); }