本文整理汇总了Java中com.google.inject.spi.Toolable类的典型用法代码示例。如果您正苦于以下问题:Java Toolable类的具体用法?Java Toolable怎么用?Java Toolable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Toolable类属于com.google.inject.spi包,在下文中一共展示了Toolable类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import com.google.inject.spi.Toolable; //导入依赖的package包/类
@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);
}
示例2: initialize
import com.google.inject.spi.Toolable; //导入依赖的package包/类
/**
* 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
}
}
示例3: initialize
import com.google.inject.spi.Toolable; //导入依赖的package包/类
/**
* 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;
}
示例4: initialize
import com.google.inject.spi.Toolable; //导入依赖的package包/类
@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);
}
示例5: initialize
import com.google.inject.spi.Toolable; //导入依赖的package包/类
/**
* 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
}
}
示例6: initialize
import com.google.inject.spi.Toolable; //导入依赖的package包/类
@Inject
@Toolable
void initialize(Injector injector) {
manager = injector.getInstance(Key.get(typeLiteral));
}
示例7: initialize
import com.google.inject.spi.Toolable; //导入依赖的package包/类
@Inject
@Toolable
void initialize(Injector injector) {
this.factory = (ComponentFactory<T>) injector.getInstance(clazz);
}
示例8: initialize
import com.google.inject.spi.Toolable; //导入依赖的package包/类
@Inject
@Toolable
void initialize(Injector injector) {
this.injector.set(injector);
this.factory = new BindingComponentFactory<T>(clazz, binderResolver, this);
}
示例9: configure
import com.google.inject.spi.Toolable; //导入依赖的package包/类
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());
}
示例10: initialize
import com.google.inject.spi.Toolable; //导入依赖的package包/类
@Inject
@Toolable
protected void initialize(RibbonResourceFactory factory) {
this.factory = factory;
}
示例11: method
import com.google.inject.spi.Toolable; //导入依赖的package包/类
@Toolable @SuppressWarnings("unused") @Inject void method(M m) { this.m = m; }
示例12: staticMethod
import com.google.inject.spi.Toolable; //导入依赖的package包/类
@Toolable @SuppressWarnings("unused") @Inject static void staticMethod(SM sm) { Tooled.sm = sm; }