Search in sources :

Example 6 with FindManagerImpl

use of com.intellij.find.impl.FindManagerImpl in project smali by JesusFreke.

the class FindUsagesTest method findUsages.

private Collection<UsageInfo> findUsages(@NotNull PsiElement element) {
    FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(getProject())).getFindUsagesManager();
    FindUsagesHandler findUsagesHandler = findUsagesManager.getFindUsagesHandler(element, false);
    Assert.assertNotNull(findUsagesHandler);
    final FindUsagesOptions options = findUsagesHandler.getFindUsagesOptions();
    final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<UsageInfo>();
    for (PsiElement primaryElement : findUsagesHandler.getPrimaryElements()) {
        findUsagesHandler.processElementUsages(primaryElement, processor, options);
    }
    for (PsiElement secondaryElement : findUsagesHandler.getSecondaryElements()) {
        findUsagesHandler.processElementUsages(secondaryElement, processor, options);
    }
    return processor.getResults();
}
Also used : FindManagerImpl(com.intellij.find.impl.FindManagerImpl) FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) FindUsagesOptions(com.intellij.find.findUsages.FindUsagesOptions) CommonProcessors(com.intellij.util.CommonProcessors) FindUsagesManager(com.intellij.find.findUsages.FindUsagesManager) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement)

Example 7 with FindManagerImpl

use of com.intellij.find.impl.FindManagerImpl in project intellij-plugins by JetBrains.

the class DartServerFindUsagesTest method testFileUsage.

public void testFileUsage() {
    final PsiFile barFile = myFixture.configureByText("bar.dart", "");
    // it is important that foo.dart is not open in the editor
    myFixture.addFileToProject("foo.dart", "import '" + barFile.getName() + "';");
    // warm up
    myFixture.doHighlighting();
    final FindUsagesManager manager = ((FindManagerImpl) FindManager.getInstance(getProject())).getFindUsagesManager();
    final FindUsagesHandler handler = manager.getFindUsagesHandler(getFile(), false);
    assertNotNull(handler);
    assertFalse(handler instanceof DartServerFindUsagesHandler);
    final Collection<PsiReference> usages = handler.findReferencesToHighlight(getFile(), GlobalSearchScope.allScope(getProject()));
    assertSize(1, usages);
    final PsiReference reference = usages.iterator().next();
    assertInstanceOf(reference, DartFileReference.class);
    assertEquals("foo.dart", reference.getElement().getContainingFile().getName());
    assertEquals("import '" + barFile.getName() + "';", reference.getElement().getParent().getText());
}
Also used : FindManagerImpl(com.intellij.find.impl.FindManagerImpl) FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) DartServerFindUsagesHandler(com.jetbrains.lang.dart.ide.findUsages.DartServerFindUsagesHandler) PsiReference(com.intellij.psi.PsiReference) PsiFile(com.intellij.psi.PsiFile) FindUsagesManager(com.intellij.find.findUsages.FindUsagesManager) DartServerFindUsagesHandler(com.jetbrains.lang.dart.ide.findUsages.DartServerFindUsagesHandler)

Example 8 with FindManagerImpl

use of com.intellij.find.impl.FindManagerImpl in project intellij-plugins by JetBrains.

the class DartServerFindUsagesTest method findUsages.

@NotNull
private Collection<UsageInfo> findUsages(@NotNull final SearchScope scope) {
    final PsiElement elementToSearch = getFile().findElementAt(getEditor().getCaretModel().getOffset());
    assertNotNull(elementToSearch);
    final FindUsagesManager manager = ((FindManagerImpl) FindManager.getInstance(getProject())).getFindUsagesManager();
    final FindUsagesHandler handler = manager.getFindUsagesHandler(elementToSearch, false);
    assertInstanceOf(handler, DartServerFindUsagesHandler.class);
    final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<>();
    handler.processElementUsages(elementToSearch, processor, new FindUsagesOptions(scope));
    return processor.getResults();
}
Also used : FindManagerImpl(com.intellij.find.impl.FindManagerImpl) FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) DartServerFindUsagesHandler(com.jetbrains.lang.dart.ide.findUsages.DartServerFindUsagesHandler) FindUsagesOptions(com.intellij.find.findUsages.FindUsagesOptions) CommonProcessors(com.intellij.util.CommonProcessors) PsiElement(com.intellij.psi.PsiElement) FindUsagesManager(com.intellij.find.findUsages.FindUsagesManager) UsageInfo(com.intellij.usageView.UsageInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with FindManagerImpl

use of com.intellij.find.impl.FindManagerImpl in project intellij-community by JetBrains.

the class TextOccurrencesUtil method isSearchTextOccurencesEnabled.

public static boolean isSearchTextOccurencesEnabled(@NotNull PsiElement element) {
    final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(element.getProject())).getFindUsagesManager();
    final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(element, true);
    return FindUsagesUtil.isSearchForTextOccurrencesAvailable(element, false, handler);
}
Also used : FindManagerImpl(com.intellij.find.impl.FindManagerImpl) FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) FindUsagesManager(com.intellij.find.findUsages.FindUsagesManager)

