com.intellij.find.findUsages.FindUsagesHandler Java Examples

The following examples show how to use com.intellij.find.findUsages.FindUsagesHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FindUsagesImpl171.java    From Android-Resource-Usage-Count with MIT License 6 votes vote down vote up
int findUsage(XmlTag element) {
    final FindUsagesHandler handler = FindUsagesImpl171.getFindUsagesHandler(element, element.getProject());
    if (handler != null) {
        final FindUsagesOptions findUsagesOptions = handler.getFindUsagesOptions();
        final PsiElement[] primaryElements = handler.getPrimaryElements();
        final PsiElement[] secondaryElements = handler.getSecondaryElements();
        Factory factory = new Factory() {
            public UsageSearcher create() {
                return FindUsagesImpl171.createUsageSearcher(primaryElements, secondaryElements, handler, findUsagesOptions, (PsiFile) null);
            }
        };
        UsageSearcher usageSearcher = (UsageSearcher)factory.create();
        final AtomicInteger mCount = new AtomicInteger(0);
        usageSearcher.generate(new Processor<Usage>() {
            @Override
            public boolean process(Usage usage) {
                if (ResourceUsageCountUtils.isUsefulUsageToCount(usage)) {
                    mCount.incrementAndGet();
                }
                return true;
            }
        });
        return mCount.get();
    }
    return 0;
}
 
Example #2
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition, final Editor editor, final int maxUsages,
    @NotNull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings,
      new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
              showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
            }
          });
          cancelAction.run();
        }
      }
  );
}
 
Example #3
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition,
    final Editor editor,
    final int maxUsages,
    @NotNull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
        }
      });
      cancelAction.run();
    }
  });
}
 
Example #4
Source File: HaxeFindUsagesHandlerFactory.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
public FindUsagesHandler createFindUsagesHandler(@NotNull final PsiElement element, final boolean forHighlightUsages) {
  if (canFindUsages(element)) {
    PsiElement target = HaxeFindUsagesUtil.getTargetElement(element);

    if (!forHighlightUsages) {
      if (target instanceof PsiReference) {
        PsiElement resolved = ((PsiReference)target).resolve();
        if (resolved instanceof HaxeMethod) {
          target = resolved;
        }
      }
      if (target instanceof HaxeMethod) {
        PsiMethod[] supers = ((HaxeMethod)target).findSuperMethods();
        if (supers.length != 0) {
          String chosen = askWhetherToSearchForOverridingMethods(target);
          if (CURRENT_CLASS.equals(chosen))    { return new HaxeFindUsagesHandler(target); }
          else if (BASE_CLASS.equals(chosen))  { return new HaxeFindUsagesHandler(supers[supers.length - 1]); }
          else /* ANCESTOR_CLASSES */     { return new HaxeFindUsagesHandler(target, supers); }
        }
      }
    }
    return new HaxeFindUsagesHandler(target != null ? target : element);
  }
  return FindUsagesHandler.NULL_HANDLER;
}
 
Example #5
Source File: FindUsagesImpl171.java    From Android-Resource-Usage-Count with MIT License 6 votes vote down vote up
private static FindUsagesHandler getFindUsagesHandler(PsiElement element, Project project) {
    FindUsagesHandlerFactory[] arrs = (FindUsagesHandlerFactory[]) Extensions.getExtensions(FindUsagesHandlerFactory.EP_NAME, project);
    FindUsagesHandler handler = null;
    int length = arrs.length;
    for (int i = 0; i < length; i++) {
        FindUsagesHandlerFactory arr = arrs[i];
        if (arr.canFindUsages(element)) {
            handler = arr.createFindUsagesHandler(element, false);
            if(handler == FindUsagesHandler.NULL_HANDLER) {
                return null;
            }

            if(handler != null) {
                return handler;
            }
        }
    }
    return null;
}
 
