Search in sources :

Example 1 with Toolable

use of com.google.inject.spi.Toolable in project guice by google.

the class FactoryProvider2 method initialize.

/**
   * 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 {
            // won't be used -- instead will bind to data.providers.
            args = null;
        }
        getBindingFromNewInjector(method, args, // throws if the binding isn't properly configured
        data);
    }
}
Also used : Message(com.google.inject.spi.Message) ConfigurationException(com.google.inject.ConfigurationException) Method(java.lang.reflect.Method) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Inject(com.google.inject.Inject) Toolable(com.google.inject.spi.Toolable)

Example 2 with Toolable

use of com.google.inject.spi.Toolable in project roboguice by roboguice.

the class FactoryProvider2 method initialize.

/**
   * 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 {
            // won't be used -- instead will bind to data.providers.
            args = null;
        }
        // throws if the binding isn't properly configured
        getBindingFromNewInjector(method, args, data);
    }
}
Also used : Message(com.google.inject.spi.Message) ConfigurationException(com.google.inject.ConfigurationException) Method(java.lang.reflect.Method) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Inject(com.google.inject.Inject) Toolable(com.google.inject.spi.Toolable)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)2 ConfigurationException (com.google.inject.ConfigurationException)2 Inject (com.google.inject.Inject)2 Message (com.google.inject.spi.Message)2 Toolable (com.google.inject.spi.Toolable)2 Method (java.lang.reflect.Method)2 Map (java.util.Map)2