void (CommentTracker ct, SwitchBranch branch, StringBuilder builder) { PsiElement label = ContainerUtil.find(branch.myUsedElements, e -> e instanceof PsiSwitchLabelStatement); if (!(label instanceof PsiSwitchLabelStatement labelStatement)) { return; } PsiSwitchLabelStatement nextLabelStatement = PsiTreeUtil.getNextSiblingOfType(labelStatement, PsiSwitchLabelStatement.class); PsiElement untilComment = null; if (nextLabelStatement != null) { untilComment = PsiTreeUtil.getPrevSiblingOfType(nextLabelStatement, PsiStatement.class); } if (untilComment == null) { PsiElement next = labelStatement.getNextSibling(); if (next != null) { while (next.getNextSibling() != null) { next = next.getNextSibling(); } } untilComment = next; } if (untilComment != null) { String commentsBefore = ct.commentsBefore(untilComment).stripTrailing(); String previousText = builder.toString().stripTrailing(); if (previousText.length() > 1 && previousText.charAt(builder.length() - 1) == '\n') { commentsBefore = StringUtil.trimStart(commentsBefore, "\n"); } if (!commentsBefore.isEmpty()) { commentsBefore += '\n'; } builder.append(commentsBefore); } }