Search in sources :

Example 1 with ChooseByNameContributor

use of com.intellij.navigation.ChooseByNameContributor in project intellij-community by JetBrains.

the class TestsLocationProviderUtil method collectCandidates.

public static List<FileInfo> collectCandidates(final Project project, final String fileName, final boolean includeNonProjectItems) {
    final List<FileInfo> filesInfo = new ArrayList<>();
    final ChooseByNameContributor[] contributors = Extensions.getExtensions(ChooseByNameContributor.FILE_EP_NAME);
    for (ChooseByNameContributor contributor : contributors) {
        // let's find files with same name in project and libraries
        final NavigationItem[] navigationItems = contributor.getItemsByName(fileName, fileName, project, includeNonProjectItems);
        for (NavigationItem navigationItem : navigationItems) {
            if (navigationItem instanceof PsiFile) {
                final VirtualFile itemFile = ((PsiFile) navigationItem).getVirtualFile();
                assert itemFile != null;
                filesInfo.add(new FileInfo(itemFile));
            }
        }
    }
    return filesInfo;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NavigationItem(com.intellij.navigation.NavigationItem) ArrayList(java.util.ArrayList) ChooseByNameContributor(com.intellij.navigation.ChooseByNameContributor) PsiFile(com.intellij.psi.PsiFile)

Example 2 with ChooseByNameContributor

use of com.intellij.navigation.ChooseByNameContributor in project intellij-elixir by KronicDeth.

the class GotoSymbolContributorTest method testIssue472.

/*
     * Tests
     */
public void testIssue472() {
    myFixture.configureByFile("issue_472.ex");
    ChooseByNameContributor[] symbolModelContributors = ChooseByNameRegistry.getInstance().getSymbolModelContributors();
    GotoSymbolContributor gotoSymbolContributor = null;
    for (ChooseByNameContributor symbolModelContributor : symbolModelContributors) {
        if (symbolModelContributor instanceof GotoSymbolContributor) {
            gotoSymbolContributor = (GotoSymbolContributor) symbolModelContributor;
        }
    }
    assertNotNull(gotoSymbolContributor);
    NavigationItem[] itemsByName = gotoSymbolContributor.getItemsByName("decode_auth_type", "decode_a", myFixture.getProject(), false);
    assertEquals(2, itemsByName.length);
    assertInstanceOf(itemsByName[0], CallDefinition.class);
    CallDefinition callDefinition = (CallDefinition) itemsByName[0];
    assertEquals("decode_auth_type", callDefinition.name());
    assertInstanceOf(itemsByName[1], CallDefinitionClause.class);
    CallDefinitionClause callDefinitionClause = (CallDefinitionClause) itemsByName[1];
    assertEquals("decode_auth_type", callDefinitionClause.getName());
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) CallDefinition(org.elixir_lang.structure_view.element.CallDefinition) ChooseByNameContributor(com.intellij.navigation.ChooseByNameContributor) CallDefinitionClause(org.elixir_lang.structure_view.element.CallDefinitionClause)

Example 3 with ChooseByNameContributor

use of com.intellij.navigation.ChooseByNameContributor in project intellij-community by JetBrains.

the class FilePathCompletionContributor method getAllNames.

private static String[] getAllNames(@NotNull final Project project) {
    Set<String> names = new HashSet<>();
    final ChooseByNameContributor[] nameContributors = ChooseByNameContributor.FILE_EP_NAME.getExtensions();
    for (final ChooseByNameContributor contributor : nameContributors) {
        try {
            names.addAll(Arrays.asList(contributor.getNames(project, false)));
        } catch (ProcessCanceledException ex) {
        // index corruption detected, ignore
        } catch (Exception ex) {
            LOG.error(ex);
        }
    }
    return ArrayUtil.toStringArray(names);
}
Also used : ChooseByNameContributor(com.intellij.navigation.ChooseByNameContributor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 4 with ChooseByNameContributor

use of com.intellij.navigation.ChooseByNameContributor in project intellij-community by JetBrains.

the class ContributorsBasedGotoByModel method processNames.

@Override
public void processNames(final Processor<String> nameProcessor, final boolean checkBoxState) {
    long start = System.currentTimeMillis();
    List<ChooseByNameContributor> liveContribs = filterDumb(myContributors);
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    Processor<ChooseByNameContributor> processor = new ReadActionProcessor<ChooseByNameContributor>() {

        @Override
        public boolean processInReadAction(@NotNull ChooseByNameContributor contributor) {
            try {
                if (!myProject.isDisposed()) {
                    long contributorStarted = System.currentTimeMillis();
                    final TIntHashSet filter = new TIntHashSet(1000);
                    myContributorToItsSymbolsMap.put(contributor, filter);
                    if (contributor instanceof ChooseByNameContributorEx) {
                        ((ChooseByNameContributorEx) contributor).processNames(s -> {
                            if (nameProcessor.process(s)) {
                                filter.add(s.hashCode());
                            }
                            return true;
                        }, FindSymbolParameters.searchScopeFor(myProject, checkBoxState), getIdFilter(checkBoxState));
                    } else {
                        String[] names = contributor.getNames(myProject, checkBoxState);
                        for (String element : names) {
                            if (nameProcessor.process(element)) {
                                filter.add(element.hashCode());
                            }
                        }
                    }
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(contributor + " for " + (System.currentTimeMillis() - contributorStarted));
                    }
                }
            } catch (ProcessCanceledException | IndexNotReadyException ex) {
            // index corruption detected, ignore
            } catch (Exception ex) {
                LOG.error(ex);
            }
            return true;
        }
    };
    if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(liveContribs, indicator, true, processor)) {
        throw new ProcessCanceledException();
    }
    if (indicator != null) {
        indicator.checkCanceled();
    }
    long finish = System.currentTimeMillis();
    if (LOG.isDebugEnabled()) {
        LOG.debug("processNames(): " + (finish - start) + "ms;");
    }
}
Also used : NotNull(org.jetbrains.annotations.NotNull) TIntHashSet(gnu.trove.TIntHashSet) PluginException(com.intellij.diagnostic.PluginException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ChooseByNameContributorEx(com.intellij.navigation.ChooseByNameContributorEx) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ChooseByNameContributor(com.intellij.navigation.ChooseByNameContributor) ReadActionProcessor(com.intellij.openapi.application.ReadActionProcessor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 5 with ChooseByNameContributor

use of com.intellij.navigation.ChooseByNameContributor in project intellij-community by JetBrains.

the class GotoClassModel2 method getSeparatorsFromContributors.

public static String[] getSeparatorsFromContributors(ChooseByNameContributor[] contributors) {
    final Set<String> separators = new HashSet<>();
    separators.add(".");
    for (ChooseByNameContributor c : contributors) {
        if (c instanceof GotoClassContributor) {
            ContainerUtil.addIfNotNull(separators, ((GotoClassContributor) c).getQualifiedNameSeparator());
        }
    }
    return ArrayUtil.toStringArray(separators);
}
Also used : GotoClassContributor(com.intellij.navigation.GotoClassContributor) ChooseByNameContributor(com.intellij.navigation.ChooseByNameContributor) HashSet(java.util.HashSet)

Aggregations

ChooseByNameContributor (com.intellij.navigation.ChooseByNameContributor)5 NavigationItem (com.intellij.navigation.NavigationItem)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 PluginException (com.intellij.diagnostic.PluginException)1 ChooseByNameContributorEx (com.intellij.navigation.ChooseByNameContributorEx)1 GotoClassContributor (com.intellij.navigation.GotoClassContributor)1 ReadActionProcessor (com.intellij.openapi.application.ReadActionProcessor)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 TIntHashSet (gnu.trove.TIntHashSet)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CallDefinition (org.elixir_lang.structure_view.element.CallDefinition)1 CallDefinitionClause (org.elixir_lang.structure_view.element.CallDefinitionClause)1 NotNull (org.jetbrains.annotations.NotNull)1