Example #6
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void searchEverywhere(@NotNull FindUsagesOptions options,
    @NotNull FindUsagesHandler handler,
    Editor editor,
    @NotNull RelativePoint popupPosition,
    int maxUsages) {
  FindUsagesOptions cloned = options.clone();
  cloned.searchScope = FindUsagesManager.getMaximalScope(handler);
  showElementUsages(handler, editor, popupPosition, maxUsages, cloned);
}
 
Example #7
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getSecondInvocationTitle(@NotNull FindUsagesOptions options, @NotNull FindUsagesHandler handler) {
  if (getShowUsagesShortcut() != null) {
    GlobalSearchScope maximalScope = FindUsagesManager.getMaximalScope(handler);
    if (!notNullizeScope(options, handler.getProject()).equals(maximalScope)) {
      return "Press " + KeymapUtil.getShortcutText(getShowUsagesShortcut()) + " again to search in " + maximalScope.getDisplayName();
    }
  }
  return null;
}
 
Example #8
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private static String suggestSecondInvocation(@NotNull FindUsagesOptions options, @NotNull FindUsagesHandler handler, @NotNull String text) {
  final String title = getSecondInvocationTitle(options, handler);

  if (title != null) {
    text += "<br><small>Press " + title + "</small>";
  }
  return "<html><body>" + text + "</body></html>";
}
 
Example #9
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void showDialogAndFindUsages(@NotNull FindUsagesHandler handler,
    @NotNull RelativePoint popupPosition,
    Editor editor,
    int maxUsages) {
  AbstractFindUsagesDialog dialog = handler.getFindUsagesDialog(false, false, false);
  dialog.show();
  if (dialog.isOK()) {
    dialog.calcFindUsagesOptions();
    showElementUsages(handler, editor, popupPosition, maxUsages, getDefaultOptions(handler));
  }
}
 
Example #10
Source File: LithoFindUsagesHandlerFactory.java    From litho with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public FindUsagesHandler createFindUsagesHandler(PsiElement element, boolean forHighlightUsages) {
  if (GeneratedClassFindUsagesHandler.canFindUsages(element)) {
    return new GeneratedClassFindUsagesHandler(element, findGeneratedClass);
  }
  if (SpecMethodFindUsagesHandler.canFindUsages(element)) {
    return new SpecMethodFindUsagesHandler(element, findGeneratedClass);
  }
  return null;
}
 
Example #11
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private JComponent createHintComponent(@NotNull String text,
    @NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition,
    final Editor editor,
    @NotNull final Runnable cancelAction,
    final int maxUsages,
    @NotNull final FindUsagesOptions options) {
  JComponent label = HintUtil.createInformationLabel(suggestSecondInvocation(options, handler, text + "&nbsp;"));
  InplaceButton button = createSettingsButton(handler, popupPosition, editor, maxUsages, cancelAction);

  JPanel panel = new JPanel(new BorderLayout()) {
    @Override
    public void addNotify() {
      mySearchEverywhereRunnable = new Runnable() {
        @Override
        public void run() {
          searchEverywhere(options, handler, editor, popupPosition, maxUsages);
        }
      };
      super.addNotify();
    }

    @Override
    public void removeNotify() {
      mySearchEverywhereRunnable = null;
      super.removeNotify();
    }
  };
  button.setBackground(label.getBackground());
  panel.setBackground(label.getBackground());
  label.setOpaque(false);
  label.setBorder(null);
  panel.setBorder(HintUtil.createHintBorder());
  panel.add(label, BorderLayout.CENTER);
  panel.add(button, BorderLayout.EAST);
  return panel;
}
 
Example #12
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void showHint(@NotNull String text,
    @Nullable final Editor editor,
    @NotNull final RelativePoint popupPosition,
    @NotNull FindUsagesHandler handler,
    int maxUsages,
    @NotNull FindUsagesOptions options) {
  JComponent label = createHintComponent(text, handler, popupPosition, editor, HIDE_HINTS_ACTION, maxUsages, options);
  if (editor == null || editor.isDisposed()) {
    HintManager.getInstance().showHint(label, popupPosition, HintManager.HIDE_BY_ANY_KEY |
        HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0);
  }
  else {
    HintManager.getInstance().showInformationHint(editor, label);
  }
}
 
