コード例 #1
0
  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);
              }
            });
  }
コード例 #2
0
 @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;
 }