boolean (final @NotNull PsiElement element, @NotNull Collection<String> stringToSearch, boolean equivalentReferencesOnly, @NotNull GlobalSearchScope searchScope, @NotNull Processor<? super UsageInfo> processor) { final TextRange elementTextRange = ReadAction.compute( () -> { if (!element.isValid()) { return null; } VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element); if (virtualFile == null || BinaryFileStubBuilders.INSTANCE.forFileType(virtualFile.getFileType()) != null) { return null; } return element.getTextRange(); }); UsageInfoFactory factory = (usage, startOffset, endOffset) -> { if (!element.isValid()) return equivalentReferencesOnly ? null : new UsageInfo(usage, startOffset, endOffset, true); if (elementTextRange != null && usage.getContainingFile() == element.getContainingFile() && elementTextRange.contains(startOffset) && elementTextRange.contains(endOffset)) { return null; } PsiReference someReference = usage.findReferenceAt(startOffset); if (someReference != null) { PsiElement refElement = someReference.getElement(); for (PsiReference ref : PsiReferenceService.getService() .getReferences(refElement, new PsiReferenceService.Hints(element, null))) { if (element.getManager().areElementsEquivalent(ref.resolve(), element)) { TextRange range = ref.getRangeInElement() .shiftRight(refElement.getTextRange().getStartOffset() - usage.getTextRange().getStartOffset()); return new UsageInfo(usage, range.getStartOffset(), range.getEndOffset(), true); } } } return equivalentReferencesOnly ? null : new UsageInfo(usage, startOffset, endOffset, true); }; for (String s : stringToSearch) { if (!processTextOccurrences(element, s, searchScope, factory, processor)) return false; } return true; }