CommentRange (List<PsiComment> comments, Document doc, int i, PsiComment comment) { PsiElement firstComment = comment; PsiElement lastComment = comment; final Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(PsiUtilCore.findLanguageFromElement(comment)); if (isLineComment(commenter, comment, doc)) { int sline = doc.getLineNumber(comment.getTextRange().getStartOffset()); int eline = doc.getLineNumber(comment.getTextRange().getEndOffset()); for (int j = i - 1; j >= 0; j--) { PsiComment cmt = comments.get(j); if (isLineComment(commenter, cmt, doc) && doc.getLineNumber(cmt.getTextRange().getEndOffset()) == sline - 1) { firstComment = cmt; sline = doc.getLineNumber(cmt.getTextRange().getStartOffset()); } else { break; } } for (int j = i + 1; j < comments.size(); j++) { PsiComment cmt = comments.get(j); if (isLineComment(commenter, cmt, doc) && doc.getLineNumber(cmt.getTextRange().getStartOffset()) == eline + 1) { lastComment = cmt; eline = doc.getLineNumber(cmt.getTextRange().getEndOffset()); } else { break; } } } return new CommentRange(firstComment, lastComment); }