Example #13
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private static FindUsagesOptions getDefaultOptions(@NotNull FindUsagesHandler handler) {
  FindUsagesOptions options = handler.getFindUsagesOptions(DataManager.getInstance().getDataContext());
  // by default, scope in FindUsagesOptions is copied from the FindSettings, but we need a default one
  options.searchScope = FindUsagesManager.getMaximalScope(handler);
  return options;
}
 
Example #14
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
void startFindUsages(@NotNull PsiElement element, @NotNull RelativePoint popupPosition, Editor editor, int maxUsages) {
  Project project = element.getProject();
  FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager();
  FindUsagesHandler handler = findUsagesManager.getNewFindUsagesHandler(element, false);
  if (handler == null) return;
  if (showSettingsDialogBefore) {
    showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
    return;
  }
  showElementUsages(handler, editor, popupPosition, maxUsages, getDefaultOptions(handler));
}
 
Example #15
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void navigateAndHint(@NotNull Usage usage,
    @Nullable final String hint,
    @NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition,
    final int maxUsages,
    @NotNull final FindUsagesOptions options) {
  usage.navigate(true);
  if (hint == null) return;
  final Editor newEditor = getEditorFor(usage);
  if (newEditor == null) return;
  final Project project = handler.getProject();
  //opening editor is performing in invokeLater
  IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      newEditor.getScrollingModel().runActionOnScrollingFinished(new Runnable() {
        @Override
        public void run() {
          // after new editor created, some editor resizing events are still bubbling. To prevent hiding hint, invokeLater this
          IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(new Runnable() {
            @Override
            public void run() {
              if (newEditor.getComponent().isShowing()) {
                showHint(hint, newEditor, popupPosition, handler, maxUsages, options);
              }
            }
          });
        }
      });
    }
  });
}
 
Example #16
Source File: IdentifierHighlighterPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Couple<Collection<TextRange>> getUsages(@Nonnull PsiElement target, PsiElement psiElement, boolean withDeclarations, boolean detectAccess) {
  List<TextRange> readRanges = new ArrayList<>();
  List<TextRange> writeRanges = new ArrayList<>();
  final ReadWriteAccessDetector detector = detectAccess ? ReadWriteAccessDetector.findDetector(target) : null;
  final FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(target.getProject())).getFindUsagesManager();
  final FindUsagesHandler findUsagesHandler = findUsagesManager.getFindUsagesHandler(target, true);
  final LocalSearchScope scope = new LocalSearchScope(psiElement);
  Collection<PsiReference> refs = findUsagesHandler != null
                                  ? findUsagesHandler.findReferencesToHighlight(target, scope)
                                  : ReferencesSearch.search(target, scope).findAll();
  for (PsiReference psiReference : refs) {
    if (psiReference == null) {
      LOG.error("Null reference returned, findUsagesHandler=" + findUsagesHandler + "; target=" + target + " of " + target.getClass());
      continue;
    }
    List<TextRange> destination;
    if (detector == null || detector.getReferenceAccess(target, psiReference) == ReadWriteAccessDetector.Access.Read) {
      destination = readRanges;
    }
    else {
      destination = writeRanges;
    }
    HighlightUsagesHandler.collectRangesToHighlight(psiReference, destination);
  }

  if (withDeclarations) {
    final TextRange declRange = HighlightUsagesHandler.getNameIdentifierRange(psiElement.getContainingFile(), target);
    if (declRange != null) {
      if (detector != null && detector.isDeclarationWriteAccess(target)) {
        writeRanges.add(declRange);
      }
      else {
        readRanges.add(declRange);
      }
    }
  }

  return Couple.<Collection<TextRange>>of(readRanges, writeRanges);
}
 
