/** * Returns the instance methods and fields of {@code instance} that will be injected to fulfill * this request. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on the class of {@code * instance}, such as a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} * of the valid injection points. */ public Set<InjectionPoint> getInjectionPoints() throws ConfigurationException { return InjectionPoint.forInstanceMethodsAndFields(instance.getClass()); }
/** * Returns all instance method and field injection points on {@code type}. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as * a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} * of the valid injection points. */ public static Set<InjectionPoint> forInstanceMethodsAndFields(Class<?> type) { return forInstanceMethodsAndFields(TypeLiteral.get(type)); }
@Override public BindingBuilder<T> toProvider(Provider<? extends T> provider) { Objects.requireNonNull(provider, "provider"); checkNotTargetted(); // lookup the injection points, adding any errors to the binder's errors list Set<InjectionPoint> injectionPoints; try { injectionPoints = InjectionPoint.forInstanceMethodsAndFields(provider.getClass()); } catch (ConfigurationException e) { for (Message message : e.getErrorMessages()) { binder.addError(message); } injectionPoints = unmodifiableSet(new HashSet<InjectionPoint>(e.getPartialValue())); } BindingImpl<T> base = getBinding(); setBinding(new ProviderInstanceBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), injectionPoints, provider)); return this; }
@Override public void toInstance(T instance) { checkNotTargetted(); // lookup the injection points, adding any errors to the binder's errors list Set<InjectionPoint> injectionPoints; if (instance != null) { try { injectionPoints = InjectionPoint.forInstanceMethodsAndFields(instance.getClass()); } catch (ConfigurationException e) { for (Message message : e.getErrorMessages()) { binder.addError(message); } injectionPoints = unmodifiableSet(new HashSet<InjectionPoint>(e.getPartialValue())); } } else { binder.addError(BINDING_TO_NULL); injectionPoints = emptySet(); } BindingImpl<T> base = getBinding(); setBinding(new InstanceBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), injectionPoints, instance)); }
/** * Returns the instance methods and fields of {@code instance} that will be injected to fulfill * this request. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on the class of {@code * instance}, such as a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} * of the valid injection points. */ public Set<InjectionPoint> getInjectionPoints() throws ConfigurationException { return InjectionPoint.forInstanceMethodsAndFields(instance.getClass()); }
/** * Returns the instance methods and fields of {@code instance} that will be injected to fulfill * this request. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on the class of {@code * instance}, such as a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} * of the valid injection points. */ public Set<InjectionPoint> getInjectionPoints() throws ConfigurationException { return InjectionPoint.forInstanceMethodsAndFields(instance.getClass()); }
/** * Returns the instance methods and fields of {@code instance} that will be injected to fulfill * this request. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on the class of {@code * instance}, such as a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} * of the valid injection points. */ public Set<InjectionPoint> getInjectionPoints() throws ConfigurationException { return InjectionPoint.forInstanceMethodsAndFields(instance.getClass()); }
/** * Returns the instance methods and fields of {@code instance} that will be injected to fulfill * this request. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on the class of {@code * instance}, such as a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} * of the valid injection points. */ public Set<InjectionPoint> getInjectionPoints() throws ConfigurationException { return InjectionPoint.forInstanceMethodsAndFields(instance.getClass()); }
/** * Returns all instance method and field injection points on {@code type}. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as * a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} * of the valid injection points. */ public static Set<InjectionPoint> forInstanceMethodsAndFields(Class<?> type) { return forInstanceMethodsAndFields(TypeLiteral.get(type)); }
/** * Creates a new members injector and attaches both injection listeners and method aspects. */ private <T> MembersInjectorImpl<T> createWithListeners(TypeLiteral<T> type, Errors errors) throws ErrorsException { int numErrorsBefore = errors.size(); Set<InjectionPoint> injectionPoints; try { injectionPoints = InjectionPoint.forInstanceMethodsAndFields(type); } catch (ConfigurationException e) { errors.merge(e.getErrorMessages()); injectionPoints = e.getPartialValue(); } List<SingleMemberInjector> injectors = getInjectors(injectionPoints, errors); errors.throwIfNewErrors(numErrorsBefore); EncounterImpl<T> encounter = new EncounterImpl<>(errors, injector.lookups); for (TypeListenerBinding typeListener : typeListenerBindings) { if (typeListener.getTypeMatcher().matches(type)) { try { typeListener.getListener().hear(type, encounter); } catch (RuntimeException e) { errors.errorNotifyingTypeListener(typeListener, type, e); } } } encounter.invalidate(); errors.throwIfNewErrors(numErrorsBefore); return new MembersInjectorImpl<>(injector, type, encounter, injectors); }
/** * Returns all instance method and field injection points on {@code type}. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as * a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} * of the valid injection points. */ public static Set<InjectionPoint> forInstanceMethodsAndFields(Class<?> type) { return forInstanceMethodsAndFields(TypeLiteral.get(type)); }
/** * Returns all instance method and field injection points on {@code type}. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as * a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} * of the valid injection points. */ public static Set<InjectionPoint> forInstanceMethodsAndFields(Class<?> type) { return forInstanceMethodsAndFields(TypeLiteral.get(type)); }
/** * Returns all instance method and field injection points on {@code type}. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as * a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} * of the valid injection points. */ public static Set<InjectionPoint> forInstanceMethodsAndFields(Class<?> type) { return forInstanceMethodsAndFields(TypeLiteral.get(type)); }
@Override public BindingBuilder<T> toProvider(Provider<? extends T> provider) { Objects.requireNonNull(provider, "provider"); checkNotTargetted(); // lookup the injection points, adding any errors to the binder's errors list Set<InjectionPoint> injectionPoints; try { injectionPoints = InjectionPoint.forInstanceMethodsAndFields(provider.getClass()); } catch (ConfigurationException e) { for (Message message : e.getErrorMessages()) { binder.addError(message); } injectionPoints = unmodifiableSet(new HashSet<InjectionPoint>(e.getPartialValue())); } BindingImpl<T> base = getBinding(); setBinding(new ProviderInstanceBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), injectionPoints, provider)); return this; }
@Override public BindingBuilder<T> toProvider(Provider<? extends T> provider) { Objects.requireNonNull(provider, "provider"); checkNotTargetted(); // lookup the injection points, adding any errors to the binder's errors list Set<InjectionPoint> injectionPoints; try { injectionPoints = InjectionPoint.forInstanceMethodsAndFields(provider.getClass()); } catch (ConfigurationException e) { for (Message message : e.getErrorMessages()) { binder.addError(message); } injectionPoints = unmodifiableSet(new HashSet<InjectionPoint>(e.getPartialValue())); } BindingImpl<T> base = getBinding(); setBinding(new ProviderInstanceBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), injectionPoints, provider)); return this; }
@Override public BindingBuilder<T> toProvider(Provider<? extends T> provider) { Objects.requireNonNull(provider, "provider"); checkNotTargetted(); // lookup the injection points, adding any errors to the binder's errors list Set<InjectionPoint> injectionPoints; try { injectionPoints = InjectionPoint.forInstanceMethodsAndFields(provider.getClass()); } catch (ConfigurationException e) { for (Message message : e.getErrorMessages()) { binder.addError(message); } injectionPoints = unmodifiableSet(new HashSet<InjectionPoint>(e.getPartialValue())); } BindingImpl<T> base = getBinding(); setBinding(new ProviderInstanceBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), injectionPoints, provider)); return this; }
@Override public void toInstance(T instance) { checkNotTargetted(); // lookup the injection points, adding any errors to the binder's errors list Set<InjectionPoint> injectionPoints; if (instance != null) { try { injectionPoints = InjectionPoint.forInstanceMethodsAndFields(instance.getClass()); } catch (ConfigurationException e) { for (Message message : e.getErrorMessages()) { binder.addError(message); } injectionPoints = unmodifiableSet(new HashSet<InjectionPoint>(e.getPartialValue())); } } else { binder.addError(BINDING_TO_NULL); injectionPoints = emptySet(); } BindingImpl<T> base = getBinding(); setBinding(new InstanceBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), injectionPoints, instance)); }
@Override public void toInstance(T instance) { checkNotTargetted(); // lookup the injection points, adding any errors to the binder's errors list Set<InjectionPoint> injectionPoints; if (instance != null) { try { injectionPoints = InjectionPoint.forInstanceMethodsAndFields(instance.getClass()); } catch (ConfigurationException e) { for (Message message : e.getErrorMessages()) { binder.addError(message); } injectionPoints = unmodifiableSet(new HashSet<InjectionPoint>(e.getPartialValue())); } } else { binder.addError(BINDING_TO_NULL); injectionPoints = emptySet(); } BindingImpl<T> base = getBinding(); setBinding(new InstanceBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), injectionPoints, instance)); }
@Override public void toInstance(T instance) { checkNotTargetted(); // lookup the injection points, adding any errors to the binder's errors list Set<InjectionPoint> injectionPoints; if (instance != null) { try { injectionPoints = InjectionPoint.forInstanceMethodsAndFields(instance.getClass()); } catch (ConfigurationException e) { for (Message message : e.getErrorMessages()) { binder.addError(message); } injectionPoints = unmodifiableSet(new HashSet<InjectionPoint>(e.getPartialValue())); } } else { binder.addError(BINDING_TO_NULL); injectionPoints = emptySet(); } BindingImpl<T> base = getBinding(); setBinding(new InstanceBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), injectionPoints, instance)); }
@Override public BindingBuilder<T> toProvider(Provider<? extends T> provider) { checkNotNull(provider, "provider"); checkNotTargetted(); // lookup the injection points, adding any errors to the binder's errors list Set<InjectionPoint> injectionPoints; try { injectionPoints = InjectionPoint.forInstanceMethodsAndFields(provider.getClass()); } catch (ConfigurationException e) { for (Message message : e.getErrorMessages()) { binder.addError(message); } injectionPoints = e.getPartialValue(); } BindingImpl<T> base = getBinding(); setBinding(new ProviderInstanceBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), injectionPoints, provider)); return this; }