boolean (@NotNull PsiFile psiFile, @NotNull VirtualFile virtualFile, @NotNull FindModel findModel, @NotNull Processor<? super UsageInfo> consumer) { if (findModel.getStringToFind().isEmpty()) { return ReadAction.compute(() -> consumer.process(new UsageInfo(psiFile))); } if (virtualFile.getFileType().isBinary()) return true; // do not decompile .class files Document document = ReadAction.compute(() -> virtualFile.isValid() ? FileDocumentManager.getInstance().getDocument(virtualFile) : null); if (document == null) return true; ProgressIndicator current = ProgressManager.getInstance().getProgressIndicator(); if (current == null) throw new IllegalStateException("must find usages under progress"); ProgressIndicator indicator = ProgressWrapper.unwrapAll(current); TooManyUsagesStatus tooManyUsagesStatus = TooManyUsagesStatus.getFrom(indicator); int before; int[] offsetRef = {0}; do { tooManyUsagesStatus.pauseProcessingIfTooManyUsages(); // wait for user out of read action before = offsetRef[0]; boolean success = ReadAction.compute(() -> !psiFile.isValid() || processSomeOccurrencesInFile(document, findModel, psiFile, offsetRef, consumer)); if (!success) { return false; } } while (offsetRef[0] != before); return true; }