Example #17
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void navigateAndHint(@NotNull Usage usage, @Nullable final String hint,
    @NotNull final FindUsagesHandler handler, @NotNull final RelativePoint popupPosition,
    final int maxUsages, @NotNull final FindUsagesOptions options) {
  usage.navigate(true);
  if (hint == null) return;
  final Editor newEditor = getEditorFor(usage);
  if (newEditor == null) return;
  final Project project = handler.getProject();
  //opening editor is performing in invokeLater
  IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      newEditor.getScrollingModel().runActionOnScrollingFinished(new Runnable() {
        @Override
        public void run() {
          // after new editor created, some editor resizing events are still bubbling. To prevent hiding hint, invokeLater this
          IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(new Runnable() {
            @Override
            public void run() {
              if (newEditor.getComponent().isShowing()) {
                showHint(hint, newEditor, popupPosition, handler, maxUsages, options);
              }
            }
          });
        }
      });
    }
  });
}
 
Example #18
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void searchEverywhere(@NotNull FindUsagesOptions options,
    @NotNull FindUsagesHandler handler, Editor editor, @NotNull RelativePoint popupPosition,
    int maxUsages) {
  FindUsagesOptions cloned = options.clone();
  cloned.searchScope = FindUsagesManager.getMaximalScope(handler);
  showElementUsages(handler, editor, popupPosition, maxUsages, cloned);
}
 
Example #19
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getSecondInvocationTitle(@NotNull FindUsagesOptions options,
    @NotNull FindUsagesHandler handler) {
  if (getShowUsagesShortcut() != null) {
    GlobalSearchScope maximalScope = FindUsagesManager.getMaximalScope(handler);
    if (!notNullizeScope(options, handler.getProject()).equals(maximalScope)) {
      return "Press "
          + KeymapUtil.getShortcutText(getShowUsagesShortcut())
          + " again to search in "
          + maximalScope.getDisplayName();
    }
  }
  return null;
}
 
Example #20
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private static String suggestSecondInvocation(@NotNull FindUsagesOptions options,
    @NotNull FindUsagesHandler handler, @NotNull String text) {
  final String title = getSecondInvocationTitle(options, handler);

  if (title != null) {
    text += "<br><small>Press " + title + "</small>";
  }
  return "<html><body>" + text + "</body></html>";
}
 
Example #21
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void showDialogAndFindUsages(@NotNull FindUsagesHandler handler,
    @NotNull RelativePoint popupPosition, Editor editor, int maxUsages) {
  AbstractFindUsagesDialog dialog = handler.getFindUsagesDialog(false, false, false);
  dialog.show();
  if (dialog.isOK()) {
    dialog.calcFindUsagesOptions();
    showElementUsages(handler, editor, popupPosition, maxUsages, getDefaultOptions(handler));
  }
}
 
Example #22
Source File: SqliteMagicFieldFindUsagesHandlerFactory.java    From sqlitemagic with Apache License 2.0 5 votes vote down vote up
@Override
  public FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, boolean forHighlightUsages) {
    return new JavaFindUsagesHandler(element, this) {
      @NotNull
      @Override
      public PsiElement[] getSecondaryElements() {
//                final PsiField psiField = (PsiField) getPsiElement();
//                final PsiClass containingClass = psiField.getContainingClass();
//                if (containingClass != null) {
//                    final AccessorsInfo accessorsInfo = AccessorsInfo.build(psiField);
//                    final String psiFieldName = psiField.getName();
//
//                    final String fieldName = accessorsInfo.removePrefix(psiFieldName);
//                    if (!fieldName.equals(psiFieldName)) {
//                        final boolean isBoolean = PsiType.BOOLEAN.equals(psiField.getType());
//
//                        final String getterName = LombokUtils.toGetterName(accessorsInfo, psiFieldName, isBoolean);
//                        final String setterName = LombokUtils.toSetterName(accessorsInfo, psiFieldName, isBoolean);
//
//                        final PsiMethod[] psiGetterMethods = containingClass.findMethodsByName(getterName, false);
//                        final PsiMethod[] psiSetterMethods = containingClass.findMethodsByName(setterName, false);
//
//                        final Set<PsiElement> elements = new THashSet<PsiElement>(psiGetterMethods.length + psiSetterMethods.length);
//                        for (PsiMethod accessor : psiGetterMethods) {
//                            ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(accessor, ACTION_STRING));
//                        }
//                        for (PsiMethod accessor : psiSetterMethods) {
//                            ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(accessor, ACTION_STRING));
//                        }
//                        return PsiUtilCore.toPsiElementArray(elements);
//                    }
//                }
        return super.getSecondaryElements();
      }
    };
  }
 
