private PsiSubstitutor inferMethodTypeParameters(@NotNull PsiMethod method,
                                                   @NotNull PsiSubstitutor partialSubstitutor,
                                                   PsiTypeParameter @NotNull [] typeParameters,
                                                   PsiType @NotNull [] argTypes) {
    if (typeParameters.length == 0 || myArgumentTypes == null) return partialSubstitutor;

    final GrSignature erasedSignature = GrClosureSignatureUtil.createSignature(method, partialSubstitutor, true);

    final GrSignature signature = GrClosureSignatureUtil.createSignature(method, partialSubstitutor);
    final GrClosureParameter[] params = signature.getParameters();

    final GrClosureSignatureUtil.ArgInfo<PsiType>[] argInfos =
      GrClosureSignatureUtil.mapArgTypesToParameters(erasedSignature, argTypes, myPlace, true);

    if (argInfos == null || params.length > argInfos.length) return partialSubstitutor;

    Deque<InferenceStep> inferenceQueue = buildInferenceQueue(method, typeParameters, params, argInfos);

    PsiSubstitutor substitutor = partialSubstitutor;
    while (!inferenceQueue.isEmpty()) {
      substitutor = inferenceQueue.pollFirst().doInfer(substitutor);
    }

    for (PsiTypeParameter typeParameter : typeParameters) {
      if (!substitutor.getSubstitutionMap().containsKey(typeParameter)) {
        substitutor = inferFromContext(typeParameter, PsiUtil.getSmartReturnType(method), substitutor);
        if (!substitutor.getSubstitutionMap().containsKey(typeParameter)) {
          substitutor = substitutor.put(typeParameter, null);
        }
      }
    }

    return partialSubstitutor.putAll(substitutor);
  }
private PsiSubstitutor inferMethodTypeParameters(@NotNull PsiMethod method,
                                                   @NotNull PsiSubstitutor partialSubstitutor,
                                                   PsiTypeParameter @NotNull [] typeParameters,
                                                   PsiType @NotNull [] argTypes)