TextRange (@NotNull PsiComment startComment, @NotNull Set<? super PsiElement> processedComments, @NotNull Predicate<? super PsiElement> isCustomRegionFunc, @NotNull CodeDocumentationAwareCommenter docCommenter) { if (isCustomRegionFunc.test(startComment)) return null; PsiElement end = null; for (PsiElement current = startComment.getNextSibling(); current != null; current = current.getNextSibling()) { ASTNode node = current.getNode(); if (node == null) { break; } final IElementType elementType = node.getElementType(); if (elementType == docCommenter.getLineCommentTokenType() && !isCustomRegionFunc.test(current) && !processedComments.contains(current)) { end = current; // We don't want to process, say, the second comment in case of three subsequent comments when it's being examined // during all elements traversal. I.e. we expect to start from the first comment and grab as many subsequent // comments as possible during the single iteration. processedComments.add(current); continue; } if (elementType == TokenType.WHITE_SPACE) { continue; } break; } if (end == null) return null; return new TextRange(startComment.getTextRange().getStartOffset(), end.getTextRange().getEndOffset()); }