Search in sources :

Example 1 with ChooseByNameContributorEx

use of com.intellij.navigation.ChooseByNameContributorEx 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)

Aggregations

PluginException (com.intellij.diagnostic.PluginException)1 ChooseByNameContributor (com.intellij.navigation.ChooseByNameContributor)1 ChooseByNameContributorEx (com.intellij.navigation.ChooseByNameContributorEx)1 ReadActionProcessor (com.intellij.openapi.application.ReadActionProcessor)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 TIntHashSet (gnu.trove.TIntHashSet)1 NotNull (org.jetbrains.annotations.NotNull)1