Java 类com.google.inject.spi.Toolable 实例源码

项目:guice-scoped-proxy-extension    文件:ScopedProxyBinder.java   
@Inject
@Toolable
@SuppressWarnings("unchecked")
void initialize(Injector injector) {
    final Binding<T> realBinding = injector.getBinding(this.rewritten);
    final Provider<T> realProvider = injector.getProvider(realBinding.getKey());

    // The proxy will be a sub type of the source type of the binding
    final Class<T> proxyType = (Class<T>) realBinding.getKey()
            .getTypeLiteral().getRawType();

    this.dependencies = Collections.singleton(
            Dependency.get(this.rewritten));
    this.ref = InstanceBuilder.forType(proxyType)
            .withConstructionStrategy(this.strategy)
            .dispatchTo(realProvider)
            .create(injector);
}
项目:guice-scoped-proxy-extension    文件:ScopedProxyBinder.java   
@Inject
@Toolable
@SuppressWarnings("unchecked")
void initialize(Injector injector) {
    final Binding<T> realBinding = injector.getBinding(this.rewritten);
    final Provider<T> realProvider = injector.getProvider(realBinding.getKey());

    // The proxy will be a sub type of the source type of the binding
    final Class<T> proxyType = (Class<T>) realBinding.getKey()
            .getTypeLiteral().getRawType();

    this.dependencies = Collections.singleton(
            Dependency.get(this.rewritten));
    this.ref = InstanceBuilder.forType(proxyType)
            .withConstructionStrategy(this.strategy)
            .dispatchTo(realProvider)
            .create(injector);
}
项目:guice-old    文件:FactoryProvider2.java   
/**
 * At injector-creation time, we initialize the invocation handler. At this time we make sure
 * all factory methods will be able to build the target types.
 */
@Inject @Toolable
void initialize(Injector injector) {
  if (this.injector != null) {
    throw new ConfigurationException(ImmutableList.of(new Message(FactoryProvider2.class,
        "Factories.create() factories may only be used in one Injector!")));
  }

  this.injector = injector;

  for (Map.Entry<Method, AssistData> entry : assistDataByMethod.entrySet()) {
    Method method = entry.getKey();
    AssistData data = entry.getValue();
    Object[] args;
    if(!data.optimized) {
      args = new Object[method.getParameterTypes().length];
      Arrays.fill(args, "dummy object for validating Factories");
    } else {
      args = null; // won't be used -- instead will bind to data.providers.
    }
    getBindingFromNewInjector(method, args, data); // throws if the binding isn't properly configured
  }
}
项目:guice-old    文件:Multibinder.java   
/**
 * Invoked by Guice at Injector-creation time to prepare providers for each
 * element in this set. At this time the set's size is known, but its
 * contents are only evaluated when get() is invoked.
 */
@Toolable @Inject void initialize(Injector injector) {
  List<Binding<T>> bindings = Lists.newArrayList();
  List<Dependency<?>> dependencies = Lists.newArrayList();
  for (Binding<?> entry : injector.findBindingsByType(elementType)) {
    if (keyMatches(entry.getKey())) {
      @SuppressWarnings("unchecked") // protected by findBindingsByType()
      Binding<T> binding = (Binding<T>) entry;
      bindings.add(binding);
      dependencies.add(Dependency.get(binding.getKey()));
    }
  }

  this.bindings = ImmutableList.copyOf(bindings);
  this.dependencies = ImmutableSet.copyOf(dependencies);
  this.permitDuplicates = permitsDuplicates(injector);
  this.binder = null;
}
项目:google-guice    文件:FactoryProvider2.java   
/**
 * At injector-creation time, we initialize the invocation handler. At this time we make sure
 * all factory methods will be able to build the target types.
 */
@Inject @Toolable
void initialize(Injector injector) {
  if (this.injector != null) {
    throw new ConfigurationException(ImmutableList.of(new Message(FactoryProvider2.class,
        "Factories.create() factories may only be used in one Injector!")));
  }

  this.injector = injector;

  for (Map.Entry<Method, AssistData> entry : assistDataByMethod.entrySet()) {
    Method method = entry.getKey();
    AssistData data = entry.getValue();
    Object[] args;
    if(!data.optimized) {
      args = new Object[method.getParameterTypes().length];
      Arrays.fill(args, "dummy object for validating Factories");
    } else {
      args = null; // won't be used -- instead will bind to data.providers.
    }
    getBindingFromNewInjector(method, args, data); // throws if the binding isn't properly configured
  }
}
项目:google-guice    文件:Multibinder.java   
/**
 * Invoked by Guice at Injector-creation time to prepare providers for each
 * element in this set. At this time the set's size is known, but its
 * contents are only evaluated when get() is invoked.
 */
