boolean (@Nullable PsiElement originalElement, @NotNull String qName, @NotNull PsiNonJavaFileReferenceProcessor processor, @NotNull GlobalSearchScope initialScope) { if (qName.isEmpty()) { throw new IllegalArgumentException("Cannot search for elements with empty text. Element: "+originalElement+ "; "+(originalElement == null ? null : originalElement.getClass())); } ProgressIndicator progress = getOrCreateIndicator(); int dotIndex = qName.lastIndexOf('.'); int dollarIndex = qName.lastIndexOf('$'); int maxIndex = Math.max(dotIndex, dollarIndex); String wordToSearch = maxIndex >= 0 ? qName.substring(maxIndex + 1) : qName; GlobalSearchScope theSearchScope = ReadAction.compute(() -> { if (originalElement != null && myManager.isInProject(originalElement) && initialScope.isSearchInLibraries()) { return initialScope.intersectWith(GlobalSearchScope.projectScope(myManager.getProject())); } return initialScope; }); PsiFile[] files = myDumbService.runReadActionInSmartMode(() -> CacheManager.getInstance(myManager.getProject()) .getFilesWithWord(wordToSearch, UsageSearchContext.IN_PLAIN_TEXT, theSearchScope, true)); StringSearcher searcher = new StringSearcher(qName, true, true, false); progress.pushState(); Ref<Boolean> stopped = Ref.create(Boolean.FALSE); try { progress.setText(IndexingBundle.message("psi.search.in.non.java.files.progress")); SearchScope useScope = originalElement == null ? null : myDumbService.runReadActionInSmartMode(() -> getUseScope(originalElement)); int patternLength = qName.length(); for (int i = 0; i < files.length; i++) { ProgressManager.checkCanceled(); PsiFile psiFile = files[i]; if (psiFile instanceof PsiBinaryFile) continue; CharSequence text = ReadAction.compute(() -> psiFile.getViewProvider().getContents()); LowLevelSearchUtil.processTexts(text, 0, text.length(), searcher, index -> { boolean isReferenceOK = myDumbService.runReadActionInSmartMode(() -> { PsiReference referenceAt = psiFile.findReferenceAt(index); return referenceAt == null || useScope == null || !PsiSearchScopeUtil.isInScope(useScope.intersectWith(initialScope), psiFile); }); if (isReferenceOK && !processor.process(psiFile, index, index + patternLength)) { stopped.set(Boolean.TRUE); return false; } return true; }); if (stopped.get()) break; progress.setFraction((double)(i + 1) / files.length); } } finally { progress.popState(); } return !stopped.get(); }