@Override public T supply(Dependency<? super T> dependency, Injector injector) { Type<? super T> type = dependency.getType(); Instance<? extends T> parametrized = instance.typed( instance .getType() .parametized(type.getParameters()) .lowerBound(dependency.getType().isLowerBound())); return injector.resolve(dependency.instanced(parametrized)); }
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); }
@Override public T supply(Dependency<? super T> dependency, Injector injector) { Object owner = instance; if (instanceMethod && owner == null) { owner = injector.resolve(dependency(factory.getDeclaringClass())); } final Object[] args = Argument.resolve(dependency, injector, arguments); return returnType.getRawType().cast(Invoke.method(factory, owner, args)); }
@SuppressWarnings("unchecked") @Override public E[] supply(Dependency<? super E[]> dependency, Injector injector) { E[] res = (E[]) Array.newInstance(arrayType.getComponentType(), elements.length); int i = 0; final Dependency<E> elementDependency = (Dependency<E>) dependency.typed(Type.raw(arrayType).elementType()); for (Supplier<? extends E> e : elements) { res[i++] = e.supply(elementDependency, injector); } return res; }
@Override public final T supply(Dependency<? super T> dependency, Injector injector) { Type<?> elementType = dependency.getType().parameter(0); return bridge(supplyArray(dependency.anyTyped(elementType.getArrayType()), injector)); }