SearchCostResult (@NotNull String name, @NotNull GlobalSearchScope scope, @Nullable PsiFile fileToIgnoreOccurrencesIn, @Nullable ProgressIndicator progress) { if (!ReadAction.compute(() -> scope.getUnloadedModulesBelongingToScope().isEmpty())) { return SearchCostResult.TOO_MANY_OCCURRENCES; } AtomicInteger filesCount = new AtomicInteger(); AtomicLong filesSizeToProcess = new AtomicLong(); Processor<VirtualFile> processor = new Processor<>() { private final VirtualFile virtualFileToIgnoreOccurrencesIn = fileToIgnoreOccurrencesIn == null ? null : fileToIgnoreOccurrencesIn.getVirtualFile(); private final int maxFilesToProcess = Registry.intValue("ide.unused.symbol.calculation.maxFilesToSearchUsagesIn", 10); private final int maxFilesSizeToProcess = Registry.intValue("ide.unused.symbol.calculation.maxFilesSizeToSearchUsagesIn", 524288); @Override public boolean process(VirtualFile file) { ProgressManager.checkCanceled(); if (Comparing.equal(file, virtualFileToIgnoreOccurrencesIn)) return true; int currentFilesCount = filesCount.incrementAndGet(); long accumulatedFileSizeToProcess = filesSizeToProcess.addAndGet(file.isDirectory() ? 0 : file.getLength()); return currentFilesCount < maxFilesToProcess && accumulatedFileSizeToProcess < maxFilesSizeToProcess; } }; TextIndexQuery query = TextIndexQuery.fromWord(name, true, null); boolean cheap = processFilesContainingAllKeys(myManager.getProject(), scope, processor, query); if (!cheap) { return SearchCostResult.TOO_MANY_OCCURRENCES; } return filesCount.get() == 0 ? SearchCostResult.ZERO_OCCURRENCES : SearchCostResult.FEW_OCCURRENCES; }