private static boolean isInferredSameTypeAfterConversion(PsiLambdaExpression lambdaExpression,
                                                           PsiMethodReferenceExpression methodReferenceExpression) {
    PsiCall call = LambdaUtil.treeWalkUp(methodReferenceExpression);
    if (call == null) {
      return true;
    }
    Object marker = new Object();
    PsiTreeUtil.mark(methodReferenceExpression, marker);
    try {
      RecaptureTypeMapper.encode(methodReferenceExpression);
      PsiCall copyTopLevelCall = LambdaUtil.copyTopLevelCall(call);
      if (copyTopLevelCall != null) {
        PsiMethodReferenceExpression methodReferenceInCopy = (PsiMethodReferenceExpression)PsiTreeUtil.releaseMark(copyTopLevelCall, marker);
        if (methodReferenceInCopy != null) {
          PsiClassType functionalInterfaceType = ObjectUtils.tryCast(methodReferenceInCopy.getFunctionalInterfaceType(), PsiClassType.class);
          if (functionalInterfaceType == null) return false;
          PsiClassType.ClassResolveResult funcResult = functionalInterfaceType.resolveGenerics();
          PsiClass funcClass = funcResult.getElement();
          PsiSubstitutor funcSubstitutor = funcResult.getSubstitutor();
          PsiSubstitutor recapture = new RecaptureTypeMapper().recapture(funcSubstitutor);
          PsiLambdaExpression lambdaCopy = (PsiLambdaExpression)methodReferenceInCopy.replace(lambdaExpression);

          PsiClassType lambdaCopyType = (PsiClassType)lambdaCopy.getFunctionalInterfaceType();
          if (lambdaCopyType == null) return false;
          PsiClassType.ClassResolveResult lambdaCopyResult = lambdaCopyType.resolveGenerics();
          PsiClass lambdaCopyClass = lambdaCopyResult.getElement();
          PsiSubstitutor lambdaCopySubstitutor = lambdaCopyResult.getSubstitutor();
          return lambdaExpression.getManager().areElementsEquivalent(funcClass, lambdaCopyClass)
                 && recapture.equals(lambdaCopySubstitutor);
        }
      }
    }
    finally {
      RecaptureTypeMapper.clean(methodReferenceExpression);
    }
    return false;
  }
private static boolean isInferredSameTypeAfterConversion(PsiLambdaExpression lambdaExpression,
                                                           PsiMethodReferenceExpression methodReferenceExpression)