private static @NotNull List<? extends PsiType> composeAcceptableType1(final PsiClass interface2Consider,
                                                                         final PsiFunctionalExpression expression,
                                                                         final PsiType qualifierType) {
    if (interface2Consider.hasTypeParameters()) {
      final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(interface2Consider);
      if (interfaceMethod != null) {
        final PsiParameter[] parameters = interfaceMethod.getParameterList().getParameters();
        Project project = interface2Consider.getProject();
        PsiType returnType = interfaceMethod.getReturnType();
        if (expression instanceof PsiLambdaExpression && ((PsiLambdaExpression)expression).hasFormalParameterTypes()) {
          PsiParameter[] functionalExprParameters = ((PsiLambdaExpression)expression).getParameterList().getParameters();
          if (parameters.length != functionalExprParameters.length) {
            return Collections.emptyList();
          }

          final PsiType[] left = new PsiType[parameters.length + 1];
          final PsiType[] right = new PsiType[parameters.length + 1];
          for (int i = 0; i < functionalExprParameters.length; i++) {
            left[i] = parameters[i].getType();
            right[i] = functionalExprParameters[i].getType();
          }

          List<PsiExpression> returnExpressions = LambdaUtil.getReturnExpressions(((PsiLambdaExpression)expression));
          left[parameters.length] = returnExpressions.isEmpty() ? PsiTypes.voidType() : returnExpressions.get(0).getType();
          right[parameters.length] = returnType;

          final PsiSubstitutor substitutor = PsiResolveHelper.getInstance(project)
            .inferTypeArguments(interface2Consider.getTypeParameters(), left, right, PsiUtil.getLanguageLevel(expression));

          PsiType type = JavaPsiFacade.getElementFactory(project).createType(interface2Consider, substitutor);

          if (expression.isAcceptable(type)) {
            return Collections.singletonList(type);
          }
        }
        else if (expression instanceof PsiMethodReferenceExpression referenceExpression) {
          List<PsiType> types = new ArrayList<>();
          for (JavaResolveResult result : referenceExpression.multiResolve(true)) {
            final PsiElement element = result.getElement();
            if (element == null) continue;

            if (element instanceof PsiMethod method) {
              int offset = hasOffset(referenceExpression, method) ? 1 : 0;
              final PsiParameter[] targetMethodParameters = method.getParameterList().getParameters();
              if (targetMethodParameters.length + offset == parameters.length) {

                final PsiType[] left = new PsiType[parameters.length + 1];
                final PsiType[] right = new PsiType[parameters.length + 1];
                if (offset > 0) {
                  if (qualifierType == null) {
                    continue;
                  }
                  left[0] = parameters[0].getType();
                  right[0] = qualifierType;
                }

                final PsiSubstitutor partialSubstitutor = getPartialSubstitutor(referenceExpression, method);

                for (int i = 0; i < targetMethodParameters.length; i++) {
                  left[i + offset] = parameters[i + offset].getType();
                  right[i + offset] = partialSubstitutor.substitute(targetMethodParameters[i].getType());
                }

                left[parameters.length] = method.isConstructor() ? qualifierType : partialSubstitutor.substitute(method.getReturnType());
                right[parameters.length] = returnType;

                ContainerUtil.addIfNotNull(types, getAcceptableType(interface2Consider, expression, left, right));
              }
            }
            else if (maybeDefaultConstructorRef(referenceExpression, interfaceMethod, element)) {

              final PsiType[] left = new PsiType[] { qualifierType };
              final PsiType[] right = new PsiType[] { returnType };

              ContainerUtil.addIfNotNull(types, getAcceptableType(interface2Consider, expression, left, right));
            }
          }
          return types;
        }
      }
    }
    return Collections.emptyList();
  }
private static @NotNull List<? extends PsiType> composeAcceptableType1(final PsiClass interface2Consider,
                                                                         final PsiFunctionalExpression expression,
                                                                         final PsiType qualifierType)