/** Returns an array of parameter values. */
  static Object[] getAll(
      Errors errors, InternalContext context, SingleParameterInjector<?>[] parameterInjectors)
      throws ErrorsException {
    if (parameterInjectors == null) {
      return NO_ARGUMENTS;
    }

    int numErrorsBefore = errors.size();

    int size = parameterInjectors.length;
    Object[] parameters = new Object[size];

    // optimization: use manual for/each to save allocating an iterator here
    for (int i = 0; i < size; i++) {
      SingleParameterInjector<?> parameterInjector = parameterInjectors[i];
      try {
        parameters[i] = parameterInjector.inject(errors, context);
      } catch (ErrorsException e) {
        errors.merge(e.getErrors());
      }
    }

    errors.throwIfNewErrors(numErrorsBefore);
    return parameters;
  }
Пример #2
0
 /**
  * When serialized, we eagerly convert sources to strings. This hurts our formatting, but it
  * guarantees that the receiving end will be able to read the message.
  */
 private Object writeReplace() throws ObjectStreamException {
   Object[] sourcesAsStrings = sources.toArray();
   for (int i = 0; i < sourcesAsStrings.length; i++) {
     sourcesAsStrings[i] = Errors.convert(sourcesAsStrings[i]).toString();
   }
   return new Message(Arrays.asList(sourcesAsStrings), message, cause);
 }
 private T inject(Errors errors, InternalContext context) throws ErrorsException {
   context.setDependency(dependency);
   try {
     return factory.get(errors.withSource(dependency), context, dependency);
   } finally {
     context.setDependency(null);
   }
 }
Пример #4
0
  /**
   * Replaces annotation scopes with instance scopes using the Injector's annotation-to-instance
   * map. If the scope annotation has no corresponding instance, an error will be added and unscoped
   * will be retuned.
   */
  static Scoping makeInjectable(Scoping scoping, InjectorImpl injector, Errors errors) {
    Class<? extends Annotation> scopeAnnotation = scoping.getScopeAnnotation();
    if (scopeAnnotation == null) {
      return scoping;
    }

    Scope scope = injector.state.getScope(scopeAnnotation);
    if (scope != null) {
      return Scoping.forInstance(scope);
    }

    errors.scopeNotFound(scopeAnnotation);
    return Scoping.UNSCOPED;
  }
Пример #5
0
 @Override
 public String getSource() {
   return sources.isEmpty()
       ? SourceProvider.UNKNOWN_SOURCE.toString()
       : Errors.convert(sources.get(sources.size() - 1)).toString();
 }