private static void optimizeScope(MatchOptions options, boolean checkForErrors, CompileContext context, CompiledPattern result)
    throws NoMatchFoundException {

    final OptimizingSearchHelper searchHelper = context.getSearchHelper();
    if (searchHelper.doOptimizing() && searchHelper.isScannedSomething()) {
      final Set<VirtualFile> filesToScan = searchHelper.getFilesSetToScan();

      final GlobalSearchScope scope = (GlobalSearchScope)options.getScope();
      assert scope != null;
      if (checkForErrors && filesToScan.isEmpty()) {
        throw new NoMatchFoundException(SSRBundle.message("ssr.will.not.find.anything", scope.getDisplayName()));
      }
      result.setScope(scope.isSearchInLibraries()
                      ? GlobalSearchScope.filesWithLibrariesScope(context.getProject(), filesToScan)
                      : GlobalSearchScope.filesWithoutLibrariesScope(context.getProject(), filesToScan));
    }
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      ourLastSearchPlan = ((TestModeOptimizingSearchHelper)searchHelper).getSearchPlan();
    }
  }
private static void optimizeScope(MatchOptions options, boolean checkForErrors, CompileContext context, CompiledPattern result)