Search in sources :

Example 1 with WeightableChainLookupElement

use of com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.WeightableChainLookupElement in project intellij-community by JetBrains.

the class MethodsChainLookupRangingHelper method chainToWeightableLookupElement.

@SuppressWarnings("ConstantConditions")
@Nullable
private static LookupElement chainToWeightableLookupElement(final MethodsChain chain, final ChainCompletionContext context, final CachedRelevantStaticMethodSearcher staticMethodSearcher) {
    final int chainSize = chain.size();
    assert chainSize != 0;
    final int lastMethodWeight = chain.getChainWeight();
    int unreachableParametersCount = 0;
    int notMatchedStringVars = 0;
    int matchedParametersInContext = 0;
    Boolean isFirstMethodStatic = null;
    Boolean hasCallingVariableInContext = null;
    LookupElement chainLookupElement = null;
    PsiClass newVariableClass = null;
    final NullableNotNullManager nullableNotNullManager = NullableNotNullManager.getInstance(context.getProject());
    for (final PsiMethod[] psiMethods : chain.getPath()) {
        final PsiMethod method = MethodChainsSearchUtil.getMethodWithMinNotPrimitiveParameters(psiMethods, Collections.singleton(context.getTarget().getClassQName()));
        if (method == null) {
            return null;
        }
        if (isFirstMethodStatic == null) {
            isFirstMethodStatic = psiMethods[0].hasModifierProperty(PsiModifier.STATIC);
        }
        final PsiClass qualifierClass;
        final boolean isHead = chainLookupElement == null;
        if (isHead) {
            final String qualifierClassName = chain.getQualifierClassName();
            qualifierClass = JavaPsiFacade.getInstance(context.getProject()).findClass(qualifierClassName, context.getResolveScope());
        } else {
            qualifierClass = null;
        }
        final MethodProcResult procResult = processMethod(method, qualifierClass, isHead, lastMethodWeight, context, staticMethodSearcher, nullableNotNullManager);
        if (procResult == null) {
            return null;
        }
        if (hasCallingVariableInContext == null) {
            hasCallingVariableInContext = procResult.hasCallingVariableInContext();
        }
        if (isHead && procResult.isIntroduceNewVariable()) {
            newVariableClass = qualifierClass;
        }
        matchedParametersInContext += procResult.getMatchedParametersInContext();
        unreachableParametersCount += procResult.getUnreachableParametersCount();
        notMatchedStringVars += procResult.getNotMatchedStringVars();
        chainLookupElement = isHead ? procResult.getLookupElement() : new JavaChainLookupElement(chainLookupElement, procResult.getLookupElement());
    }
    if (newVariableClass != null) {
        chainLookupElement = ChainCompletionNewVariableLookupElement.create(newVariableClass, chainLookupElement);
    }
    final ChainRelevance relevance = new ChainRelevance(chainSize, lastMethodWeight, unreachableParametersCount, notMatchedStringVars, hasCallingVariableInContext, isFirstMethodStatic, matchedParametersInContext);
    return new WeightableChainLookupElement(chainLookupElement, relevance);
}
Also used : NullableNotNullManager(com.intellij.codeInsight.NullableNotNullManager) WeightableChainLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.WeightableChainLookupElement) JavaChainLookupElement(com.intellij.codeInsight.completion.JavaChainLookupElement) SubLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.SubLookupElement) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ChainCompletionLookupElementUtil.createLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.ChainCompletionLookupElementUtil.createLookupElement) WeightableChainLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.WeightableChainLookupElement) ChainCompletionNewVariableLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.ChainCompletionNewVariableLookupElement) GetterLookupSubLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.GetterLookupSubLookupElement) VariableSubLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.VariableSubLookupElement) JavaChainLookupElement(com.intellij.codeInsight.completion.JavaChainLookupElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with WeightableChainLookupElement

use of com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.WeightableChainLookupElement in project intellij-community by JetBrains.

the class MethodChainsCompletionTest method doCompletion.

private List<WeightableChainLookupElement> doCompletion() {
    compileAndIndexData(TEST_INDEX_FILE_NAME);
    final LookupElement[] allLookupElements = runCompletion();
    final List<WeightableChainLookupElement> targetLookupElements = new SmartList<>();
    for (final LookupElement lookupElement : allLookupElements) {
        if (lookupElement instanceof WeightableChainLookupElement) {
            targetLookupElements.add((WeightableChainLookupElement) lookupElement);
        }
    }
    return targetLookupElements;
}
Also used : WeightableChainLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.WeightableChainLookupElement) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ChainCompletionMethodCallLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.ChainCompletionMethodCallLookupElement) WeightableChainLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.WeightableChainLookupElement) SmartList(com.intellij.util.SmartList)

Aggregations

LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 WeightableChainLookupElement (com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.WeightableChainLookupElement)2 NullableNotNullManager (com.intellij.codeInsight.NullableNotNullManager)1 JavaChainLookupElement (com.intellij.codeInsight.completion.JavaChainLookupElement)1 ChainCompletionLookupElementUtil.createLookupElement (com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.ChainCompletionLookupElementUtil.createLookupElement)1 ChainCompletionMethodCallLookupElement (com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.ChainCompletionMethodCallLookupElement)1 ChainCompletionNewVariableLookupElement (com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.ChainCompletionNewVariableLookupElement)1 GetterLookupSubLookupElement (com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.GetterLookupSubLookupElement)1 SubLookupElement (com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.SubLookupElement)1 VariableSubLookupElement (com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.VariableSubLookupElement)1 SmartList (com.intellij.util.SmartList)1 Nullable (org.jetbrains.annotations.Nullable)1