PsiSubstitutor (boolean includeReturnConstraint) { if (interfaceMethod == null) return substitutor; InferenceSession session = new InferenceSession(method.getTypeParameters(), substitutor, reference.getManager(), reference); session.initThrowsConstraints(method); PsiSubstitutor psiSubstitutor = session.collectApplicabilityConstraints(reference, this, functionalInterfaceType); if (psiSubstitutor != null) { return psiSubstitutor; } if (!session.repeatInferencePhases()) { List<String> errorMessages = session.getIncompatibleErrorMessages(); if (errorMessages != null) { setApplicabilityError(StringUtil.join(errorMessages, "\n")); } return substitutor; } if (includeReturnConstraint && !PsiTypes.voidType().equals(interfaceMethodReturnType) && interfaceMethodReturnType != null) { PsiType returnType = method.isConstructor() ? composeReturnType(containingClass, substitutor) : PsiMethodReferenceCompatibilityConstraint .getSubstitutor(signature, qualifierResolveResult, method, containingClass, reference) .substitute(method.getReturnType()); if (returnType != null) { session.registerReturnTypeConstraints(returnType, interfaceMethodReturnType, reference); } } return session.infer(method.getParameterList().getParameters(), null, null, null); }