public void findMatches(MatchResultSink sink) throws MalformedPatternException, UnsupportedPatternException {
    final MatchContext matchContext = getMatchContext();
    matchContext.clear();
    matchContext.setSink(new DuplicateFilteringResultSink(sink));
    final CompiledPattern compiledPattern = matchContext.getPattern();
    if (compiledPattern == null) {
      return;
    }

    if (isTesting) {
      // testing mode;
      final LocalSearchScope scope = (LocalSearchScope)matchContext.getOptions().getScope();
      assert scope != null;
      final PsiElement[] elements = scope.getScope();

      final PsiElement parent = elements[0].getParent();
      if (matchContext.getPattern().getStrategy().continueMatching(parent != null ? parent : elements[0])) {
        visitor.matchContext(SsrFilteringNodeIterator.create(elements));
      }
      else {
        for (PsiElement element : elements) {
          match(element);
        }
      }

      matchContext.getSink().matchingFinished();
    }
    else {
      if (scheduler == null) scheduler = new TaskScheduler();
      matchContext.getSink().setMatchingProcess(scheduler);
      scheduler.init();
      PsiManager.getInstance(project).runInBatchFilesMode(() -> {
        findMatches();

        if (scheduler.getTaskQueueEndAction() == null) {
          scheduler.setTaskQueueEndAction(() -> matchContext.getSink().matchingFinished());
        }
        scheduler.executeNext();
        return null;
      });
    }
  }
public void findMatches(MatchResultSink sink)