Exemplo n.º 1
0
 private static <T> void bind(Binder binder, Class<T> type) {
   ImmutableMap.Builder<Method, Call> methods = ImmutableMap.builder();
   for (Method method : type.getMethods()) {
     try {
       Call call = new Call(method, binder.getProvider(Storage.class));
       methods.put(method, call);
     } catch (ParseException e) {
       binder.addError("%s\n%s", method, e.getMessage());
     }
   }
   binder.bind(type).toInstance(proxy(type, methods.build()));
 }
  private <T> ProviderMethod<T> createProviderMethod(
      Binder binder, Method method, Annotation annotation) {
    binder = binder.withSource(method);
    Errors errors = new Errors(method);

    // prepare the parameter providers
    InjectionPoint point = InjectionPoint.forMethod(method, typeLiteral);
    List<Dependency<?>> dependencies = point.getDependencies();
    List<Provider<?>> parameterProviders = Lists.newArrayList();
    for (Dependency<?> dependency : point.getDependencies()) {
      parameterProviders.add(binder.getProvider(dependency));
    }

    @SuppressWarnings("unchecked") // Define T as the method's return type.
    TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method);
    Key<T> key = getKey(errors, returnType, method, method.getAnnotations());
    try {
      key = scanner.prepareMethod(binder, annotation, key, point);
    } catch (Throwable t) {
      binder.addError(t);
    }
    Class<? extends Annotation> scopeAnnotation =
        Annotations.findScopeAnnotation(errors, method.getAnnotations());
    for (Message message : errors.getMessages()) {
      binder.addError(message);
    }
    return ProviderMethod.create(
        key,
        method,
        delegate,
        ImmutableSet.copyOf(dependencies),
        parameterProviders,
        scopeAnnotation,
        skipFastClassGeneration,
        annotation);
  }
Exemplo n.º 3
0
 @Override
 public <T> Provider<T> getProvider(Dependency<T> dependency) {
   return binder.getProvider(dependency);
 }
Exemplo n.º 4
0
 @Override
 public <T> Provider<T> getProvider(Class<T> type) {
   return binder.getProvider(type);
 }
Exemplo n.º 5
0
 @Override
 public <T> Provider<T> getProvider(Key<T> key) {
   return binder.getProvider(key);
 }