void (@NotNull PsiElement element) { final PsiComment oldComment = (PsiComment)element; final PsiElement parent = oldComment.getParent(); assert parent != null; final String commentText = oldComment.getText(); final String text = commentText.substring(2, commentText.length() - 2); final String[] lines = text.split("\n"); final int tabSize = getTabSize(oldComment); final int textColumn = getTextStartColumn(text, tabSize); final int commentColumn = getCommentStartColumn(oldComment, tabSize); final int column = textColumn >= 0 ? textColumn : commentColumn - textColumn + 1; trimLinesWithAlignment(lines, tabSize, column); final Project project = oldComment.getProject(); // newline followed by space convinces formatter to indent line final PsiElement ws = PsiParserFacade.getInstance(project).createWhiteSpaceFromText("\n "); final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory(); final int last = lines[lines.length - 1].trim().isEmpty() ? lines.length - 2 : lines.length - 1; final int first = lines[0].trim().isEmpty() ? 1 : 0; for (int i = last; i > first; i--) { parent.addAfter(factory.createCommentFromText("// " + lines[i], parent), oldComment); if (commentColumn > 0) parent.addAfter(ws, oldComment); } String firstLine = (textColumn >= 0 ? "// " : "//") + (first >= lines.length ? "" : lines[first]); oldComment.replace(factory.createCommentFromText(firstLine, parent)); }