public PsiSubstitutor inferSubstitutorFromArgs(@NotNull ParameterTypeInferencePolicy policy, final PsiExpression[] arguments) { if (myTypeArguments == null) { return inferTypeArguments(policy, arguments); } else { PsiSubstitutor incompleteSubstitutor = super.getSubstitutor(); PsiMethod method = getElement(); if (method != null) { PsiTypeParameter[] typeParams = method.getTypeParameters(); for (int i = 0; i < myTypeArguments.length && i < typeParams.length; i++) { incompleteSubstitutor = incompleteSubstitutor.put(typeParams[i], myTypeArguments[i]); } } return incompleteSubstitutor; } }
@Nullable private static InferenceSession startTopLevelInference(final PsiCall topLevelCall, final ParameterTypeInferencePolicy policy) { final JavaResolveResult result = topLevelCall.resolveMethodGenerics(); if(result instanceof MethodCandidateInfo) { final PsiMethod method = ((MethodCandidateInfo) result).getElement(); final PsiParameter[] topLevelParameters = method.getParameterList().getParameters(); final PsiExpressionList topLevelCallArgumentList = topLevelCall.getArgumentList(); LOG.assertTrue(topLevelCallArgumentList != null, topLevelCall); final PsiExpression[] topLevelArguments = topLevelCallArgumentList.getExpressions(); return PsiResolveHelper.ourGraphGuard.doPreventingRecursion(topLevelCall, true, new Computable<InferenceSession>() { @Override public InferenceSession compute() { final InferenceSession topLevelSession = new InferenceSession(method.getTypeParameters(), ((MethodCandidateInfo) result).getSiteSubstitutor(), topLevelCall.getManager(), topLevelCall, policy); topLevelSession.initExpressionConstraints(topLevelParameters, topLevelArguments, topLevelCall, method, ((MethodCandidateInfo) result).isVarargs()); topLevelSession.infer(topLevelParameters, topLevelArguments, topLevelCall, ((MethodCandidateInfo) result).createProperties()); return topLevelSession; } }); } return null; }
@Override public PsiType inferTypeForMethodTypeParameter(@NotNull PsiTypeParameter typeParameter, @NotNull PsiParameter[] parameters, @NotNull PsiExpression[] arguments, @NotNull PsiSubstitutor partialSubstitutor, @Nullable PsiElement parent, @NotNull ParameterTypeInferencePolicy policy) { final PsiSubstitutor substitutor; if(parent != null) { substitutor = inferTypeArguments(new PsiTypeParameter[]{typeParameter}, parameters, arguments, partialSubstitutor, parent, policy, PsiUtil.getLanguageLevel(parent)); } else { final InferenceSession inferenceSession = new InferenceSession(new PsiTypeParameter[]{typeParameter}, partialSubstitutor, myManager, null); inferenceSession.initExpressionConstraints(parameters, arguments, null); substitutor = inferenceSession.infer(); } return substitutor.substitute(typeParameter); }
@NotNull @Override public PsiSubstitutor inferTypeArguments(@NotNull PsiTypeParameter[] typeParameters, @NotNull PsiParameter[] parameters, @NotNull PsiExpression[] arguments, @NotNull PsiSubstitutor partialSubstitutor, @NotNull PsiElement parent, @NotNull ParameterTypeInferencePolicy policy, @NotNull LanguageLevel languageLevel) { if(typeParameters.length == 0) { return partialSubstitutor; } return InferenceSessionContainer.infer(typeParameters, parameters, arguments, partialSubstitutor, parent, policy); }
/** * If iterated through all candidates, should be called under {@link #ourOverloadGuard} guard so results won't be cached on the top level call */ @NotNull public PsiSubstitutor inferTypeArguments(@NotNull final ParameterTypeInferencePolicy policy, @NotNull final PsiExpression[] arguments, boolean includeReturnConstraint) { return computeForOverloadedCandidate(() -> { final PsiMethod method = this.getElement(); PsiTypeParameter[] typeParameters = method.getTypeParameters(); if(this.isRawSubstitution()) { return JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createRawSubstitutor(mySubstitutor, typeParameters); } final PsiElement parent = this.getParent(); if(parent == null) { return PsiSubstitutor.EMPTY; } Project project = method.getProject(); JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project); return javaPsiFacade.getResolveHelper().inferTypeArguments(typeParameters, method.getParameterList().getParameters(), arguments, mySubstitutor, parent, policy, myLanguageLevel); }, super.getSubstitutor(), policy.isVarargsIgnored() || isVarargs(), !includeReturnConstraint); }
@Override public PsiType inferTypeForMethodTypeParameter(@NotNull PsiTypeParameter typeParameter, @NotNull PsiParameter[] parameters, @NotNull PsiExpression[] arguments, @NotNull PsiSubstitutor partialSubstitutor, @Nullable PsiElement parent, @NotNull ParameterTypeInferencePolicy policy) { final InferenceSession inferenceSession = new InferenceSession(new PsiTypeParameter[]{typeParameter}, partialSubstitutor, myManager, parent); inferenceSession.initExpressionConstraints(parameters, arguments, parent, null); return inferenceSession.infer(parameters, arguments, parent).substitute(typeParameter); }
@NotNull @Override public PsiSubstitutor inferTypeArguments(@NotNull PsiTypeParameter[] typeParameters, @NotNull PsiParameter[] parameters, @NotNull PsiExpression[] arguments, @NotNull PsiSubstitutor partialSubstitutor, @NotNull PsiElement parent, @NotNull ParameterTypeInferencePolicy policy, @NotNull LanguageLevel languageLevel) { if (typeParameters.length == 0) return partialSubstitutor; final InferenceSession inferenceSession = new InferenceSession(typeParameters, partialSubstitutor, myManager, parent); inferenceSession.initExpressionConstraints(parameters, arguments, parent, null); return inferenceSession.infer(parameters, arguments, parent); }
public PsiSubstitutor inferSubstitutorFromArgs(@NotNull ParameterTypeInferencePolicy policy, final PsiExpression[] arguments) { if (myTypeArguments == null) { return inferTypeArguments(policy, arguments, true); } else { return getSiteSubstitutor(); } }
/** * @return {@link PsiType#NULL} iff no type could be inferred * null iff the type inferred is raw * inferred type otherwise */ PsiType inferTypeForMethodTypeParameter(@NotNull PsiTypeParameter typeParameter, @NotNull PsiParameter[] parameters, @NotNull PsiExpression[] arguments, @NotNull PsiSubstitutor partialSubstitutor, @Nullable PsiElement parent, @NotNull ParameterTypeInferencePolicy policy);
@NotNull PsiSubstitutor inferTypeArguments(@NotNull PsiTypeParameter[] typeParameters, @NotNull PsiParameter[] parameters, @NotNull PsiExpression[] arguments, @NotNull PsiSubstitutor partialSubstitutor, @NotNull PsiElement parent, @NotNull ParameterTypeInferencePolicy policy);
@NotNull PsiSubstitutor inferTypeArguments(@NotNull PsiTypeParameter[] typeParameters, @NotNull PsiParameter[] parameters, @NotNull PsiExpression[] arguments, @NotNull PsiSubstitutor partialSubstitutor, @NotNull PsiElement parent, @NotNull ParameterTypeInferencePolicy policy, @NotNull LanguageLevel languageLevel);
public InferenceSession(PsiTypeParameter[] typeParams, PsiSubstitutor siteSubstitutor, PsiManager manager, PsiElement context, ParameterTypeInferencePolicy policy) { myManager = manager; mySiteSubstitutor = siteSubstitutor; myContext = context; myPolicy = policy; initBounds(typeParams); }
public PsiSubstitutor inferSubstitutorFromArgs(@NotNull ParameterTypeInferencePolicy policy, final PsiExpression[] arguments) { if(myTypeArguments == null) { return inferTypeArguments(policy, arguments, true); } else { return getSiteSubstitutor(); } }
@NotNull public PsiSubstitutor inferTypeArguments(@NotNull ParameterTypeInferencePolicy policy, boolean includeReturnConstraint) { return inferTypeArguments(policy, myArgumentList instanceof PsiExpressionList ? ((PsiExpressionList)myArgumentList).getExpressions() : PsiExpression.EMPTY_ARRAY, includeReturnConstraint); }
public PsiSubstitutor inferTypeArguments(@NotNull ParameterTypeInferencePolicy policy) { return inferTypeArguments(policy, myArgumentList instanceof PsiExpressionList ? ((PsiExpressionList)myArgumentList).getExpressions() : PsiExpression.EMPTY_ARRAY); }
@NotNull public PsiSubstitutor inferTypeArguments(@NotNull ParameterTypeInferencePolicy policy, boolean includeReturnConstraint) { return inferTypeArguments(policy, myArgumentList instanceof PsiExpressionList ? ((PsiExpressionList) myArgumentList).getExpressions() : PsiExpression.EMPTY_ARRAY, includeReturnConstraint); }