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);
}
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;
}
Aggregations