@Override public BindingBuilder<T> toProvider(Key<? extends Provider<? extends T>> providerKey) { Objects.requireNonNull(providerKey, "providerKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedProviderBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), providerKey)); return this; }
@Override public BindingBuilder<T> to(Key<? extends T> linkedKey) { Objects.requireNonNull(linkedKey, "linkedKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), linkedKey)); 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 notify(Errors errors) { InjectorImpl privateInjector = (InjectorImpl) privateElements.getInjector(); BindingImpl<T> explicitBinding = privateInjector.state.getExplicitBinding(key); // validate that the child injector has its own factory. If the getInternalFactory() returns // this, then that child injector doesn't have a factory (and getExplicitBinding has returned // its parent's binding instead if (explicitBinding.getInternalFactory() == this) { errors.withSource(explicitBinding.getSource()).exposedButNotBound(key); return; } this.delegate = explicitBinding; }
@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)); }
private void toConstant(Class<?> type, Object instance) { // this type will define T, so these assignments are safe @SuppressWarnings("unchecked") Class<T> typeAsClassT = (Class<T>) type; @SuppressWarnings("unchecked") T instanceAsT = (T) instance; if (keyTypeIsSet()) { binder.addError(CONSTANT_VALUE_ALREADY_SET); return; } BindingImpl<T> base = getBinding(); Key<T> key; if (base.getKey().getAnnotation() != null) { key = Key.get(typeAsClassT, base.getKey().getAnnotation()); } else if (base.getKey().getAnnotationType() != null) { key = Key.get(typeAsClassT, base.getKey().getAnnotationType()); } else { key = Key.get(typeAsClassT); } if (instanceAsT == null) { binder.addError(BINDING_TO_NULL); } setBinding(new InstanceBindingImpl<>( base.getSource(), key, base.getScoping(), emptySet(), instanceAsT)); }
Object source = stringBinding.getSource();
@Override public BindingBuilder<T> to(Key<? extends T> linkedKey) { Objects.requireNonNull(linkedKey, "linkedKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), linkedKey)); return this; }
@Override public BindingBuilder<T> toProvider(Key<? extends Provider<? extends T>> providerKey) { Objects.requireNonNull(providerKey, "providerKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedProviderBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), providerKey)); return this; }
@Override public BindingBuilder<T> to(Key<? extends T> linkedKey) { Objects.requireNonNull(linkedKey, "linkedKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), linkedKey)); return this; }
@Override public BindingBuilder<T> to(Key<? extends T> linkedKey) { Objects.requireNonNull(linkedKey, "linkedKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), linkedKey)); return this; }
@Override public BindingBuilder<T> toProvider(Key<? extends Provider<? extends T>> providerKey) { Objects.requireNonNull(providerKey, "providerKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedProviderBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), providerKey)); return this; }
@Override public BindingBuilder<T> toProvider(Key<? extends Provider<? extends T>> providerKey) { Objects.requireNonNull(providerKey, "providerKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedProviderBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), providerKey)); 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 notify(Errors errors) { InjectorImpl privateInjector = (InjectorImpl) privateElements.getInjector(); BindingImpl<T> explicitBinding = privateInjector.state.getExplicitBinding(key); // validate that the child injector has its own factory. If the getInternalFactory() returns // this, then that child injector doesn't have a factory (and getExplicitBinding has returned // its parent's binding instead if (explicitBinding.getInternalFactory() == this) { errors.withSource(explicitBinding.getSource()).exposedButNotBound(key); return; } this.delegate = explicitBinding; }
@Override public void notify(Errors errors) { InjectorImpl privateInjector = (InjectorImpl) privateElements.getInjector(); BindingImpl<T> explicitBinding = privateInjector.state.getExplicitBinding(key); // validate that the child injector has its own factory. If the getInternalFactory() returns // this, then that child injector doesn't have a factory (and getExplicitBinding has returned // its parent's binding instead if (explicitBinding.getInternalFactory() == this) { errors.withSource(explicitBinding.getSource()).exposedButNotBound(key); return; } this.delegate = explicitBinding; }
@Override public void notify(Errors errors) { InjectorImpl privateInjector = (InjectorImpl) privateElements.getInjector(); BindingImpl<T> explicitBinding = privateInjector.state.getExplicitBinding(key); // validate that the child injector has its own factory. If the getInternalFactory() returns // this, then that child injector doesn't have a factory (and getExplicitBinding has returned // its parent's binding instead if (explicitBinding.getInternalFactory() == this) { errors.withSource(explicitBinding.getSource()).exposedButNotBound(key); return; } this.delegate = explicitBinding; }
@Override public void notify(Errors errors) { InjectorImpl privateInjector = (InjectorImpl) privateElements.getInjector(); BindingImpl<T> explicitBinding = privateInjector.state.getExplicitBinding(key); // validate that the child injector has its own factory. If the getInternalFactory() returns // this, then that child injector doesn't have a factory (and getExplicitBinding has returned // its parent's binding instead if (explicitBinding.getInternalFactory() == this) { errors.withSource(explicitBinding.getSource()).exposedButNotBound(key); return; } this.delegate = explicitBinding; }
@Override public BindingBuilder<T> to(Key<? extends T> linkedKey) { checkNotNull(linkedKey, "linkedKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), linkedKey)); return this; }
@Override public BindingBuilder<T> toProvider(Key<? extends Provider<? extends T>> providerKey) { checkNotNull(providerKey, "providerKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedProviderBindingImpl<>( base.getSource(), base.getKey(), base.getScoping(), providerKey)); return this; }