Search in sources :

Example 1 with TargetType

use of com.intellij.compiler.classFilesIndex.chainsSearch.context.TargetType in project intellij-community by JetBrains.

the class MethodsChainsCompletionContributor method searchForLookups.

private static List<LookupElement> searchForLookups(final TargetType target, final Set<String> contextRelevantTypes, final ChainCompletionContext completionContext) {
    final Project project = completionContext.getProject();
    final MethodsUsageIndexReader methodsUsageIndexReader = MethodsUsageIndexReader.getInstance(project);
    final List<MethodsChain> searchResult = searchChains(target, contextRelevantTypes, MAX_SEARCH_RESULT_SIZE, MAX_CHAIN_SIZE, completionContext, methodsUsageIndexReader);
    if (searchResult.size() < MAX_SEARCH_RESULT_SIZE) {
        if (!target.isArray()) {
            final List<MethodsChain> inheritorFilteredSearchResult = new SmartList<>();
            final Processor<TargetType> consumer = targetType -> {
                for (final MethodsChain chain : searchChains(targetType, contextRelevantTypes, MAX_SEARCH_RESULT_SIZE, MAX_CHAIN_SIZE, completionContext, methodsUsageIndexReader)) {
                    boolean insert = true;
                    for (final MethodsChain baseChain : searchResult) {
                        final MethodsChain.CompareResult r = MethodsChain.compare(baseChain, chain, completionContext.getPsiManager());
                        if (r != MethodsChain.CompareResult.NOT_EQUAL) {
                            insert = false;
                            break;
                        }
                    }
                    if (insert) {
                        inheritorFilteredSearchResult.add(chain);
                    }
                }
                searchResult.addAll(inheritorFilteredSearchResult);
                return searchResult.size() < MAX_SEARCH_RESULT_SIZE;
            };
            DirectClassInheritorsSearch.search(((PsiClassType) target.getPsiType()).resolve()).forEach(psiClass -> {
                final String inheritorQName = psiClass.getQualifiedName();
                if (inheritorQName == null) {
                    return true;
                }
                return consumer.process(new TargetType(inheritorQName, false, new PsiImmediateClassType(psiClass, PsiSubstitutor.EMPTY)));
            });
        }
    }
    final List<MethodsChain> chains = searchResult.size() > MAX_CHAIN_SIZE ? chooseHead(searchResult) : searchResult;
    return MethodsChainLookupRangingHelper.chainsToWeightableLookupElements(filterTailAndGetSumLastMethodOccurrence(chains), completionContext);
}
Also used : PsiImmediateClassType(com.intellij.psi.impl.source.PsiImmediateClassType) java.util(java.util) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) LookupElement(com.intellij.codeInsight.lookup.LookupElement) com.intellij.compiler.classFilesIndex.chainsSearch(com.intellij.compiler.classFilesIndex.chainsSearch) MethodsUsageIndexReader(com.intellij.compiler.classFilesIndex.impl.MethodsUsageIndexReader) ElementPattern(com.intellij.patterns.ElementPattern) com.intellij.codeInsight.completion(com.intellij.codeInsight.completion) ClassFilesIndexFeaturesHolder(com.intellij.compiler.classFilesIndex.api.index.ClassFilesIndexFeaturesHolder) ContextUtil(com.intellij.compiler.classFilesIndex.chainsSearch.context.ContextUtil) Nullable(org.jetbrains.annotations.Nullable) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) ChainCompletionContext(com.intellij.compiler.classFilesIndex.chainsSearch.context.ChainCompletionContext) TargetType(com.intellij.compiler.classFilesIndex.chainsSearch.context.TargetType) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Project(com.intellij.openapi.project.Project) CompletionContributorPatternUtil(com.intellij.compiler.classFilesIndex.chainsSearch.completion.CompletionContributorPatternUtil) com.intellij.psi(com.intellij.psi) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) DirectClassInheritorsSearch(com.intellij.psi.search.searches.DirectClassInheritorsSearch) ClassFilesIndexFeature(com.intellij.compiler.classFilesIndex.api.index.ClassFilesIndexFeature) PsiJavaPatterns.or(com.intellij.patterns.PsiJavaPatterns.or) Project(com.intellij.openapi.project.Project) PsiImmediateClassType(com.intellij.psi.impl.source.PsiImmediateClassType) TargetType(com.intellij.compiler.classFilesIndex.chainsSearch.context.TargetType) MethodsUsageIndexReader(com.intellij.compiler.classFilesIndex.impl.MethodsUsageIndexReader)

Aggregations

com.intellij.codeInsight.completion (com.intellij.codeInsight.completion)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 ClassFilesIndexFeature (com.intellij.compiler.classFilesIndex.api.index.ClassFilesIndexFeature)1 ClassFilesIndexFeaturesHolder (com.intellij.compiler.classFilesIndex.api.index.ClassFilesIndexFeaturesHolder)1 com.intellij.compiler.classFilesIndex.chainsSearch (com.intellij.compiler.classFilesIndex.chainsSearch)1 CompletionContributorPatternUtil (com.intellij.compiler.classFilesIndex.chainsSearch.completion.CompletionContributorPatternUtil)1 ChainCompletionContext (com.intellij.compiler.classFilesIndex.chainsSearch.context.ChainCompletionContext)1 ContextUtil (com.intellij.compiler.classFilesIndex.chainsSearch.context.ContextUtil)1 TargetType (com.intellij.compiler.classFilesIndex.chainsSearch.context.TargetType)1 MethodsUsageIndexReader (com.intellij.compiler.classFilesIndex.impl.MethodsUsageIndexReader)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)1 Project (com.intellij.openapi.project.Project)1 ElementPattern (com.intellij.patterns.ElementPattern)1 PsiJavaPatterns.or (com.intellij.patterns.PsiJavaPatterns.or)1 com.intellij.psi (com.intellij.psi)1 PsiImmediateClassType (com.intellij.psi.impl.source.PsiImmediateClassType)1 DirectClassInheritorsSearch (com.intellij.psi.search.searches.DirectClassInheritorsSearch)1 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)1 com.intellij.util (com.intellij.util)1