@Toolable @Inject void initialize(Injector injector) {
  List<Binding<T>> bindings = Lists.newArrayList();
  List<Dependency<?>> dependencies = Lists.newArrayList();
  for (Binding<?> entry : injector.findBindingsByType(elementType)) {
    if (keyMatches(entry.getKey())) {
      @SuppressWarnings("unchecked") // protected by findBindingsByType()
      Binding<T> binding = (Binding<T>) entry;
      bindings.add(binding);
      dependencies.add(Dependency.get(binding.getKey()));
    }
  }

  this.bindings = ImmutableList.copyOf(bindings);
  this.dependencies = ImmutableSet.copyOf(dependencies);
  this.permitDuplicates = permitsDuplicates(injector);
  this.binder = null;
}
项目:guice-utils    文件:ListBinder.java   
@Inject
@Toolable
void initialize(Injector injector) {
    List<Binding<T>> bindings = new ArrayList<Binding<T>>();

    for ( Binding<?> entry : injector.findBindingsByType(elementType) ) {
        if ( !keyMatches(entry.getKey()) )
            continue;

        @SuppressWarnings("unchecked")
        Binding<T> binding = (Binding<T>) entry;
        bindings.add(binding);
    }

    Collections.sort(bindings, new PriorityComparator());
    this.bindings = Collections.unmodifiableList(bindings);
}
项目:guice    文件:FactoryProvider2.java   
/**
 * At injector-creation time, we initialize the invocation handler. At this time we make sure all
 * factory methods will be able to build the target types.
 */
@Inject
@Toolable
void initialize(Injector injector) {
  if (this.injector != null) {
    throw new ConfigurationException(
        ImmutableList.of(
            new Message(
                FactoryProvider2.class,
                "Factories.create() factories may only be used in one Injector!")));
  }

  this.injector = injector;

  for (Map.Entry<Method, AssistData> entry : assistDataByMethod.entrySet()) {
    Method method = entry.getKey();
    AssistData data = entry.getValue();
    Object[] args;
    if (!data.optimized) {
      args = new Object[method.getParameterTypes().length];
      Arrays.fill(args, "dummy object for validating Factories");
    } else {
      args = null; // won't be used -- instead will bind to data.providers.
    }
    getBindingFromNewInjector(
        method, args, data); // throws if the binding isn't properly configured
  }
}
项目:fabricator    文件:NamedInstanceProvider.java   
@Inject
@Toolable
void initialize(Injector injector) {
    manager = injector.getInstance(Key.get(typeLiteral));
}
项目:fabricator    文件:ComponentFactoryFactoryProvider.java   
@Inject
@Toolable
void initialize(Injector injector) {
    this.factory = (ComponentFactory<T>) injector.getInstance(clazz);
}
项目:fabricator    文件:GuiceBindingComponentFactoryProvider.java   
@Inject
@Toolable
void initialize(Injector injector) {
    this.injector.set(injector);
    this.factory = new BindingComponentFactory<T>(clazz, binderResolver, this);
}
项目:guice-old    文件:OptionalBinder.java   
public void configure(Binder binder) {
  checkConfiguration(!isInitialized(), "OptionalBinder was already initialized");

  final Provider<Map<Source, Provider<T>>> mapProvider = binder.getProvider(mapKey);
  binder.bind(optionalProviderKey).toProvider(
      new RealOptionalBinderProviderWithDependencies<Optional<Provider<T>>>(typeKey) {
    private Optional<Provider<T>> optional;

    @Toolable @Inject void initialize(Injector injector) {
      RealOptionalBinder.this.binder = null;
      Map<Source, Provider<T>> map = mapProvider.get();
      // Map might be null if duplicates prevented MapBinder from initializing
      if (map != null) {
        if (map.containsKey(Source.ACTUAL)) {
          // TODO(sameb): Consider exposing an option that will allow
          // ACTUAL to fallback to DEFAULT if ACTUAL's provider returns null.
          // Right now, an ACTUAL binding can convert from present -> absent
          // if it's bound to a provider that returns null.
          optional = Optional.fromNullable(map.get(Source.ACTUAL)); 
        } else if (map.containsKey(Source.DEFAULT)) {
          optional = Optional.fromNullable(map.get(Source.DEFAULT));
        } else {
          optional = Optional.absent();
        }

        // Also set up the bindings for the SPI.
        if (map.containsKey(Source.ACTUAL)) {
          actualBinding = getBindingFromMapProvider(injector, map.get(Source.ACTUAL));
        }
        if (map.containsKey(Source.DEFAULT)) {
          defaultBinding = getBindingFromMapProvider(injector, map.get(Source.DEFAULT));
        }
      }
    }

    public Optional<Provider<T>> get() {
      return optional;
    }

    public Set<Dependency<?>> getDependencies() {
      return dependencies;
    }
  });

  // Optional is immutable, so it's safe to expose Optional<Provider<T>> as
  // Optional<javax.inject.Provider<T>> (since Guice provider implements javax Provider).
  @SuppressWarnings({"unchecked", "cast"})
  Key massagedOptionalProviderKey = (Key) optionalProviderKey;
  binder.bind(optionalJavaxProviderKey).to(massagedOptionalProviderKey);

  binder.bind(optionalKey).toProvider(new RealOptionalKeyProvider());
}
项目:ribbon    文件:RibbonResourceProvider.java   
@Inject
@Toolable
protected void initialize(RibbonResourceFactory factory) {
    this.factory = factory;
}
项目:guice-old    文件:ToolStageInjectorTest.java   
@Toolable @SuppressWarnings("unused") @Inject void method(M m) { this.m = m; }
项目:guice-old    文件:ToolStageInjectorTest.java   
@Toolable @SuppressWarnings("unused") @Inject static void staticMethod(SM sm) { Tooled.sm = sm; }
项目:google-guice    文件:ToolStageInjectorTest.java   
@Toolable @SuppressWarnings("unused") @Inject void method(M m) { this.m = m; }
项目:google-guice    文件:ToolStageInjectorTest.java   
@Toolable @SuppressWarnings("unused") @Inject static void staticMethod(SM sm) { Tooled.sm = sm; }