Search in sources :

Example 11 with FindUsagesHandler

use of com.intellij.find.findUsages.FindUsagesHandler in project intellij-community by JetBrains.

the class PyRefactoringUtil method findUsages.

@NotNull
public static List<UsageInfo> findUsages(@NotNull PsiNamedElement element, boolean forHighlightUsages) {
    final List<UsageInfo> usages = new ArrayList<>();
    final FindUsagesHandler handler = new PyFindUsagesHandlerFactory().createFindUsagesHandler(element, forHighlightUsages);
    assert handler != null;
    final List<PsiElement> elementsToProcess = new ArrayList<>();
    Collections.addAll(elementsToProcess, handler.getPrimaryElements());
    Collections.addAll(elementsToProcess, handler.getSecondaryElements());
    for (PsiElement e : elementsToProcess) {
        handler.processElementUsages(e, usageInfo -> {
            if (!usageInfo.isNonCodeUsage) {
                usages.add(usageInfo);
            }
            return true;
        }, FindUsagesHandler.createFindUsagesOptions(element.getProject(), null));
    }
    return usages;
}
Also used : FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) PyFindUsagesHandlerFactory(com.jetbrains.python.findUsages.PyFindUsagesHandlerFactory) UsageInfo(com.intellij.usageView.UsageInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with FindUsagesHandler

use of com.intellij.find.findUsages.FindUsagesHandler in project intellij-community by JetBrains.

the class PyStaticCallHierarchyUtil method findUsages.

private static Collection<UsageInfo> findUsages(@NotNull final PsiElement element) {
    final FindUsagesHandler handler = createFindUsageHandler(element);
    if (handler == null) {
        return Lists.newArrayList();
    }
    final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<>();
    final PsiElement[] psiElements = ArrayUtil.mergeArrays(handler.getPrimaryElements(), handler.getSecondaryElements());
    final FindUsagesOptions options = handler.getFindUsagesOptions(null);
    for (PsiElement psiElement : psiElements) {
        handler.processElementUsages(psiElement, processor, options);
    }
    return processor.getResults();
}
Also used : FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) PyFunctionFindUsagesHandler(com.jetbrains.python.findUsages.PyFunctionFindUsagesHandler) PyClassFindUsagesHandler(com.jetbrains.python.findUsages.PyClassFindUsagesHandler) FindUsagesOptions(com.intellij.find.findUsages.FindUsagesOptions) CommonProcessors(com.intellij.util.CommonProcessors) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement)

Aggregations

FindUsagesHandler (com.intellij.find.findUsages.FindUsagesHandler)12 FindUsagesManager (com.intellij.find.findUsages.FindUsagesManager)7 FindManagerImpl (com.intellij.find.impl.FindManagerImpl)7 UsageInfo (com.intellij.usageView.UsageInfo)7 FindUsagesOptions (com.intellij.find.findUsages.FindUsagesOptions)5 PsiElement (com.intellij.psi.PsiElement)5 NotNull (org.jetbrains.annotations.NotNull)5 CommonProcessors (com.intellij.util.CommonProcessors)4 Project (com.intellij.openapi.project.Project)2 PsiFile (com.intellij.psi.PsiFile)2 DartServerFindUsagesHandler (com.jetbrains.lang.dart.ide.findUsages.DartServerFindUsagesHandler)2 ResourceItem (com.android.ide.common.res2.ResourceItem)1 ResourceType (com.android.resources.ResourceType)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1 HtmlBuilder (com.android.utils.HtmlBuilder)1 ReadWriteAccessDetector (com.intellij.codeInsight.highlighting.ReadWriteAccessDetector)1 JavaMethodFindUsagesOptions (com.intellij.find.findUsages.JavaMethodFindUsagesOptions)1 PsiElement2UsageTargetAdapter (com.intellij.find.findUsages.PsiElement2UsageTargetAdapter)1 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1 Document (com.intellij.openapi.editor.Document)1