Processor(BindingImpl<T> binding) { source = binding.getSource(); key = binding.getKey(); rawType = key.getTypeLiteral().getRawType(); scoping = binding.getScoping(); }
/** * We tolerate duplicate bindings if one exposes the other or if the two bindings are considered * duplicates (see {@link Bindings#areDuplicates(BindingImpl, BindingImpl)}. * * @param original the binding in the parent injector (candidate for an exposing binding) * @param binding the binding to check (candidate for the exposed binding) */ private boolean isOkayDuplicate(BindingImpl<?> original, BindingImpl<?> binding, State state) { if (original instanceof ExposedBindingImpl) { ExposedBindingImpl exposed = (ExposedBindingImpl) original; InjectorImpl exposedFrom = (InjectorImpl) exposed.getPrivateElements().getInjector(); return (exposedFrom == binding.getInjector()); } else { original = (BindingImpl<?>) state.getExplicitBindingsThisLevel().get(binding.getKey()); // If no original at this level, the original was on a parent, and we don't // allow deduplication between parents & children. if (original == null) { return false; } else { return original.equals(binding); } } }
@Override void doInitialize() { BindingImpl<T> targetBinding = bindingSelection.getBinding(); // we only install this factory if they call setBinding()/setDefault() so we know that // targetBinding will be non-null. this.targetKey = targetBinding.getKey(); this.targetSource = targetBinding.getSource(); this.targetFactory = targetBinding.getInternalFactory(); }
SingleParameterInjector(Dependency<T> dependency, BindingImpl<? extends T> binding) { this.dependency = dependency; this.source = binding.getSource(); this.factory = binding.getInternalFactory(); }
/** Sets the binding to a copy with the specified annotation on the bound key */ protected BindingImpl<T> annotatedWithInternal(Annotation annotation) { checkNotNull(annotation, "annotation"); checkNotAnnotated(); return setBinding(binding.withKey(Key.get(this.binding.getKey().getTypeLiteral(), annotation))); }
if (stringBinding == null || !stringBinding.isConstant()) { return null; String stringValue = stringBinding.getProvider().get(); Object source = stringBinding.getSource();
public void in(final Class<? extends Annotation> scopeAnnotation) { checkNotNull(scopeAnnotation, "scopeAnnotation"); checkNotScoped(); setBinding(getBinding().withScoping(Scoping.forAnnotation(scopeAnnotation))); }
if (stringBinding == null || !stringBinding.isConstant()) { return null; Object source = stringBinding.getSource();
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 void run() { try { binding.getInjector().initializeBinding(binding, errors.withSource(source)); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } };
protected void putBinding(BindingImpl<?> binding) { Key<?> key = binding.getKey(); try { if (!isOkayDuplicate(original, binding, injector.state)) { errors.bindingAlreadySet(key, original.getSource()); return; errors.errorCheckingDuplicateBinding(key, original.getSource(), t); return; injector.state.parent().blacklist(key, injector.state, binding.getSource()); injector.state.putBinding(key, binding);
@Override public T get(InternalContext context, Dependency<?> dependency, boolean linked) throws InternalProvisionException { // TODO(lukes): add a source to the thrown exception? return delegate.getInternalFactory().get(context, dependency, linked); } }
@Override void doInitialize() { if (bindingSelection.getBinding() == null) { value = Optional.absent(); } else { value = Optional.of(bindingSelection.getBinding().getProvider()); } }
@Override public Key<? extends T> getProvidedKey() { return providedBinding.getKey(); }
state.parent().blacklist(key, state, binding.getSource()); jitBindings.put(key, binding); return binding;
/** Sets the binding to a copy with the specified annotation on the bound key */ protected BindingImpl<T> annotatedWithInternal(Class<? extends Annotation> annotationType) { checkNotNull(annotationType, "annotationType"); checkNotAnnotated(); return setBinding( binding.withKey(Key.get(this.binding.getKey().getTypeLiteral(), annotationType))); }
if (stringBinding == null || !stringBinding.isConstant()) { return null; String stringValue = stringBinding.getProvider().get(); Object source = stringBinding.getSource();
<T> Provider<T> getProviderOrThrow(final Dependency<T> dependency, Errors errors) throws ErrorsException { Key<T> key = dependency.getKey(); BindingImpl<? extends T> binding = getBindingOrThrow(key, errors, JitLimitation.NO_JIT); final InternalFactory<? extends T> internalFactory = binding.getInternalFactory(); final Object source = binding.getSource(); return new Provider<T>() { @Override public T get() { InternalContext currentContext = enterContext(); Dependency previous = currentContext.pushDependency(dependency, source); try { T t = internalFactory.get(currentContext, dependency, false); return t; } catch (InternalProvisionException e) { throw e.addSource(dependency).toProvisionException(); } finally { currentContext.popStateAndSetDependency(previous); currentContext.close(); } } @Override public String toString() { return internalFactory.toString(); } }; }
public void in(final Scope scope) { checkNotNull(scope, "scope"); checkNotScoped(); setBinding(getBinding().withScoping(Scoping.forInstance(scope))); }
if (stringBinding == null || !stringBinding.isConstant()) { return null; Object source = stringBinding.getSource();