Example #23
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private JComponent createHintComponent(@NotNull String text,
    @NotNull final FindUsagesHandler handler, @NotNull final RelativePoint popupPosition,
    final Editor editor, @NotNull final Runnable cancelAction, final int maxUsages,
    @NotNull final FindUsagesOptions options) {
  JComponent label =
      HintUtil.createInformationLabel(suggestSecondInvocation(options, handler, text + "&nbsp;"));
  InplaceButton button =
      createSettingsButton(handler, popupPosition, editor, maxUsages, cancelAction);

  JPanel panel = new JPanel(new BorderLayout()) {
    @Override
    public void addNotify() {
      mySearchEverywhereRunnable = new Runnable() {
        @Override
        public void run() {
          searchEverywhere(options, handler, editor, popupPosition, maxUsages);
        }
      };
      super.addNotify();
    }

    @Override
    public void removeNotify() {
      mySearchEverywhereRunnable = null;
      super.removeNotify();
    }
  };
  button.setBackground(label.getBackground());
  panel.setBackground(label.getBackground());
  label.setOpaque(false);
  label.setBorder(null);
  panel.setBorder(HintUtil.createHintBorder());
  panel.add(label, BorderLayout.CENTER);
  panel.add(button, BorderLayout.EAST);
  return panel;
}
 
Example #24
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void showHint(@NotNull String text, @Nullable final Editor editor,
    @NotNull final RelativePoint popupPosition, @NotNull FindUsagesHandler handler, int maxUsages,
    @NotNull FindUsagesOptions options) {
  JComponent label =
      createHintComponent(text, handler, popupPosition, editor, HIDE_HINTS_ACTION, maxUsages,
          options);

  HintManager.getInstance().showHint(label, popupPosition, HintManager.HIDE_BY_ANY_KEY |
      HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0);
}
 
Example #25
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private static FindUsagesOptions getDefaultOptions(@NotNull FindUsagesHandler handler) {
  FindUsagesOptions options =
      handler.getFindUsagesOptions(DataManager.getInstance().getDataContext());
  // by default, scope in FindUsagesOptions is copied from the FindSettings, but we need a default one
  options.searchScope = FindUsagesManager.getMaximalScope(handler);
  return options;
}
 
Example #26
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
public void startFindUsages(@NotNull PsiElement element, @NotNull RelativePoint popupPosition,
    Editor editor, int maxUsages) {
  Project project = element.getProject();
  FindUsagesManager findUsagesManager =
      ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
  FindUsagesHandler handler = findUsagesManager.getNewFindUsagesHandler(element, false);
  if (handler == null) return;
  if (showSettingsDialogBefore) {
    showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
    return;
  }
  showElementUsages(handler, editor, popupPosition, maxUsages, getDefaultOptions(handler));
}
 
Example #27
Source File: XQueryFindUsagesHandlerFactory.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@Override
public FindUsagesHandler createFindUsagesHandler(@NotNull final PsiElement element,
                                                 final boolean forHighlightUsages) {
    if (canFindUsages(element)) {
        return new XQueryFindUsagesHandler(element);
    }
    return null;
}
 
