boolean (@NotNull Project project, @NotNull PsiElement scope, @NotNull ASTNode leafNode, int offsetInLeaf, @NotNull StringSearcher searcher, boolean processInjectedPsi, @NotNull ProgressIndicator progress, @NotNull TextOccurenceProcessor processor) { final int patternLength = searcher.getPatternLength(); InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(project); ASTNode currentNode = leafNode; int currentOffset = offsetInLeaf; boolean contains = false; ASTNode prevNode = null; PsiElement run = null; while (run != scope) { ProgressManager.checkCanceled(); currentOffset += prevNode == null ? 0 : prevNode.getStartOffsetInParent(); prevNode = currentNode; run = currentNode.getPsi(); if (!contains) contains = run.getTextLength() - currentOffset >= patternLength; //do not compute if already contains if (contains) { if (processInjectedPsi) { Boolean result = processInjectedFile(run, searcher, currentOffset, progress, injectedLanguageManager, processor); if (result != null) { return result.booleanValue(); } } if (!processor.execute(run, currentOffset)) { return false; } } currentNode = currentNode.getTreeParent(); if (currentNode == null) break; } assert run == scope : "Malbuilt PSI; scopeNode: " + scope + "; containingFile: " + PsiTreeUtil.getParentOfType(scope, PsiFile.class, false) + "; currentNode: " + run + "; isAncestor: " + PsiTreeUtil.isAncestor(scope, run, false) + "; in same file: " + (PsiTreeUtil.getParentOfType(scope, PsiFile.class, false) == PsiTreeUtil.getParentOfType(run, PsiFile.class, false)); return true; }