private void doReRun() {
    final AtomicInteger tooManyUsages = new AtomicInteger();
    final CountDownLatch waitWhileUserClick = new CountDownLatch(1);
    final AtomicInteger usageCountWithoutDefinition = new AtomicInteger(0);
    ProgressManager.getInstance()
        .run(
            new Task.Backgroundable(
                myProject, UsageViewManagerImpl.getProgressTitle(myPresentation)) {
              @Override
              public void run(@NotNull final ProgressIndicator indicator) {
                setSearchInProgress(true);
                final com.intellij.usages.UsageViewManager usageViewManager =
                    com.intellij.usages.UsageViewManager.getInstance(myProject);
                usageViewManager.setCurrentSearchCancelled(false);

                myChangesDetected = false;
                UsageSearcher usageSearcher = myUsageSearcherFactory.create();
                usageSearcher.generate(
                    new Processor<Usage>() {
                      @Override
                      public boolean process(final Usage usage) {
                        if (usageViewManager.searchHasBeenCancelled()) return false;
                        if (tooManyUsages.get() == 1) {
                          try {
                            waitWhileUserClick.await(1, TimeUnit.SECONDS);
                          } catch (InterruptedException ignored) {
                          }
                        }

                        boolean incrementCounter =
                            !com.intellij.usages.UsageViewManager.isSelfUsage(usage, myTargets);

                        if (incrementCounter) {
                          final int usageCount = usageCountWithoutDefinition.incrementAndGet();
                          if (usageCount > UsageLimitUtil.USAGES_LIMIT
                              && tooManyUsages.get() == 0
                              && tooManyUsages.compareAndSet(0, 1)) {
                            ((UsageViewManagerImpl) usageViewManager)
                                .showTooManyUsagesWarning(
                                    indicator,
                                    waitWhileUserClick,
                                    usageCountWithoutDefinition.get());
                          }
                          appendUsageLater(usage);
                        }
                        ProgressIndicator indicator =
                            ProgressManager.getInstance().getProgressIndicator();
                        return indicator == null || !indicator.isCanceled();
                      }
                    });
                drainQueuedUsageNodes();
                setSearchInProgress(false);
              }
            });
  }
 @NotNull
 private static List<UsageNode> collectData(
     @NotNull List<Usage> usages,
     @NotNull Collection<UsageNode> visibleNodes,
     @NotNull UsageViewImpl usageView,
     @NotNull UsageViewPresentation presentation) {
   @NotNull List<UsageNode> data = new ArrayList<UsageNode>();
   int filtered = filtered(usages, usageView);
   if (filtered != 0) {
     data.add(createStringNode(UsageViewBundle.message("usages.were.filtered.out", filtered)));
   }
   data.addAll(visibleNodes);
   if (data.isEmpty()) {
     String progressText = UsageViewManagerImpl.getProgressTitle(presentation);
     data.add(createStringNode(progressText));
   }
   Collections.sort(data, USAGE_NODE_COMPARATOR);
   return data;
 }
  private void searchInFiles(
      @NotNull Collection<PsiFile> psiFiles,
      @NotNull FindUsagesProcessPresentation processPresentation,
      @NotNull final Processor<UsageInfo> consumer) {
    int i = 0;
    long totalFilesSize = 0;
    int count = 0;

    for (final PsiFile psiFile : psiFiles) {
      final VirtualFile virtualFile = psiFile.getVirtualFile();
      final int index = i++;
      if (virtualFile == null) continue;

      long fileLength = UsageViewManagerImpl.getFileLength(virtualFile);
      if (fileLength == -1) continue; // Binary or invalid

      final boolean skipProjectFile =
          ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)
              && !myFindModel.isSearchInProjectFiles();
      if (skipProjectFile && !Registry.is("find.search.in.project.files")) continue;

      if (fileLength > SINGLE_FILE_SIZE_LIMIT) {
        myLargeFiles.add(psiFile);
        continue;
      }

      myProgress.checkCanceled();
      myProgress.setFraction((double) index / psiFiles.size());
      String text =
          FindBundle.message(
              "find.searching.for.string.in.file.progress",
              myFindModel.getStringToFind(),
              virtualFile.getPresentableUrl());
      myProgress.setText(text);
      myProgress.setText2(
          FindBundle.message("find.searching.for.string.in.file.occurrences.progress", count));

      int countInFile =
          FindInProjectUtil.processUsagesInFile(
              psiFile,
              myFindModel,
              new Processor<UsageInfo>() {
                @Override
                public boolean process(UsageInfo info) {
                  return skipProjectFile || consumer.process(info);
                }
              });

      if (countInFile > 0 && skipProjectFile) {
        processPresentation.projectFileUsagesFound(
            new Runnable() {
              @Override
              public void run() {
                FindModel model = myFindModel.clone();
                model.setSearchInProjectFiles(true);
                FindInProjectManager.getInstance(myProject).startFindInProject(model);
              }
            });
        continue;
      }

      count += countInFile;
      if (countInFile > 0) {
        totalFilesSize += fileLength;
        if (totalFilesSize > FILES_SIZE_LIMIT && !myWarningShown) {
          myWarningShown = true;
          String message =
              FindBundle.message(
                  "find.excessive.total.size.prompt",
                  UsageViewManagerImpl.presentableSize(totalFilesSize),
                  ApplicationNamesInfo.getInstance().getProductName());
          UsageLimitUtil.showAndCancelIfAborted(
              myProject, message, processPresentation.getUsageViewPresentation());
        }
      }
    }
  }