Processor(BindingImpl<T> binding) { source = binding.getSource(); key = binding.getKey(); rawType = key.getTypeLiteral().getRawType(); scoping = binding.getScoping(); }
protected void checkNotScoped() { // Scoping isn't allowed when we have only one instance. if (binding instanceof InstanceBinding) { binder.addError(SINGLE_INSTANCE_AND_SCOPE); return; } if (binding.getScoping().isExplicitlyScoped()) { binder.addError(SCOPE_ALREADY_SET); } } }
@Override public BindingBuilder<T> to(Key<? extends T> linkedKey) { checkNotNull(linkedKey, "linkedKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding( new LinkedBindingImpl<T>(base.getSource(), base.getKey(), base.getScoping(), linkedKey)); return this; }
private boolean isEagerSingleton(InjectorImpl injector, BindingImpl<?> binding, Stage stage) { if (binding.getScoping().isEagerSingleton(stage)) { return true; } // handle a corner case where a child injector links to a binding in a parent injector, and // that binding is singleton. We won't catch this otherwise because we only iterate the child's // bindings. if (binding instanceof LinkedBindingImpl) { Key<?> linkedBinding = ((LinkedBindingImpl<?>) binding).getLinkedKey(); return isEagerSingleton(injector, injector.getBinding(linkedBinding), stage); } return false; }
@Override public BindingBuilder<T> toProvider( Key<? extends javax.inject.Provider<? extends T>> providerKey) { checkNotNull(providerKey, "providerKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding( new LinkedProviderBindingImpl<T>( base.getSource(), base.getKey(), base.getScoping(), providerKey)); return this; }
@Override public BindingBuilder<T> toProvider(javax.inject.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) { copyErrorsToBinder(e); injectionPoints = e.getPartialValue(); } BindingImpl<T> base = getBinding(); setBinding( new ProviderInstanceBindingImpl<T>( base.getSource(), base.getKey(), base.getScoping(), injectionPoints, provider)); return this; }
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<T>( base.getSource(), key, base.getScoping(), ImmutableSet.<InjectionPoint>of(), instanceAsT)); }
@Override public <S extends T> ScopedBindingBuilder toConstructor( Constructor<S> constructor, TypeLiteral<? extends S> type) { checkNotNull(constructor, "constructor"); checkNotNull(type, "type"); checkNotTargetted(); BindingImpl<T> base = getBinding(); Set<InjectionPoint> injectionPoints; try { injectionPoints = InjectionPoint.forInstanceMethodsAndFields(type); } catch (ConfigurationException e) { copyErrorsToBinder(e); injectionPoints = e.getPartialValue(); } try { InjectionPoint constructorPoint = InjectionPoint.forConstructor(constructor, type); setBinding( new ConstructorBindingImpl<T>( base.getKey(), base.getSource(), base.getScoping(), constructorPoint, injectionPoints)); } catch (ConfigurationException e) { copyErrorsToBinder(e); } return this; }
public void releaseContext(GuiceBean bean, Object context) { Scoping scoping = ((BindingImpl)bean.binding).getScoping(); if (scoping.isNoScope()) { invokePreDestroy(context); } }
Processor(BindingImpl<T> binding) { source = binding.getSource(); key = binding.getKey(); rawType = key.getTypeLiteral().getRawType(); scoping = binding.getScoping(); }
Processor(BindingImpl<T> binding) { source = binding.getSource(); key = binding.getKey(); rawType = key.getTypeLiteral().getRawType(); scoping = binding.getScoping(); }
protected void checkNotScoped() { // Scoping isn't allowed when we have only one instance. if (binding instanceof InstanceBinding) { binder.addError(SINGLE_INSTANCE_AND_SCOPE); return; } if (binding.getScoping().isExplicitlyScoped()) { binder.addError(SCOPE_ALREADY_SET); } } }
protected void checkNotScoped() { // Scoping isn't allowed when we have only one instance. if (binding instanceof InstanceBinding) { binder.addError(SINGLE_INSTANCE_AND_SCOPE); return; } if (binding.getScoping().isExplicitlyScoped()) { binder.addError(SCOPE_ALREADY_SET); } } }
protected void checkNotScoped() { // Scoping isn't allowed when we have only one instance. if (binding instanceof InstanceBinding) { binder.addError(SINGLE_INSTANCE_AND_SCOPE); return; } if (binding.getScoping().isExplicitlyScoped()) { binder.addError(SCOPE_ALREADY_SET); } } }
@Override public BindingBuilder<T> to(Key<? extends T> linkedKey) { checkNotNull(linkedKey, "linkedKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding( new LinkedBindingImpl<T>(base.getSource(), base.getKey(), base.getScoping(), linkedKey)); return this; }
public BindingBuilder<T> to(Key<? extends T> linkedKey) { checkNotNull(linkedKey, "linkedKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedBindingImpl<T>( base.getSource(), base.getKey(), base.getScoping(), linkedKey)); return this; }
public BindingBuilder<T> toProvider( Key<? extends javax.inject.Provider<? extends T>> providerKey) { checkNotNull(providerKey, "providerKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedProviderBindingImpl<T>( base.getSource(), base.getKey(), base.getScoping(), providerKey)); return this; }
public BindingBuilder<T> toProvider( Key<? extends javax.inject.Provider<? extends T>> providerKey) { checkNotNull(providerKey, "providerKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedProviderBindingImpl<T>( base.getSource(), base.getKey(), base.getScoping(), providerKey)); return this; }
public BindingBuilder<T> to(Key<? extends T> linkedKey) { checkNotNull(linkedKey, "linkedKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedBindingImpl<T>( base.getSource(), base.getKey(), base.getScoping(), linkedKey)); return this; }
public BindingBuilder<T> toProvider( Key<? extends javax.inject.Provider<? extends T>> providerKey) { checkNotNull(providerKey, "providerKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding(new LinkedProviderBindingImpl<T>( base.getSource(), base.getKey(), base.getScoping(), providerKey)); return this; }