com.intellij.find.findUsages.FindUsagesManager Java Examples

The following examples show how to use com.intellij.find.findUsages.FindUsagesManager. 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: FindManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Inject
public FindManagerImpl(Project project, FindSettings findSettings, UsageViewManager anotherManager) {
  myProject = project;
  myBus = project.getMessageBus();
  findSettings.initModelBySetings(myFindInProjectModel);

  myFindInFileModel.setCaseSensitive(findSettings.isLocalCaseSensitive());
  myFindInFileModel.setWholeWordsOnly(findSettings.isLocalWholeWordsOnly());
  myFindInFileModel.setRegularExpressions(findSettings.isLocalRegularExpressions());

  myFindUsagesManager = new FindUsagesManager(myProject, anotherManager);
  myFindInProjectModel.setMultipleFiles(true);

  NotificationsConfigurationImpl.remove("FindInPath");
  Disposer.register(project, new Disposable() {
    @Override
    public void dispose() {
      if (myHelper != null) {
        Disposer.dispose(myHelper);
      }
    }
  });
}
 
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: 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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: FindManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void showSettingsAndFindUsages(@Nonnull NavigationItem[] targets) {
  FindUsagesManager.showSettingsAndFindUsages(targets);
}
 
Example #12
Source File: FindManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public FindUsagesManager getFindUsagesManager() {
  return myFindUsagesManager;
}
 
Example #13
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);
}
 
Example #14
Source File: OttoProjectHandler.java    From otto-intellij-plugin with Apache License 2.0 4 votes vote down vote up
private void performSearch(final SearchScope searchScope, final String subscribeClassName) {
  JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(myProject);
  PsiClass subscribePsiClass = javaPsiFacade.findClass(subscribeClassName,
      GlobalSearchScope.allScope(myProject));
  if (subscribePsiClass == null) {
    // the guava or otto library isn't available in this project so do nothing
    return;
  }

  FindUsagesHandler handler = findUsagesManager.getNewFindUsagesHandler(subscribePsiClass, false);
  if (handler != null) {
    UsageInfoToUsageConverter.TargetElementsDescriptor descriptor =
        new UsageInfoToUsageConverter.TargetElementsDescriptor(handler.getPrimaryElements(),
            handler.getSecondaryElements());

    final long startTime = System.currentTimeMillis();
    Processor<Usage> processor = new Processor<Usage>() {
      @Override public boolean process(Usage usage) {
        if (usage instanceof UsageInfo2UsageAdapter) {
          PsiElement element = ((UsageInfo2UsageAdapter) usage).getElement();
          if ((element = element.getContext()) instanceof PsiAnnotation) {
            if ((element = element.getContext()) instanceof PsiModifierList) {
              if ((element = element.getContext()) instanceof PsiMethod) {
                if (PsiConsultantImpl.hasAnnotation((PsiMethod) element, subscribeClassName)) {
                  maybeAddSubscriberMethod((PsiMethod) element);
                }
              }
            }
          }
        }
        return true;
      }
    };
    JavaClassFindUsagesOptions options = new JavaClassFindUsagesOptions(myProject);
    options.searchScope = searchScope;
    FindUsagesManager.startProcessUsages(handler, handler.getPrimaryElements(), handler.getSecondaryElements(), processor, options, new Runnable() {
      @Override public void run() {
        int eventClassCount = optimizeEventClassIndex();
        if (eventClassCount > 0) {
          scheduleRefreshOfEventFiles();
        } else {
          maybeScheduleAnotherSearch();
        }

        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug(String.format("Searched for @Subscribe in %s in %dms",
              searchScope, System.currentTimeMillis() - startTime));
        }
      }
    });
  }
}