Search in sources :

Example 1 with JavaMethodsConflictResolver

use of com.intellij.psi.scope.conflictResolvers.JavaMethodsConflictResolver in project intellij-community by JetBrains.

the class PsiDiamondTypeImpl method getStaticFactoryCandidateInfo.

private static JavaResolveResult getStaticFactoryCandidateInfo(final PsiNewExpression newExpression, final PsiElement context) {
    return ourDiamondGuard.doPreventingRecursion(context, false, () -> {
        final PsiExpressionList argumentList = newExpression.getArgumentList();
        if (argumentList == null) {
            //token expected diagnostic is provided by parser
            return null;
        }
        final JavaMethodsConflictResolver resolver = new JavaMethodsConflictResolver(argumentList, PsiUtil.getLanguageLevel(newExpression));
        final JavaResolveResult[] result = collectStaticFactories(newExpression, resolver);
        final PsiMethod staticFactory = result != null && result.length == 1 ? (PsiMethod) result[0].getElement() : null;
        if (staticFactory == null) {
            //additional diagnostics: inference fails due to unresolved constructor
            return JavaResolveResult.EMPTY;
        }
        final MethodCandidateInfo staticFactoryCandidateInfo = createMethodCandidate(staticFactory, context, false, argumentList);
        if (!staticFactory.isVarArgs()) {
            return staticFactoryCandidateInfo;
        }
        final ArrayList<CandidateInfo> conflicts = new ArrayList<>();
        conflicts.add(staticFactoryCandidateInfo);
        conflicts.add(createMethodCandidate(staticFactory, context, true, argumentList));
        return resolver.resolveConflict(conflicts);
    });
}
Also used : MethodCandidateInfo(com.intellij.psi.infos.MethodCandidateInfo) CandidateInfo(com.intellij.psi.infos.CandidateInfo) MethodCandidateInfo(com.intellij.psi.infos.MethodCandidateInfo) JavaMethodsConflictResolver(com.intellij.psi.scope.conflictResolvers.JavaMethodsConflictResolver)

Aggregations

CandidateInfo (com.intellij.psi.infos.CandidateInfo)1 MethodCandidateInfo (com.intellij.psi.infos.MethodCandidateInfo)1 JavaMethodsConflictResolver (com.intellij.psi.scope.conflictResolvers.JavaMethodsConflictResolver)1