InjectorImpl injector = new InjectorImpl(state, initializer); if (privateElements != null) { privateElements.initInjector(injector);
void injectMembers() { try { injector.callInContext(new ContextualCallable<Void>() { @Override public Void call(InternalContext context) { for (SingleMemberInjector injector : memberInjectors) { injector.inject(errors, context, null); } return null; } }); } catch (ErrorsException e) { throw new AssertionError(); } } }
public Injector createInjector() { Injector injector = Guice.createInjector(modules); ((InjectorImpl) injector).clearCache(); // in ES, we always create all instances as if they are eager singletons // this allows for considerable memory savings (no need to store construction info) as well as cycles ((InjectorImpl) injector).readOnlyAllSingletons(); return injector; } }
if (isProvider(key)) { BindingImpl binding = createProviderBinding((Key) key, errors); return binding; if (isMembersInjector(key)) { BindingImpl binding = createMembersInjectorBinding((Key) key, errors); return binding; BindingImpl<T> convertedBinding = convertConstantStringBinding(key, errors); if (convertedBinding != null) { return convertedBinding; try { Errors ignored = new Errors(); return getBindingOrThrow(key.withoutAttributes(), ignored); } catch (ErrorsException ignored) { BindingImpl<T> binding = createUnitializedBinding(key, Scoping.UNSCOPED, source, errors); initializeBinding(binding, errors); return binding;
BindingImpl<T> binding = (BindingImpl<T>) createTypeLiteralBinding( (Key<TypeLiteral<Object>>) key, errors); return binding; if (implementedBy != null) { Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors); return createImplementedByBinding(key, scoping, implementedBy, errors); if (providedBy != null) { Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors); return createProvidedByBinding(key, scoping, providedBy, errors);
/** * Attempts to create a just-in-time binding for {@code key} in the root injector, falling back to * other ancestor injectors until this injector is tried. */ private <T> BindingImpl<T> createJustInTimeBindingRecursive(Key<T> key, Errors errors) throws ErrorsException { // ask the parent to create the JIT binding if (parent != null && !parent.readOnly /* ES: don't check on parent if its read only, its already created all the bindings it can*/) { try { return parent.createJustInTimeBindingRecursive(key, new Errors()); } catch (ErrorsException ignored) { } } if (state.isBlacklisted(key)) { throw errors.childBindingAlreadySet(key).toException(); } BindingImpl<T> binding = createJustInTimeBinding(key, errors); state.parent().blacklist(key); jitBindings.put(key, binding); return binding; }
/** * Returns a just-in-time binding for {@code key}, creating it if necessary. * * @throws ErrorsException if the binding could not be created. */ private <T> BindingImpl<T> getJustInTimeBinding(Key<T> key, Errors errors) throws ErrorsException { synchronized (state.lock()) { // first try to find a JIT binding that we've already created @SuppressWarnings("unchecked") // we only store bindings that match their key BindingImpl<T> binding = (BindingImpl<T>) jitBindings.get(key); if (binding != null) { return binding; } return createJustInTimeBindingRecursive(key, errors); } }
/** * Returns parameter injectors, or {@code null} if there are no parameters. */ SingleParameterInjector<?>[] getParametersInjectors( List<Dependency<?>> parameters, Errors errors) throws ErrorsException { if (parameters.isEmpty()) { return null; } int numErrorsBefore = errors.size(); SingleParameterInjector<?>[] result = new SingleParameterInjector<?>[parameters.size()]; int i = 0; for (Dependency<?> parameter : parameters) { try { result[i++] = createParameterInjector(parameter, errors.withSource(parameter)); } catch (ErrorsException rethrownBelow) { // rethrown below } } errors.throwIfNewErrors(numErrorsBefore); return result; }
/** * Attempts to create a just-in-time binding for {@code key} in the root injector, falling back to * other ancestor injectors until this injector is tried. */ private <T> BindingImpl<T> createJustInTimeBindingRecursive(Key<T> key, Errors errors) throws ErrorsException { if (state.isBlacklisted(key)) { throw errors.childBindingAlreadySet(key).toException(); } BindingImpl<T> binding = createJustInTimeBinding(key, errors); state.parent().blacklist(key); jitBindings.put(key, binding); return binding; }
public static void cleanCaches(Injector injector) { ((InjectorImpl) injector).clearCache(); if (injector.getParent() != null) { cleanCaches(injector.getParent()); } } }
if (isProvider(key)) { BindingImpl binding = createProviderBinding((Key) key, errors); return binding; if (isMembersInjector(key)) { BindingImpl binding = createMembersInjectorBinding((Key) key, errors); return binding; BindingImpl<T> convertedBinding = convertConstantStringBinding(key, errors); if (convertedBinding != null) { return convertedBinding; try { Errors ignored = new Errors(); return getBindingOrThrow(key.withoutAttributes(), ignored); } catch (ErrorsException ignored) { BindingImpl<T> binding = createUnitializedBinding(key, Scoping.UNSCOPED, source, errors); initializeBinding(binding, errors); return binding;
BindingImpl<T> binding = (BindingImpl<T>) createTypeLiteralBinding( (Key<TypeLiteral<Object>>) key, errors); return binding; if (implementedBy != null) { Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors); return createImplementedByBinding(key, scoping, implementedBy, errors); if (providedBy != null) { Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors); return createProvidedByBinding(key, scoping, providedBy, errors);
/** * Returns a just-in-time binding for {@code key}, creating it if necessary. * * @throws ErrorsException if the binding could not be created. */ private <T> BindingImpl<T> getJustInTimeBinding(Key<T> key, Errors errors) throws ErrorsException { synchronized (state.lock()) { // first try to find a JIT binding that we've already created @SuppressWarnings("unchecked") // we only store bindings that match their key BindingImpl<T> binding = (BindingImpl<T>) jitBindings.get(key); if (binding != null) { return binding; } return createJustInTimeBindingRecursive(key, errors); } }
/** * Returns parameter injectors, or {@code null} if there are no parameters. */ SingleParameterInjector<?>[] getParametersInjectors( List<Dependency<?>> parameters, Errors errors) throws ErrorsException { if (parameters.isEmpty()) { return null; } int numErrorsBefore = errors.size(); SingleParameterInjector<?>[] result = new SingleParameterInjector<?>[parameters.size()]; int i = 0; for (Dependency<?> parameter : parameters) { try { result[i++] = createParameterInjector(parameter, errors.withSource(parameter)); } catch (ErrorsException rethrownBelow) { // rethrown below } } errors.throwIfNewErrors(numErrorsBefore); return result; }
/** * Attempts to create a just-in-time binding for {@code key} in the root injector, falling back to * other ancestor injectors until this injector is tried. */ private <T> BindingImpl<T> createJustInTimeBindingRecursive(Key<T> key, Errors errors) throws ErrorsException { if (state.isBlacklisted(key)) { throw errors.childBindingAlreadySet(key).toException(); } BindingImpl<T> binding = createJustInTimeBinding(key, errors); state.parent().blacklist(key); jitBindings.put(key, binding); return binding; }
if (isProvider(key)) { BindingImpl binding = createProviderBinding((Key) key, errors); return binding; if (isMembersInjector(key)) { BindingImpl binding = createMembersInjectorBinding((Key) key, errors); return binding; BindingImpl<T> convertedBinding = convertConstantStringBinding(key, errors); if (convertedBinding != null) { return convertedBinding; try { Errors ignored = new Errors(); return getBindingOrThrow(key.withoutAttributes(), ignored); } catch (ErrorsException ignored) { BindingImpl<T> binding = createUnitializedBinding(key, Scoping.UNSCOPED, source, errors); initializeBinding(binding, errors); return binding;
BindingImpl<T> binding = (BindingImpl<T>) createTypeLiteralBinding( (Key<TypeLiteral<Object>>) key, errors); return binding; if (implementedBy != null) { Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors); return createImplementedByBinding(key, scoping, implementedBy, errors); if (providedBy != null) { Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors); return createProvidedByBinding(key, scoping, providedBy, errors);
void injectAndNotify(final T instance, final Errors errors) throws ErrorsException { if (instance == null) { return; } injector.callInContext(new ContextualCallable<Void>() { @Override public Void call(InternalContext context) throws ErrorsException { injectMembers(instance, errors, context); return null; } }); notifyListeners(instance, errors); }
public Injector createInjector() { Injector injector = Guice.createInjector(modules); ((InjectorImpl) injector).clearCache(); // in ES, we always create all instances as if they are eager singletons // this allows for considerable memory savings (no need to store construction info) as well as cycles ((InjectorImpl) injector).readOnlyAllSingletons(); return injector; } }
/** * Returns a just-in-time binding for {@code key}, creating it if necessary. * * @throws ErrorsException if the binding could not be created. */ private <T> BindingImpl<T> getJustInTimeBinding(Key<T> key, Errors errors) throws ErrorsException { synchronized (state.lock()) { // first try to find a JIT binding that we've already created @SuppressWarnings("unchecked") // we only store bindings that match their key BindingImpl<T> binding = (BindingImpl<T>) jitBindings.get(key); if (binding != null) { return binding; } return createJustInTimeBindingRecursive(key, errors); } }