void (@NotNull PsiElement element, @NotNull ActionContext context, @NotNull ModPsiUpdater updater) { final PsiComment selectedComment = (PsiComment) element; PsiComment firstComment = selectedComment; while (true) { final PsiElement prevComment = getPrevNonWhiteSpace(firstComment); if (!isEndOfLineComment(prevComment)) { break; } firstComment = (PsiComment) prevComment; } final JavaPsiFacade manager = JavaPsiFacade.getInstance(selectedComment.getProject()); final PsiElementFactory factory = manager.getElementFactory(); String text = getCommentContents(firstComment); final List<PsiElement> commentsToDelete = new ArrayList<>(); PsiElement nextComment = firstComment; while (true) { nextComment = getNextNonWhiteSpace(nextComment); if (!isEndOfLineComment(nextComment)) { break; } text += nextComment.getPrevSibling().getText() + " " //to get the whitespace for proper spacing + getCommentContents((PsiComment) nextComment); commentsToDelete.add(nextComment); } final PsiComment newComment = factory.createCommentFromText("/*" + text + " */", selectedComment.getParent()); firstComment.replace(newComment); for (PsiElement commentToDelete : commentsToDelete) { commentToDelete.delete(); } }