String (PsiSwitchLabeledRuleStatement rule, CommentTracker ct, PsiSwitchBlock switchBlock) { StreamEx.ofTree((PsiElement)rule, el -> StreamEx.of(el.getChildren())) .select(PsiYieldStatement.class) .filter(statement -> statement.getExpression() != null && statement.findEnclosingExpression() == switchBlock) .forEach(statement -> handleYieldInside(statement, ct)); PsiCaseLabelElementList labelElementList = rule.getCaseLabelElementList(); String caseExpressionsText; if (labelElementList == null || labelElementList.getElementCount() == 0) { if (SwitchUtils.isDefaultLabel(rule)) { caseExpressionsText = "default:"; } else { caseExpressionsText = "case:"; } } else { PsiCaseLabelElement[] labelElements = labelElementList.getElements(); if (ContainerUtil.exists(labelElements, label -> label instanceof PsiPattern)) { //to preserve the style, when labels are listed separated by commas PsiExpression guardExpression = rule.getGuardExpression(); String guardText = guardExpression == null ? "" : " when " + ct.text(guardExpression); caseExpressionsText = StreamEx.of(labelElements) .map(e -> ct.text(e)) .joining(",", "case " , guardText + ":"); } else { caseExpressionsText = StreamEx.of(labelElements) .map(e -> e instanceof PsiDefaultCaseLabelElement ? (ct.text(e) + ":") : ("case " + ct.text(e) + ":")) .joining("\n"); } } PsiStatement body = rule.getBody(); String finalBody; if (body == null) { finalBody = ""; } else if (!(body instanceof PsiBlockStatement)) { finalBody = generateExpressionBranch(body, ct); } else { finalBody = generateBlockBranch(body, ct); } ct.grabComments(rule); return caseExpressionsText + finalBody; }