@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); }
/** * 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 } }
/** * 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; }
@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); }
/** * 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 } }
@Inject @Toolable void initialize(Injector injector) { manager = injector.getInstance(Key.get(typeLiteral)); }
@Inject @Toolable void initialize(Injector injector) { this.factory = (ComponentFactory<T>) injector.getInstance(clazz); }
@Inject @Toolable void initialize(Injector injector) { this.injector.set(injector); this.factory = new BindingComponentFactory<T>(clazz, binderResolver, this); }
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()); }
@Inject @Toolable protected void initialize(RibbonResourceFactory factory) { this.factory = factory; }
@Toolable @SuppressWarnings("unused") @Inject void method(M m) { this.m = m; }
@Toolable @SuppressWarnings("unused") @Inject static void staticMethod(SM sm) { Tooled.sm = sm; }