Example #28
Source File: JSGraphQLEndpointFindUsagesHandlerFactory.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, boolean forHighlightUsages) {

    if (canFindUsages(element)) {
        return new FindUsagesHandler(element) {};
    }

    return null;

}
 
Example #29
Source File: FindUsagesImpl171.java    From Android-Resource-Usage-Count with MIT License 4 votes vote down vote up
@NotNull
private static UsageSearcher createUsageSearcher(@NotNull final PsiElement[] primaryElements, @NotNull final PsiElement[] secondaryElements, @NotNull final FindUsagesHandler handler, @NotNull FindUsagesOptions options, final PsiFile scopeFile) {
    final FindUsagesOptions optionsClone = options.clone();
    return new UsageSearcher() {
        public void generate(@NotNull final Processor<Usage> processor) {
            Project project = (Project) ApplicationManager.getApplication().runReadAction(new Computable() {
                public Project compute() {
                    return scopeFile != null?scopeFile.getProject():primaryElements[0].getProject();
                }
            });
            dropResolveCacheRegularly(ProgressManager.getInstance().getProgressIndicator(), project);
            if(scopeFile != null) {
                optionsClone.searchScope = new LocalSearchScope(scopeFile);
            }

            final CommonProcessors.UniqueProcessor usageInfoProcessor = new CommonProcessors.UniqueProcessor(new Processor<UsageInfo>() {
                @Override
                public boolean process(final UsageInfo usageInfo) {
                    Usage usage = (Usage)ApplicationManager.getApplication().runReadAction(new Computable() {
                        public Usage compute() {
                            return UsageInfoToUsageConverter.convert(primaryElements, usageInfo);
                        }
                    });
                    return processor.process(usage);
                }
            });
            Iterable elements = ContainerUtil.concat(new PsiElement[][]{primaryElements, secondaryElements});
            optionsClone.fastTrack = new SearchRequestCollector(new SearchSession());
            if(optionsClone.searchScope instanceof GlobalSearchScope) {
                optionsClone.searchScope = optionsClone.searchScope.union(GlobalSearchScope.projectScope(project));
            }

            try {
                Iterator i$ = elements.iterator();

                while(i$.hasNext()) {
                    final PsiElement element = (PsiElement)i$.next();
                    ApplicationManager.getApplication().runReadAction(new Runnable() {
                        public void run() {

                        }
                    });
                    handler.processElementUsages(element, usageInfoProcessor, optionsClone);
                    CustomUsageSearcher[] arr$ = (CustomUsageSearcher[])Extensions.getExtensions(CustomUsageSearcher.EP_NAME);
                    int len$ = arr$.length;

                    for(int i$1 = 0; i$1 < len$; ++i$1) {
                        CustomUsageSearcher searcher = arr$[i$1];

                        try {
                            searcher.processElementUsages(element, processor, optionsClone);
                        } catch (IndexNotReadyException var17) {
                            DumbService.getInstance(element.getProject()).showDumbModeNotification("Find usages is not available during indexing");
                        } catch (ProcessCanceledException var18) {
                            throw var18;
                        } catch (Exception var19) {

                        }
                    }
                }

                PsiSearchHelper.SERVICE.getInstance(project).processRequests(optionsClone.fastTrack, new Processor<PsiReference>() {
                    public boolean process(final PsiReference ref) {
                        UsageInfo info = (UsageInfo)ApplicationManager.getApplication().runReadAction(new Computable() {
                            public UsageInfo compute() {
                                return !ref.getElement().isValid()?null:new UsageInfo(ref);
                            }
                        });
                        return info == null || usageInfoProcessor.process(info);
                    }
                });
            } finally {
                optionsClone.fastTrack = null;
            }

        }
    };
}
 
Example #30
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 4 votes vote down vote up
private void appendMoreUsages(Editor editor, @NotNull RelativePoint popupPosition, @NotNull FindUsagesHandler handler, int maxUsages) {
  showElementUsages(handler, editor, popupPosition, maxUsages+USAGES_PAGE_SIZE, getDefaultOptions(handler));
}