List<CommentRange> (final Lexer lexer, final CharSequence chars, final TextRange range, final TokenSet commentTokens, final IndexPatternBuilder builderForFile, final boolean multiLine) { List<CommentRange> commentRanges = new ArrayList<>(); int lastEndOffset = -1; for (lexer.start(chars); ; lexer.advance()) { IElementType tokenType = lexer.getTokenType(); if (tokenType == null) break; if (range != null) { if (lexer.getTokenEnd() <= range.getStartOffset()) continue; if (lexer.getTokenStart() >= range.getEndOffset() && (!multiLine || lastEndOffset < 0 || !containsOneLineBreak(chars, lastEndOffset, lexer.getTokenStart()))) break; } boolean isComment = commentTokens.contains(tokenType) || CacheUtil.isInComments(tokenType); if (isComment) { final int startDelta = builderForFile != null ? builderForFile.getCommentStartDelta(lexer.getTokenType(), lexer.getTokenSequence()) : 0; final int endDelta = builderForFile != null ? builderForFile.getCommentEndDelta(lexer.getTokenType()) : 0; int start = lexer.getTokenStart() + startDelta; int end = lexer.getTokenEnd() - endDelta; if (start < end && end <= chars.length()) { commentRanges.add(new CommentRange(start, end, startDelta, endDelta, builderForFile == null ? "" : builderForFile.getCharsAllowedInContinuationPrefix(tokenType))); } lastEndOffset = end; } } return commentRanges; }