Example 10 with FindManagerImpl

use of com.intellij.find.impl.FindManagerImpl in project intellij-community by JetBrains.

the class ChangeMethodSignatureFromUsageFix method performChange.

public static List<ParameterInfoImpl> performChange(final Project project, final Editor editor, final PsiFile file, final PsiMethod method, final int minUsagesNumber, final ParameterInfoImpl[] newParametersInfo, final boolean changeAllUsages, final boolean allowDelegation) {
    if (!FileModificationService.getInstance().prepareFileForWrite(method.getContainingFile()))
        return null;
    final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
    final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(method, false);
    //on failure or cancel (e.g. cancel of super methods dialog)
    if (handler == null)
        return null;
    final JavaMethodFindUsagesOptions options = new JavaMethodFindUsagesOptions(project);
    options.isImplementingMethods = true;
    options.isOverridingMethods = true;
    options.isUsages = true;
    options.isSearchForTextOccurrences = false;
    final int[] usagesFound = new int[1];
    Runnable runnable = () -> {
        Processor<UsageInfo> processor = t -> ++usagesFound[0] < minUsagesNumber;
        handler.processElementUsages(method, processor, options);
    };
    String progressTitle = QuickFixBundle.message("searching.for.usages.progress.title");
    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, progressTitle, true, project))
        return null;
    if (ApplicationManager.getApplication().isUnitTestMode() || usagesFound[0] < minUsagesNumber) {
        ChangeSignatureProcessor processor = new ChangeSignatureProcessor(project, method, false, null, method.getName(), method.getReturnType(), newParametersInfo) {

            @Override
            @NotNull
            protected UsageInfo[] findUsages() {
                return changeAllUsages ? super.findUsages() : UsageInfo.EMPTY_ARRAY;
            }

            @Override
            protected void performRefactoring(@NotNull UsageInfo[] usages) {
                CommandProcessor.getInstance().setCurrentCommandName(getCommandName());
                super.performRefactoring(usages);
            }
        };
        processor.run();
        ApplicationManager.getApplication().runWriteAction(() -> UndoUtil.markPsiFileForUndo(file));
        return Arrays.asList(newParametersInfo);
    } else {
        final List<ParameterInfoImpl> parameterInfos = newParametersInfo != null ? new ArrayList<>(Arrays.asList(newParametersInfo)) : new ArrayList<>();
        final PsiReferenceExpression refExpr = JavaTargetElementEvaluator.findReferenceExpression(editor);
        JavaChangeSignatureDialog dialog = JavaChangeSignatureDialog.createAndPreselectNew(project, method, parameterInfos, allowDelegation, refExpr);
        dialog.setParameterInfos(parameterInfos);
        dialog.show();
        return dialog.isOK() ? dialog.getParameters() : null;
    }
}
Also used : FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) ChangeSignatureProcessor(com.intellij.refactoring.changeSignature.ChangeSignatureProcessor) CommandProcessor(com.intellij.openapi.command.CommandProcessor) Processor(com.intellij.util.Processor) JavaMethodFindUsagesOptions(com.intellij.find.findUsages.JavaMethodFindUsagesOptions) ParameterInfoImpl(com.intellij.refactoring.changeSignature.ParameterInfoImpl) NotNull(org.jetbrains.annotations.NotNull) FindManagerImpl(com.intellij.find.impl.FindManagerImpl) JavaChangeSignatureDialog(com.intellij.refactoring.changeSignature.JavaChangeSignatureDialog) FindUsagesManager(com.intellij.find.findUsages.FindUsagesManager) UsageInfo(com.intellij.usageView.UsageInfo) ChangeSignatureProcessor(com.intellij.refactoring.changeSignature.ChangeSignatureProcessor)

Aggregations

FindManagerImpl (com.intellij.find.impl.FindManagerImpl)12 FindUsagesHandler (com.intellij.find.findUsages.FindUsagesHandler)7 FindUsagesManager (com.intellij.find.findUsages.FindUsagesManager)7 PsiElement (com.intellij.psi.PsiElement)5 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)4 UsageInfo (com.intellij.usageView.UsageInfo)4 FindManager (com.intellij.find.FindManager)2 FindSettings (com.intellij.find.FindSettings)2 FindUsagesOptions (com.intellij.find.findUsages.FindUsagesOptions)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2 CommonProcessors (com.intellij.util.CommonProcessors)2 Processor (com.intellij.util.Processor)2 DartServerFindUsagesHandler (com.jetbrains.lang.dart.ide.findUsages.DartServerFindUsagesHandler)2 TargetElementUtil (com.intellij.codeInsight.TargetElementUtil)1 HighlightUsagesHandler (com.intellij.codeInsight.highlighting.HighlightUsagesHandler)1 ReadWriteAccessDetector (com.intellij.codeInsight.highlighting.ReadWriteAccessDetector)1 HintManager (com.intellij.codeInsight.hint.HintManager)1 HintUtil (com.intellij.codeInsight.hint.HintUtil)1 FeatureUsageTracker (com.intellij.featureStatistics.FeatureUsageTracker)1