com.intellij.find.impl.FindManagerImpl Java Examples

The following examples show how to use com.intellij.find.impl.FindManagerImpl. 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: PsiElement2UsageTargetAdapter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void highlightUsages(@Nonnull PsiFile file, @Nonnull Editor editor, boolean clearHighlights) {
  PsiElement target = getElement();

  if (file instanceof PsiCompiledFile) file = ((PsiCompiledFile)file).getDecompiledPsiFile();

  Project project = target.getProject();
  final FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager();
  final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(target, true);

  // in case of injected file, use host file to highlight all occurrences of the target in each injected file
  PsiFile context = InjectedLanguageManager.getInstance(project).getTopLevelFile(file);
  SearchScope searchScope = new LocalSearchScope(context);
  Collection<PsiReference> refs = handler == null ? ReferencesSearch.search(target, searchScope, false).findAll() : handler.findReferencesToHighlight(target, searchScope);

  new HighlightUsagesHandler.DoHighlightRunnable(new ArrayList<>(refs), project, target, editor, context, clearHighlights).run();
}
 
Example #2
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 #3
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 #4
Source File: FindInProjectManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void startFindInProject(@Nonnull FindModel findModel) {
  if (findModel.getDirectoryName() != null && FindInProjectUtil.getDirectory(findModel) == null) {
    return;
  }

  UsageViewManager manager = UsageViewManager.getInstance(myProject);

  if (manager == null) return;
  final FindManager findManager = FindManager.getInstance(myProject);
  findManager.getFindInProjectModel().copyFrom(findModel);
  final FindModel findModelCopy = findModel.clone();
  final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(findModelCopy);
  final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, presentation);
  ConfigurableUsageTarget usageTarget = new FindInProjectUtil.StringUsageTarget(myProject, findModel);

  ((FindManagerImpl)FindManager.getInstance(myProject)).getFindUsagesManager().addToHistory(usageTarget);

  manager.searchAndShowUsages(new UsageTarget[]{usageTarget}, () -> processor -> {
    myIsFindInProgress = true;

    try {
      Processor<UsageInfo> consumer = info -> {
        Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info);
        usage.getPresentation().getIcon(); // cache icon
        return processor.process(usage);
      };
      FindInProjectUtil.findUsages(findModelCopy, myProject, consumer, processPresentation);
    }
    finally {
      myIsFindInProgress = false;
    }
  }, processPresentation, presentation, null);
}
 
Example #5
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void startFindUsages(@Nonnull PsiElement element, @Nonnull RelativePoint popupPosition, Editor editor, int maxUsages) {
  Project project = element.getProject();
  FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager();
  FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(element, false);
  if (handler == null) return;
  if (myShowSettingsDialogBefore) {
    showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
    return;
  }
  showElementUsages(editor, popupPosition, handler, maxUsages, handler.getFindUsagesOptions(DataManager.getInstance().getDataContext()));
}
 
Example #6
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private ActiveComponent createPinButton(@Nonnull final FindUsagesHandler handler,
                                        @Nonnull final UsageViewImpl usageView,
                                        @Nonnull final FindUsagesOptions options,
                                        @Nonnull final JBPopup[] popup,
                                        @Nonnull DefaultActionGroup pinGroup) {
  final AnAction pinAction = new AnAction("Open Find Usages Toolwindow", "Show all usages in a separate toolwindow", AllIcons.General.AutohideOff) {
    {
      AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_USAGES);
      setShortcutSet(action.getShortcutSet());
    }

    @Override
    public boolean startInTransaction() {
      return true;
    }

    @Override
    public void actionPerformed(@Nonnull AnActionEvent e) {
      hideHints();
      cancel(popup[0]);
      FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(usageView.getProject())).getFindUsagesManager();
      findUsagesManager.findUsages(handler.getPrimaryElements(), handler.getSecondaryElements(), handler, options,
                                   FindSettings.getInstance().isSkipResultsWithOneUsage());
    }
  };
  pinGroup.add(pinAction);
  final ActionToolbar pinToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.USAGE_VIEW_TOOLBAR, pinGroup, true);
  pinToolbar.setReservePlaceAutoPopupIcon(false);
  final JComponent pinToolBar = pinToolbar.getComponent();
  pinToolBar.setBorder(null);
  pinToolBar.setOpaque(false);

  return new ActiveComponent.Adapter() {
    @Override
    public JComponent getComponent() {
      return pinToolBar;
    }
  };
}
 
Example #7
Source File: PsiElement2UsageTargetAdapter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void showSettings() {
  PsiElement element = getElement();
  if (element != null) {
    FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(myPointer.getProject())).getFindUsagesManager();
    findUsagesManager.findUsages(element, null, null, true, null);
  }
}
 
Example #8
Source File: PsiElement2UsageTargetComposite.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void findUsages() {
  PsiElement element = getElement();
  if (element == null) return;
  FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(element.getProject())).getFindUsagesManager();
  FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(element, false);
  boolean skipResultsWithOneUsage = FindSettings.getInstance().isSkipResultsWithOneUsage();
  findUsagesManager.findUsages(myDescriptor.getPrimaryElements(), myDescriptor.getAdditionalElements(), handler, myOptions, skipResultsWithOneUsage);
}
 
Example #9
Source File: OttoProjectHandler.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
protected OttoProjectHandler(Project project, PsiManager psiManager) {
  super(project);
  this.findUsagesManager =
      ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
  this.psiManager = psiManager;
  project.putUserData(KEY, this);
  //System.out.println("OttoProjectHandler initialized");
}
 
Example #10
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 #11
Source File: PsiElement2UsageTargetAdapter.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void findUsages() {
  PsiElement element = getElement();
  if (element == null) return;
  ((FindManagerImpl)FindManager.getInstance(element.getProject())).getFindUsagesManager().startFindUsages(element, myOptions, null, null);
}
 
Example #12
Source File: TextOccurrencesUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isSearchTextOccurencesEnabled(@Nonnull PsiElement element) {
  final FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(element.getProject())).getFindUsagesManager();
  final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(element, true);
  return FindUsagesUtil.isSearchForTextOccurrencesAvailable(element, false, handler);
}