public Errors merge(Errors moreErrors) { if (moreErrors.root == root || moreErrors.root.errors == null) { return this; } merge(moreErrors.root.errors); return this; }
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 Errors merge(InternalProvisionException ipe) { merge(ipe.getErrors()); return this; }
/** * Performs creation-time injections on all objects that require it. Whenever fulfilling an * injection depends on another object that requires injection, we inject it first. If the two * instances are codependent (directly or transitively), ordering of injection is arbitrary. */ void injectAll(final Errors errors) { Preconditions.checkState(validationStarted, "Validation should be done before injection"); for (InjectableReference<?> reference : pendingInjections) { try { reference.get(); } catch (InternalProvisionException ipe) { errors.merge(ipe); } } pendingInjections.clear(); }
public Errors errorInUserCode(Throwable cause, String messageFormat, Object... arguments) { Collection<Message> messages = getMessagesFromThrowable(cause); if (!messages.isEmpty()) { return merge(messages); } else { return addMessage(cause, messageFormat, arguments); } }
void validate() { Errors errorsForMember = errors.withSource(source); Set<InjectionPoint> injectionPoints; try { injectionPoints = request.getInjectionPoints(); } catch (ConfigurationException e) { errorsForMember.merge(e.getErrorMessages()); injectionPoints = e.getPartialValue(); } if (injectionPoints != null) { memberInjectors = injector.membersInjectorStore.getInjectors(injectionPoints, errorsForMember); } else { memberInjectors = ImmutableList.of(); } errors.merge(errorsForMember); }
@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()); } }
@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()); } }
/** * Prepares member injectors for all injected instances. This prompts Guice to do static analysis * on the injected instances. */ void validateOustandingInjections(Errors errors) { validationStarted = true; initializablesCache.clear(); for (InjectableReference<?> reference : pendingInjections) { try { reference.validate(errors); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } }
private ImmutableList<Dependency<?>> forMember( Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) { Errors errors = new Errors(member); List<Dependency<?>> dependencies = Lists.newArrayList(); int index = 0; for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) { try { Annotation[] parameterAnnotations = paramterAnnotations[index]; Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors); dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index)); index++; } catch (ConfigurationException e) { errors.merge(e.getErrorMessages()); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } errors.throwConfigurationExceptionIfErrorsExist(); return ImmutableList.copyOf(dependencies); }
InjectionPoint(TypeLiteral<?> declaringType, Field field, boolean optional) { this.member = field; this.declaringType = declaringType; this.optional = optional; Annotation[] annotations = field.getAnnotations(); Errors errors = new Errors(field); Key<?> key = null; try { key = Annotations.getKey(declaringType.getFieldType(field), field, annotations, errors); } catch (ConfigurationException e) { errors.merge(e.getErrorMessages()); } catch (ErrorsException e) { errors.merge(e.getErrors()); } errors.throwConfigurationExceptionIfErrorsExist(); this.dependencies = ImmutableList.<Dependency<?>>of( newDependency(key, Nullability.allowsNull(annotations), -1)); }
@Override public void run() { try { binding.getInjector().initializeBinding(binding, errors.withSource(source)); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } };
@Override public Object load(K key) { Errors errors = new Errors(); V result = null; try { result = FailableCache.this.create(key, errors); } catch (ErrorsException e) { errors.merge(e.getErrors()); } return errors.hasErrors() ? errors : result; } });
@Override public <T> Boolean visit(MembersInjectorLookup<T> lookup) { try { MembersInjector<T> membersInjector = injector.membersInjectorStore.get(lookup.getType(), errors); lookup.initializeDelegate(membersInjector); } catch (ErrorsException e) { errors.merge(e.getErrors()); // TODO: source } return true; }
@Override public <T> Boolean visit(ProviderLookup<T> lookup) { // ensure the provider can be created try { Provider<T> provider = injector.getProviderOrThrow(lookup.getDependency(), errors); lookup.initializeDelegate(provider); } catch (ErrorsException e) { errors.merge(e.getErrors()); // TODO: source } return true; } }
@Override public <T> MembersInjector<T> getMembersInjector(TypeLiteral<T> typeLiteral) { Errors errors = new Errors(typeLiteral); try { return membersInjectorStore.get(typeLiteral, errors); } catch (ErrorsException e) { throw new ConfigurationException(errors.merge(e.getErrors()).getMessages()); } }
/** Returns the binding for {@code key} */ @Override public <T> BindingImpl<T> getBinding(Key<T> key) { Errors errors = new Errors(key); try { BindingImpl<T> result = getBindingOrThrow(key, errors, JitLimitation.EXISTING_JIT); errors.throwConfigurationExceptionIfErrorsExist(); return result; } catch (ErrorsException e) { throw new ConfigurationException(errors.merge(e.getErrors()).getMessages()); } }
@Override public Boolean visit(InjectionRequest<?> request) { Set<InjectionPoint> injectionPoints; try { injectionPoints = request.getInjectionPoints(); } catch (ConfigurationException e) { errors.merge(e.getErrorMessages()); injectionPoints = e.getPartialValue(); } initializer.requestInjection( injector, request.getInstance(), null, request.getSource(), injectionPoints); return true; }
void injectMembers() { InternalContext context = injector.enterContext(); try { boolean isStageTool = injector.options.stage == Stage.TOOL; for (SingleMemberInjector memberInjector : memberInjectors) { // Run injections if we're not in tool stage (ie, PRODUCTION or DEV), // or if we are in tool stage and the injection point is toolable. if (!isStageTool || memberInjector.getInjectionPoint().isToolable()) { try { memberInjector.inject(context, null); } catch (InternalProvisionException e) { errors.merge(e); } } } } finally { context.close(); } } }
@Override public <T> Provider<T> getProvider(final Key<T> key) { Errors errors = new Errors(key); try { Provider<T> result = getProviderOrThrow(Dependency.get(key), errors); errors.throwIfNewErrors(0); return result; } catch (ErrorsException e) { throw new ConfigurationException(errors.merge(e.getErrors()).getMessages()); } }