boolean (@NotNull Document document, @NotNull FindModel findModel, @NotNull PsiFile psiFile, int @NotNull [] offsetRef, @NotNull Processor<? super UsageInfo> consumer) { CharSequence text = document.getCharsSequence(); int textLength = document.getTextLength(); int offset = offsetRef[0]; Project project = psiFile.getProject(); FindManager findManager = FindManager.getInstance(project); int count = 0; while (offset < textLength) { FindResult result = findManager.findString(text, offset, findModel, psiFile.getVirtualFile()); if (!result.isStringFound()) break; int prevOffset = offset; offset = result.getEndOffset(); if (prevOffset == offset || offset == result.getStartOffset()) { // for regular expr the size of the match could be zero -> could be infinite loop in finding usages! ++offset; } SearchScope customScope = findModel.getCustomScope(); if (customScope instanceof LocalSearchScope) { if (!((LocalSearchScope)customScope).containsRange(psiFile, result)) continue; } UsageInfo info = new FindResultUsageInfo(findManager, psiFile, prevOffset, findModel, result); if (!consumer.process(info)) { return false; } count++; if (count >= USAGES_PER_READ_ACTION) { break; } } offsetRef[0] = offset; return true; }