Exemple #1
0
 public static <T> Supplier<T> costructor(Constructor<T> constructor, Parameter<?>... parameters) {
   final Class<?>[] params = constructor.getParameterTypes();
   if (params.length == 0) {
     return new StaticConstructorSupplier<T>(constructor, NO_ARGS);
   }
   Argument<?>[] arguments = Argument.arguments(parameterTypes(constructor), parameters);
   return Argument.allConstants(arguments)
       ? new StaticConstructorSupplier<T>(constructor, Argument.constantsFrom(arguments))
       : new ConstructorSupplier<T>(constructor, arguments);
 }
Exemple #2
0
 public static <T> Supplier<T> method(
     Type<T> returnType, Method factory, Object instance, Parameter<?>... parameters) {
   if (!Type.returnType(factory).isAssignableTo(returnType)) {
     throw new IllegalArgumentException(
         "The factory methods methods return type `"
             + Type.returnType(factory)
             + "` is not assignable to: "
             + returnType);
   }
   if (instance != null && factory.getDeclaringClass() != instance.getClass()) {
     throw new IllegalArgumentException(
         "The factory method and the instance it is invoked on have to be the same class.");
   }
   Argument<?>[] arguments = Argument.arguments(Type.parameterTypes(factory), parameters);
   return new FactoryMethodSupplier<T>(returnType, factory, instance, arguments);
 }