public V get(K key, Errors errors) throws ErrorsException { Object resultOrError = delegate.getUnchecked(key); if (resultOrError instanceof Errors) { errors.merge((Errors) resultOrError); throw errors.toException(); } else { @SuppressWarnings("unchecked") // create returned a non-error result, so this is safe V result = (V) resultOrError; return result; } }
public void throwIfNewErrors(int expectedSize) throws ErrorsException { if (size() == expectedSize) { return; } throw toException(); }
private static <T> Key<T> getProvidedKey(Key<Provider<T>> key, Errors errors) throws ErrorsException { Type providerType = key.getTypeLiteral().getType(); // If the Provider has no type parameter (raw Provider)... if (!(providerType instanceof ParameterizedType)) { throw errors.cannotInjectRawProvider().toException(); } Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; @SuppressWarnings("unchecked") // safe because T came from Key<Provider<T>> Key<T> providedKey = (Key<T>) key.ofType(entryType); return providedKey; }
Type typeLiteralType = key.getTypeLiteral().getType(); if (!(typeLiteralType instanceof ParameterizedType)) { throw errors.cannotInjectRawTypeLiteral().toException(); && !(innerType instanceof GenericArrayType) && !(innerType instanceof ParameterizedType)) { throw errors.cannotInjectTypeLiteralOf(innerType).toException();
/** Creates a binding for a type annotated with @ImplementedBy. */ private <T> BindingImpl<T> createImplementedByBinding( Key<T> key, Scoping scoping, ImplementedBy implementedBy, Errors errors) throws ErrorsException { Class<?> rawType = key.getTypeLiteral().getRawType(); Class<?> implementationType = implementedBy.value(); // Make sure it's not the same type. TODO: Can we check for deeper cycles? if (implementationType == rawType) { throw errors.recursiveImplementationType().toException(); } // Make sure implementationType extends type. if (!rawType.isAssignableFrom(implementationType)) { throw errors.notASubtype(implementationType, rawType).toException(); } @SuppressWarnings("unchecked") // After the preceding check, this cast is safe. Class<? extends T> subclass = (Class<? extends T>) implementationType; // Look up the target binding. final Key<? extends T> targetKey = Key.get(subclass); Object source = rawType; FactoryProxy<T> factory = new FactoryProxy<>(this, key, targetKey, source); factory.notify(errors); // causes the factory to initialize itself internally return new LinkedBindingImpl<T>( this, key, source, Scoping.<T>scope(key, this, factory, source, scoping), scoping, targetKey); }
private <T> BindingImpl<MembersInjector<T>> createMembersInjectorBinding( Key<MembersInjector<T>> key, Errors errors) throws ErrorsException { Type membersInjectorType = key.getTypeLiteral().getType(); if (!(membersInjectorType instanceof ParameterizedType)) { throw errors.cannotInjectRawMembersInjector().toException(); } @SuppressWarnings("unchecked") // safe because T came from Key<MembersInjector<T>> TypeLiteral<T> instanceType = (TypeLiteral<T>) TypeLiteral.get(((ParameterizedType) membersInjectorType).getActualTypeArguments()[0]); MembersInjector<T> membersInjector = membersInjectorStore.get(instanceType, errors); InternalFactory<MembersInjector<T>> factory = new ConstantFactory<MembersInjector<T>>(Initializables.of(membersInjector)); return new InstanceBindingImpl<MembersInjector<T>>( this, key, SourceProvider.UNKNOWN_SOURCE, factory, ImmutableSet.<InjectionPoint>of(), membersInjector); }
&& !jitOverride && !(binding instanceof ConvertedConstantBindingImpl)) { throw errors.jitDisabled(key).toException(); } else { return binding; throw errors.toException();
throw errors.missingImplementationWithHint(key, this).toException();
throw errors .converterReturnedNull(stringValue, source, type, typeConverterBinding) .toException(); throw errors .conversionTypeError(stringValue, source, type, typeConverterBinding, converted) .toException(); throw errors .conversionError(stringValue, source, type, typeConverterBinding, e) .toException();
/** Creates a binding for a type annotated with @ProvidedBy. */ <T> BindingImpl<T> createProvidedByBinding( Key<T> key, Scoping scoping, ProvidedBy providedBy, Errors errors) throws ErrorsException { Class<?> rawType = key.getTypeLiteral().getRawType(); Class<? extends javax.inject.Provider<?>> providerType = providedBy.value(); // Make sure it's not the same type. TODO: Can we check for deeper loops? if (providerType == rawType) { throw errors.recursiveProviderType().toException(); } // Assume the provider provides an appropriate type. We double check at runtime. @SuppressWarnings("unchecked") Key<? extends Provider<T>> providerKey = (Key<? extends Provider<T>>) Key.get(providerType); ProvidedByInternalFactory<T> internalFactory = new ProvidedByInternalFactory<T>(rawType, providerType, providerKey); Object source = rawType; BindingImpl<T> binding = LinkedProviderBindingImpl.createWithInitializer( this, key, source, Scoping.<T>scope(key, this, internalFactory, source, scoping), scoping, providerKey, internalFactory); internalFactory.setProvisionListenerCallback(provisionListenerStore.get(binding)); return binding; }
&& !parent.options.jitDisabled) { throw errors.jitDisabledInParent(key).toException(); throw errors.childBindingAlreadySet(key, sources).toException();
throw errors.childBindingAlreadySet(key, sources).toException(); throw errors.jitDisabled(key).toException(); throw errors.missingImplementationWithHint(key, this).toException();
throw errors.merge(e.getErrorMessages()).toException();
@Override public ConstructionProxy<T> create() throws ErrorsException { if (interceptors.isEmpty()) { return new DefaultConstructionProxyFactory<T>(injectionPoint).create(); } @SuppressWarnings("unchecked") Class<? extends Callback>[] callbackTypes = new Class[callbacks.length]; for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] == net.sf.cglib.proxy.NoOp.INSTANCE) { callbackTypes[i] = net.sf.cglib.proxy.NoOp.class; } else { callbackTypes[i] = net.sf.cglib.proxy.MethodInterceptor.class; } } // Create the proxied class. We're careful to ensure that all enhancer state is not-specific // to this injector. Otherwise, the proxies for each injector will waste PermGen memory try { Enhancer enhancer = BytecodeGen.newEnhancer(declaringClass, visibility); enhancer.setCallbackFilter(new IndicesCallbackFilter(methods)); enhancer.setCallbackTypes(callbackTypes); return new ProxyConstructor<T>(enhancer, injectionPoint, callbacks, interceptors); } catch (Throwable e) { throw new Errors().errorEnhancingClass(declaringClass, e).toException(); } }
public V get(K key, Errors errors) throws ErrorsException { Object resultOrError = delegate.getUnchecked(key); if (resultOrError instanceof Errors) { errors.merge((Errors) resultOrError); throw errors.toException(); } else { @SuppressWarnings("unchecked") // create returned a non-error result, so this is safe V result = (V) resultOrError; return result; } }
public V get(K key, Errors errors) throws ErrorsException { Object resultOrError = delegate.getUnchecked(key); if (resultOrError instanceof Errors) { errors.merge((Errors) resultOrError); throw errors.toException(); } else { @SuppressWarnings("unchecked") // create returned a non-error result, so this is safe V result = (V) resultOrError; return result; } }
public T get(Errors errors, InternalContext context, Dependency<?> dependency, boolean linked) throws ErrorsException { errors = errors.withSource(providerKey); javax.inject.Provider<? extends T> provider = providerFactory.get(errors, context, dependency, true); try { return errors.checkForNull(provider.get(), source, dependency); } catch(RuntimeException userException) { throw errors.errorInProvider(userException).toException(); } }
public T get(Errors errors, InternalContext context, Dependency<?> dependency, boolean linked) throws ErrorsException { errors = errors.withSource(providerKey); javax.inject.Provider<? extends T> provider = providerFactory.get(errors, context, dependency, true); try { return errors.checkForNull(provider.get(), source, dependency); } catch(RuntimeException userException) { throw errors.errorInProvider(userException).toException(); } }
private static <T> Key<T> getProvidedKey(Key<Provider<T>> key, Errors errors) throws ErrorsException { Type providerType = key.getTypeLiteral().getType(); // If the Provider has no type parameter (raw Provider)... if (!(providerType instanceof ParameterizedType)) { throw errors.cannotInjectRawProvider().toException(); } Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; @SuppressWarnings("unchecked") // safe because T came from Key<Provider<T>> Key<T> providedKey = (Key<T>) key.ofType(entryType); return providedKey; }
private static <T> Key<T> getProvidedKey(Key<Provider<T>> key, Errors errors) throws ErrorsException { Type providerType = key.getTypeLiteral().getType(); // If the Provider has no type parameter (raw Provider)... if (!(providerType instanceof ParameterizedType)) { throw errors.cannotInjectRawProvider().toException(); } Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; @SuppressWarnings("unchecked") // safe because T came from Key<Provider<T>> Key<T> providedKey = (Key<T>) key.ofType(entryType); return providedKey; }