boolean (PsiElement scope, String stringToSearch, boolean allowReferences, PairProcessor<? super PsiElement, ? super TextRange> processor) { String text = scope.getText(); for (int offset = 0; offset < text.length(); offset++) { offset = text.indexOf(stringToSearch, offset); if (offset < 0) break; final PsiReference referenceAt = scope.findReferenceAt(offset); if (!allowReferences && referenceAt != null && (referenceAt.resolve() != null || referenceAt instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)referenceAt).multiResolve(true).length > 0)) { continue; } if (offset > 0) { char c = text.charAt(offset - 1); if (Character.isJavaIdentifierPart(c) && c != '$') { if (offset < 2 || text.charAt(offset - 2) != '\\') continue; //escape sequence } } if (offset + stringToSearch.length() < text.length()) { char c = text.charAt(offset + stringToSearch.length()); if (Character.isJavaIdentifierPart(c) && c != '$') { continue; } } TextRange textRange = new TextRange(offset, offset + stringToSearch.length()); if (!processor.process(scope, textRange)) { return false; } offset += stringToSearch.length(); } return true; }