private Constructor findMatchingConstructor(Method method, TypeLiteral<?> implementation,
      List<Key<?>> paramList, Errors errors) throws ErrorsException {
    Constructor<?> matchingConstructor = null;
    boolean anyAssistedInjectConstructors = false;

    // Look for AssistedInject constructors...
    for (Constructor<?> constructor : implementation.getRawType().getDeclaredConstructors()) {
      if (constructor.isAnnotationPresent(AssistedInject.class)) {
        anyAssistedInjectConstructors = true;

        if (constructorHasMatchingParams(implementation, constructor, paramList, errors)) {
          if (matchingConstructor != null) {
            errors.addMessage(PrettyPrinter.format(
                "%s has more than one constructor annotated with @AssistedInject "
                    + "that matches the parameters in method %s.",
                implementation, method));
            return null;
          } else {
            matchingConstructor = constructor;
          }
        }
      }
    }

    if (matchingConstructor != null) {
      return matchingConstructor;
    }

    if (anyAssistedInjectConstructors) {
      errors.addMessage(PrettyPrinter.format(
          "%s has @AssistedInject constructors, but none of them match the "
              + "parameters in method %s.", implementation, method));
      return null;
    }

    // Look for @Inject constructors...
    Constructor<?> injectConstructor =
        (Constructor) InjectionPoint.forConstructorOf(implementation).getMember();

    if (injectConstructorHasMatchingParams(implementation, injectConstructor, paramList, errors)) {
      return injectConstructor;
    }

    // No matching constructor exists, complain.
    errors.addMessage(PrettyPrinter.format(
        "%s has no constructors matching the parameters in method %s.",
        implementation, method));
    return null;
  }
private Constructor findMatchingConstructor ( Method method , TypeLiteral < ? > implementation , List < Key < ? > > paramList , Errors errors ) throws ErrorsException { Constructor < ? > matchingConstructor = null ; boolean anyAssistedInjectConstructors = false ; for ( Constructor < ? > constructor : implementation . getRawType ( ) . getDeclaredConstructors ( ) ) { if ( constructor . isAnnotationPresent ( AssistedInject . class ) ) { anyAssistedInjectConstructors = true ; if ( constructorHasMatchingParams ( implementation , constructor , paramList , errors ) ) { if ( matchingConstructor != null ) { errors . addMessage ( PrettyPrinter . format ( "%s has more than one constructor annotated with @AssistedInject " + "that matches the parameters in method %s." , implementation , method ) ) ; return null ; } else { matchingConstructor = constructor ; } } } } if ( matchingConstructor != null ) { return matchingConstructor ; } if ( anyAssistedInjectConstructors ) { errors . addMessage ( PrettyPrinter . format ( "%s has @AssistedInject constructors, but none of them match the " + "parameters in method %s." , implementation , method ) ) ; return null ; } Constructor < ? > injectConstructor = ( Constructor ) InjectionPoint . forConstructorOf ( implementation ) . getMember ( ) ; if ( injectConstructorHasMatchingParams ( implementation , injectConstructor , paramList , errors ) ) { return injectConstructor ; } errors . addMessage ( PrettyPrinter . format ( "%s has no constructors matching the parameters in method %s." , implementation , method ) ) ; return null ; }
Finds a constructor suitable for the method. If the implementation
contained any constructors marked with {@link AssistedInject}, this
requires all {@link Assisted} parameters to exactly match the parameters
(in any order) listed in the method. Otherwise, if no
{@link AssistedInject} constructors exist, this will default to looking
for a {@literal @}{@link Inject} constructor.