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.º 2
0
 public void applyTo(Binder binder) {
   getScoping()
       .applyTo(
           binder.withSource(getSource()).bind(getKey()).toProvider(getUserSuppliedProvider()));
 }
Exemplo n.º 3
0
 public void applyTo(Binder binder) {
   binder.withSource(getSource()).bindScope(annotationType, scope);
 }
 @Override
 public void applyTo(Binder binder) {
   getScoping().applyTo(binder.withSource(getSource()).bind(getKey()));
 }
Exemplo n.º 5
0
 @Override
 public Binder withSource(Object source) {
   return binder.withSource(source);
 }
Exemplo n.º 6
0
 @Override
 public void bindListener(Matcher<? super TypeLiteral<?>> typeMatcher, TypeListener listener) {
   binder.withSource(getBindingLocation()).bindListener(typeMatcher, listener);
 }
Exemplo n.º 7
0
 @Override
 public void install(Module module) {
   binder.withSource(getBindingLocation()).install(module);
 }
Exemplo n.º 8
0
 @Override
 public void requestStaticInjection(Class<?>... types) {
   binder.withSource(getBindingLocation()).requestStaticInjection(types);
 }
Exemplo n.º 9
0
 @Override
 public void requestInjection(Object instance) {
   binder.withSource(getBindingLocation()).requestInjection(instance);
 }
Exemplo n.º 10
0
 @Override
 public <T> void requestInjection(TypeLiteral<T> type, T instance) {
   binder.withSource(getBindingLocation()).requestInjection(type, instance);
 }
Exemplo n.º 11
0
 @Override
 public AnnotatedConstantBindingBuilder bindConstant() {
   return binder.withSource(getBindingLocation()).bindConstant();
 }
Exemplo n.º 12
0
 @Override
 public <T> AnnotatedBindingBuilder<T> bind(Class<T> type) {
   warnOnSpecialized(type);
   return binder.withSource(getBindingLocation()).bind(type);
 }
Exemplo n.º 13
0
 @Override
 public <T> AnnotatedBindingBuilder<T> bind(TypeLiteral<T> typeLiteral) {
   warnOnSpecialized(typeLiteral.getRawType());
   return binder.withSource(getBindingLocation()).bind(typeLiteral);
 }
Exemplo n.º 14
0
 @Override
 public <T> LinkedBindingBuilder<T> bind(Key<T> key) {
   warnOnSpecialized(key.getTypeLiteral().getRawType());
   return binder.withSource(getBindingLocation()).bind(key);
 }