List<TextRange> (@NotNull PsiFile file) { final List<String> excludedWords = new SmartList<>(); final StringBuilder fileText = new StringBuilder(); final TodoIndexPatternProvider todoIndexPatternProvider = TodoIndexPatternProvider.getInstance(); final Collection<IndexPatternOccurrence> occurrences = IndexPatternSearch.search(file, todoIndexPatternProvider, TodoConfiguration.getInstance().isMultiLine()).findAll(); return occurrences.stream() .map(occurrence -> { TextRange mainRange = occurrence.getTextRange(); List<TextRange> additionalRanges = occurrence.getAdditionalTextRanges(); return additionalRanges.isEmpty() ? mainRange : new TextRange(mainRange.getStartOffset(), additionalRanges.get(additionalRanges.size() - 1).getEndOffset()); }) .filter(range -> { if (!onlyWarnOnEmpty) return true; if (excludedWords.isEmpty()) { for (IndexPattern pattern : todoIndexPatternProvider.getIndexPatterns()) { excludedWords.addAll(pattern.getWordsToFindFirst()); } } if (fileText.isEmpty()) fileText.append(file.getText()); final CharSequence text = range.subSequence(fileText); outer: for (String word : StringUtil.getWordsIn(text.toString())) { for (String excludedWord : excludedWords) { if (word.equalsIgnoreCase(excludedWord)) { continue outer; } } return false; } return true; }) .sorted(Comparator.comparingInt(TextRange::getStartOffset)) .collect(Collectors.toList()); }