/** * Returns an object producer. */ private <T> BindingAmp<T> findObjectBinding(Key<T> key) { Objects.requireNonNull(key); if (key.qualifiers().length != 1) { throw new IllegalArgumentException(); } return (BindingAmp) findBinding(Key.of(Object.class, key.qualifiers()[0])); }
/** * Builds Key from field's generic type and field's qualifying annotations. * A qualifying annotation is marked with a {@code @Qualifier}. * * @param field field for deriving type and annotation from * @param <T> target type * @return instance of a Key */ public static <T> Key<T> of(Field field) { return new Key(field.getGenericType(), qualifiers(field.getAnnotations())); }
/** * Builds Key from method's generic return type and method's qualifying * annotations. A qualifying annotation is marked with a {@code @Qualifier}. * * @param method method for deriving return type and annotations from * @param <T> target type * @return instance of a Key */ public static <T> Key<T> of(Method method) { return new Key(method.getGenericReturnType(), qualifiers(method.getAnnotations())); }
/** * Builds Key from constructor's declaring class and constructor's qualifying * annotations. A qualifying annotation is marked with a {@code @Qualifier}. * * @param ctor constructor for deriving type and annotations from * @param <T> target type * @return instance of a Key */ public static <T> Key<T> of(Constructor ctor) { return new Key(ctor.getDeclaringClass(), qualifiers(ctor.getAnnotations())); }
/** * Builds Key from parameter's parameterized type and and qualifying annotations * found on the parameter and its declaring executable (e.g. Method) * * @param parameter parameter for deriving type and annotations from * @return instance of a key */ public static Key<?> of(Parameter parameter) { return new Key(parameter.getParameterizedType(), qualifiers(parameter.getAnnotations(), parameter.getDeclaringExecutable().getAnnotations())); }