@Override public void inject(InternalContext context, Object o) throws InternalProvisionException { Object[] parameters = SingleParameterInjector.getAll(context, parameterInjectors); try { methodInvoker.invoke(o, parameters); } catch (IllegalAccessException e) { throw new AssertionError(e); // a security manager is blocking us, we're hosed } catch (InvocationTargetException userException) { Throwable cause = userException.getCause() != null ? userException.getCause() : userException; throw InternalProvisionException.errorInjectingMethod(cause).addSource(injectionPoint); } } }
@Override protected T provision( javax.inject.Provider<? extends T> provider, Dependency<?> dependency, ConstructionContext<T> constructionContext) throws InternalProvisionException { try { return super.provision(provider, dependency, constructionContext); } catch (RuntimeException userException) { throw InternalProvisionException.errorInProvider(userException).addSource(source); } }
@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 public T get(InternalContext context, Dependency<?> dependency, boolean linked) throws InternalProvisionException { try { T t = provider.get(); if (t == null && !dependency.isNullable()) { InternalProvisionException.onNullInjectedIntoNonNullableDependency(source, dependency); } return t; } catch (RuntimeException userException) { throw InternalProvisionException.errorInProvider(userException).addSource(source); } }
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); } }
private T provision( Dependency<?> dependency, InternalContext context, ConstructionContext<T> constructionContext) throws InternalProvisionException { try { T t = doProvision(context, dependency); constructionContext.setProxyDelegates(t); return t; } catch (InternalProvisionException ipe) { throw ipe.addSource(getSource()); } catch (Throwable t) { throw InternalProvisionException.errorInProvider(t).addSource(getSource()); } } }
@Override protected T provision( javax.inject.Provider<? extends T> provider, Dependency<?> dependency, ConstructionContext<T> constructionContext) throws InternalProvisionException { try { Object o = super.provision(provider, dependency, constructionContext); if (o != null && !rawType.isInstance(o)) { throw InternalProvisionException.subtypeNotProvided(providerType, rawType); } @SuppressWarnings("unchecked") // protected by isInstance() check above T t = (T) o; return t; } catch (RuntimeException e) { throw InternalProvisionException.errorInProvider(e).addSource(source); } } }
@Override public T get(InternalContext context, Dependency<?> dependency, boolean linked) throws InternalProvisionException { Key<? extends T> localTargetKey = targetKey; context.pushState(localTargetKey, source); try { return targetFactory.get(context, dependency, true); } catch (InternalProvisionException ipe) { throw ipe.addSource(localTargetKey); } finally { context.popState(); } }
@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(); } }
@Override public void inject(InternalContext context, Object o) throws InternalProvisionException { Dependency previous = context.pushDependency(dependency, binding.getSource()); try { Object value = binding.getInternalFactory().get(context, dependency, false); field.set(o, value); } catch (InternalProvisionException e) { throw e.addSource(dependency); } catch (IllegalAccessException e) { throw new AssertionError(e); // a security manager is blocking us, we're hosed } finally { context.popStateAndSetDependency(previous); } } }
@Override protected Optional<T> doProvision(InternalContext context, Dependency<?> currentDependency) throws InternalProvisionException { InternalFactory<? extends T> local = delegate; if (local == null) { return Optional.absent(); } Dependency<?> localDependency = targetDependency; T result; Dependency previous = context.pushDependency(localDependency, getSource()); try { // currentDependency is Optional<? super T>, so we really just need to set the target // dependency to ? super T, but we are currently setting it to T. We could hypothetically // make it easier for our delegate to generate proxies by modifying the dependency, but that // would also require us to rewrite the key on each call. So for now we don't do it. result = local.get(context, localDependency, false); } catch (InternalProvisionException ipe) { throw ipe.addSource(localDependency); } finally { context.popStateAndSetDependency(previous); } return Optional.fromNullable(result); }
instance, key, provisionCallback, source, injector.options.stage == Stage.TOOL); } catch (InternalProvisionException ipe) { throw ipe.addSource(source);
@Override protected T doProvision(InternalContext context, Dependency<?> dependency) throws InternalProvisionException { try { T t = doProvision(SingleParameterInjector.getAll(context, parameterInjectors)); if (t == null && !dependency.isNullable()) { InternalProvisionException.onNullInjectedIntoNonNullableDependency(getMethod(), dependency); } return t; } catch (IllegalAccessException e) { throw new AssertionError(e); } catch (InvocationTargetException userException) { Throwable cause = userException.getCause() != null ? userException.getCause() : userException; throw InternalProvisionException.errorInProvider(cause).addSource(getSource()); } }
@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(); } }
@Override protected Object doProvision(InternalContext context, Dependency dependency) throws InternalProvisionException { InternalFactory<?> local = target; if (local == null) { return JAVA_OPTIONAL_EMPTY; } Dependency<?> localDependency = targetDependency; Object result; Dependency previous = context.pushDependency(localDependency, getSource()); try { // See comments in RealOptionalKeyProvider, about how localDependency may be more specific // than what we actually need. result = local.get(context, localDependency, false); } catch (InternalProvisionException ipe) { throw ipe.addSource(localDependency); } finally { context.popStateAndSetDependency(previous); } return invokeJavaOptionalOfNullable(result); }
@Override public T get(InternalContext context, Dependency<?> dependency, boolean linked) throws InternalProvisionException { BindingImpl<? extends Provider<T>> localProviderBinding = providerBinding; if (localProviderBinding == null) { throw new IllegalStateException("not initialized"); } Key<? extends Provider<T>> localProviderKey = providerKey; context.pushState(localProviderKey, localProviderBinding.getSource()); try { Provider<? extends T> provider = localProviderBinding.getInternalFactory().get(context, dependency, true); return circularGet(provider, context, dependency, provisionCallback); } catch (InternalProvisionException ipe) { throw ipe.addSource(localProviderKey); } finally { context.popState(); } }
@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(); } }
/** Provisions a new T. */ private T provision(InternalContext context, ConstructionContext<T> constructionContext) throws InternalProvisionException { try { T t; try { Object[] parameters = SingleParameterInjector.getAll(context, parameterInjectors); t = constructionProxy.newInstance(parameters); constructionContext.setProxyDelegates(t); } finally { constructionContext.finishConstruction(); } // Store reference. If an injector re-enters this factory, they'll get the same reference. constructionContext.setCurrentReference(t); MembersInjectorImpl<T> localMembersInjector = membersInjector; localMembersInjector.injectMembers(t, context, false); localMembersInjector.notifyListeners(t); return t; } catch (InvocationTargetException userException) { Throwable cause = userException.getCause() != null ? userException.getCause() : userException; throw InternalProvisionException.errorInjectingConstructor(cause) .addSource(constructionProxy.getInjectionPoint()); } finally { constructionContext.removeCurrentReference(); } } }
.addSource(source);
@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(); } }