@Override public void run() { try { binding.getInjector().initializeBinding(binding, errors.withSource(source)); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } };
@Override public void notify(Errors errors) { try { providerFactory = injector.getInternalFactory( providerKey, errors.withSource(source), JitLimitation.NEW_OR_EXISTING_JIT); } catch (ErrorsException e) { errors.merge(e.getErrors()); } }
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; }
private <T> void bindExposed(PrivateElements privateElements, Key<T> key) { ExposedKeyFactory<T> exposedKeyFactory = new ExposedKeyFactory<>(key, privateElements); bindingData.addCreationListener(exposedKeyFactory); putBinding( new ExposedBindingImpl<T>( injector, privateElements.getExposedSource(key), key, exposedKeyFactory, privateElements)); } }
@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(); }
@Override protected T doProvision(InternalContext context, Dependency<?> dependency) throws InternalProvisionException { // This is what linked bindings do (see FactoryProxy), and we are pretty similar. context.pushState(targetKey, targetSource); try { return targetFactory.get(context, dependency, true); } catch (InternalProvisionException ipe) { throw ipe.addSource(targetKey); } finally { context.popState(); } }
/** * Creates a synthetic binding to {@code Provider<T>}, i.e. a binding to the provider from {@code * Binding<T>}. */ private <T> BindingImpl<Provider<T>> createProviderBinding(Key<Provider<T>> key, Errors errors) throws ErrorsException { Key<T> providedKey = getProvidedKey(key, errors); BindingImpl<T> delegate = getBindingOrThrow(providedKey, errors, JitLimitation.NO_JIT); return new ProviderBindingImpl<T>(this, key, delegate); }
T inject(InternalContext context) throws InternalProvisionException { Dependency<T> localDependency = dependency; Dependency previous = context.pushDependency(localDependency, source); try { return factory.get(context, localDependency, false); } catch (InternalProvisionException ipe) { throw ipe.addSource(localDependency); } finally { context.popStateAndSetDependency(previous); } }
/** Returns an injection point that can be used to clean up the constructor store. */ InjectionPoint getInternalConstructor() { if (factory.constructorInjector != null) { return factory.constructorInjector.getConstructionProxy().getInjectionPoint(); } else { return constructorInjectionPoint; } }
@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 public void initialize(final InjectorImpl injector, final Errors errors) throws ErrorsException { originalFactory.source = getSource(); originalFactory.provisionCallback = injector.provisionListenerStore.get(this); // For these kinds of providers, the 'user supplied provider' is really 'guice supplied' // So make our user supplied provider just delegate to the guice supplied one. originalFactory.delegateProvider = getProvider(); originalFactory.initialize(injector, errors); }
@Override public void injectMembers(T instance) { TypeLiteral<T> localTypeLiteral = typeLiteral; try { injectAndNotify(instance, null, null, localTypeLiteral, false); } catch (InternalProvisionException ipe) { throw ipe.addSource(localTypeLiteral).toProvisionException(); } }
@Override void doInitialize() { if (bindingSelection.getBinding() != null) { target = bindingSelection.getBinding().getInternalFactory(); targetDependency = bindingSelection.getDependency(); } }
/** * Schedule initialization of this binding to occur immediately after all bindings have been * initialially processed. */ protected void scheduleInitialization(BindingImpl<?> binding) { bindingData.addUninitializedBinding(asRunnable(binding)); }
/** * Returns the key to use for the default binding. * * <p>As a side effect this installs support for the 'direct type', so a binding for {@code T} * will be made available. */ Key<T> getKeyForDefaultBinding() { bindingSelection.checkNotInitialized(); addDirectTypeBinding(binder); return bindingSelection.getKeyForDefaultBinding(); }
/** * Returns the key to use for the actual binding, overrides the default if set. * * <p>As a side effect this installs support for the 'direct type', so a binding for {@code T} * will be made available. */ Key<T> getKeyForActualBinding() { bindingSelection.checkNotInitialized(); addDirectTypeBinding(binder); return bindingSelection.getKeyForActualBinding(); }
@Override public void notify(final Errors errors) { try { targetFactory = injector.getInternalFactory( targetKey, errors.withSource(source), JitLimitation.NEW_OR_EXISTING_JIT); } catch (ErrorsException e) { errors.merge(e.getErrors()); } }
@Override public T get(InternalContext context, Dependency<?> dependency, boolean linked) throws InternalProvisionException { context.pushState(providerKey, source); try { javax.inject.Provider<? extends T> provider = providerFactory.get(context, dependency, true); return circularGet(provider, context, dependency, provisionCallback); } catch (InternalProvisionException ipe) { throw ipe.addSource(providerKey); } finally { context.popState(); } }