String (@NotNull PsiElement element) { List<PsiElement> comments = grabCommentsBefore(element); if (comments.isEmpty()) return ""; StringBuilder sb = new StringBuilder(); for (PsiElement comment : comments) { PsiElement prev = comment.getPrevSibling(); if (sb.length() == 0 && prev instanceof PsiWhiteSpace) { sb.append(prev.getText()); } sb.append(comment.getText()); PsiElement next = PsiTreeUtil.nextLeaf(comment); if (next instanceof PsiWhiteSpace) { sb.append(next.getText()); } } comments.forEach(PsiElement::delete); return sb.toString(); }