Package com.google.inject.internal

Examples of com.google.inject.internal.Errors


  @SuppressWarnings("unchecked") // safe because it's a constructor of the typeLiteral
  static <T> Constructor<? extends T> findThrowingConstructor(
      TypeLiteral<? extends T> typeLiteral, Binder binder) {
   
    Class<?> rawType = typeLiteral.getRawType();
    Errors errors = new Errors(rawType);
    Constructor<?> cxtor = null;
    for (Constructor<?> constructor : rawType.getDeclaredConstructors()) {
      if (constructor.isAnnotationPresent(ThrowingInject.class)) {
        if (cxtor != null) {
          errors.addMessage("%s has more than one constructor annotated with @ThrowingInject. "
              + CONSTRUCTOR_RULES, rawType);
        }

        cxtor = constructor;
        Annotation misplacedBindingAnnotation = Annotations.findBindingAnnotation(
            errors, cxtor, ((AnnotatedElement) cxtor).getAnnotations());
        if (misplacedBindingAnnotation != null) {
          errors.misplacedBindingAnnotation(cxtor, misplacedBindingAnnotation);
        }
      }
    }
   
    if (cxtor == null) {
      errors.addMessage(
          "Could not find a suitable constructor in %s. " + CONSTRUCTOR_RULES, rawType);
    }

    for (Message msg : errors.getMessages()) {
      binder.addError(msg);
    }
    return (Constructor<? extends T>) cxtor;
  }
View Full Code Here


  }

  <T> CheckedProviderMethod<T> createProviderMethod(Binder binder, final Method method,
      Class<? extends CheckedProvider> throwingProvider) {
    binder = binder.withSource(method);
    Errors errors = new Errors(method);

    // prepare the parameter providers
    List<Dependency<?>> dependencies = Lists.newArrayList();
    List<Provider<?>> parameterProviders = Lists.newArrayList();
    List<TypeLiteral<?>> parameterTypes = typeLiteral.getParameterTypes(method);
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    for (int i = 0; i < parameterTypes.size(); i++) {
      Key<?> key = getKey(errors, parameterTypes.get(i), method, parameterAnnotations[i]);
      if(key.equals(Key.get(Logger.class))) {
        // If it was a Logger, change the key to be unique & bind it to a
        // provider that provides a logger with a proper name.
        // This solves issue 482 (returning a new anonymous logger on every call exhausts memory)
        Key<Logger> loggerKey = Key.get(Logger.class, UniqueAnnotations.create());
        binder.bind(loggerKey).toProvider(new LogProvider(method));
        key = loggerKey;
      }
      dependencies.add(Dependency.get(key));
      parameterProviders.add(binder.getProvider(key));       
    }

    @SuppressWarnings("unchecked") // Define T as the method's return type.
    TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method);
    List<TypeLiteral<?>> exceptionTypes = typeLiteral.getExceptionTypes(method);

    Key<T> key = getKey(errors, returnType, method, method.getAnnotations());
    Class<? extends Annotation> scopeAnnotation
        = Annotations.findScopeAnnotation(errors, method.getAnnotations());

    for (Message message : errors.getMessages()) {
      binder.addError(message);
    }

    return new CheckedProviderMethod<T>(key, method, delegate, ImmutableSet.copyOf(dependencies),
        parameterProviders, scopeAnnotation, throwingProvider, exceptionTypes);
View Full Code Here

TOP

Related Classes of com.google.inject.internal.Errors

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.