本文整理汇总了Java中com.google.inject.spi.Dependency.get方法的典型用法代码示例。如果您正苦于以下问题:Java Dependency.get方法的具体用法?Java Dependency.get怎么用?Java Dependency.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.inject.spi.Dependency
的用法示例。
在下文中一共展示了Dependency.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDependencyChain
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
/** Returns the current dependency chain (all the state stored in the dependencyStack). */
java.util.List<com.google.inject.spi.DependencyAndSource> getDependencyChain() {
com.google.common.collect.ImmutableList.Builder<com.google.inject.spi.DependencyAndSource>
builder = com.google.common.collect.ImmutableList.builder();
for (int i = 0; i < dependencyStackSize; i += 2) {
Object evenEntry = dependencyStack[i];
Dependency<?> dependency;
if (evenEntry instanceof com.google.inject.Key) {
dependency = Dependency.get((com.google.inject.Key<?>) evenEntry);
} else {
dependency = (Dependency<?>) evenEntry;
}
builder.add(new com.google.inject.spi.DependencyAndSource(dependency, dependencyStack[i + 1]));
}
return builder.build();
}
示例2: extractDependency
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
Dependency<ListenableFuture<?>> extractDependency(Errors methodErrors, Parameter parameter) {
@Nullable Annotation bindingAnnotation =
Annotations.findBindingAnnotation(
methodErrors,
parameter.getDeclaringInvokable(),
parameter.getAnnotations());
return Dependency.get(futureKey(
parameter.getType(),
bindingAnnotation));
}
示例3: loadEagerSingletons
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
/**
* Loads eager singletons, or all singletons if we're in Stage.PRODUCTION. Bindings discovered
* while we're binding these singletons are not be eager.
*/
void loadEagerSingletons(InjectorImpl injector, Stage stage, final Errors errors) {
List<BindingImpl<?>> candidateBindings = new ArrayList<>();
@SuppressWarnings("unchecked") // casting Collection<Binding> to Collection<BindingImpl> is safe
Collection<BindingImpl<?>> bindingsAtThisLevel =
(Collection) injector.state.getExplicitBindingsThisLevel().values();
candidateBindings.addAll(bindingsAtThisLevel);
synchronized (injector.state.lock()) {
// jit bindings must be accessed while holding the lock.
candidateBindings.addAll(injector.jitBindings.values());
}
InternalContext context = injector.enterContext();
try {
for (BindingImpl<?> binding : candidateBindings) {
if (isEagerSingleton(injector, binding, stage)) {
Dependency<?> dependency = Dependency.get(binding.getKey());
Dependency previous = context.pushDependency(dependency, binding.getSource());
try {
binding.getInternalFactory().get(context, dependency, false);
} catch (InternalProvisionException e) {
errors.withSource(dependency).merge(e);
} finally {
context.popStateAndSetDependency(previous);
}
}
}
} finally {
context.close();
}
}
示例4: doInitialize
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
@Override
protected void doInitialize(InjectorImpl injector, Errors errors) throws ErrorsException {
@SuppressWarnings({"unchecked", "rawtypes"})
PerKeyData<K, V>[] typedPerKeyData =
new PerKeyData[bindingSelection.getMapBindings().size()];
perKeyDatas = typedPerKeyData;
ImmutableSet.Builder<Dependency<?>> dependenciesBuilder = ImmutableSet.builder();
List<Dependency<?>> dependenciesForKey = Lists.newArrayList();
int i = 0;
for (Map.Entry<K, Set<Binding<V>>> entry :
bindingSelection.getMultimapBindings().entrySet()) {
// Clear the list of dependencies because we're reusing it for each different key
dependenciesForKey.clear();
Set<Binding<V>> bindings = entry.getValue();
@SuppressWarnings({"unchecked", "rawtypes"})
Binding<V>[] typedBindings = new Binding[bindings.size()];
Binding<V>[] bindingsArray = typedBindings;
int j = 0;
for (Binding<V> binding : bindings) {
Dependency<V> dependency = Dependency.get(binding.getKey());
dependenciesBuilder.add(dependency);
dependenciesForKey.add(dependency);
bindingsArray[j] = binding;
j++;
}
@SuppressWarnings("unchecked")
SingleParameterInjector<V>[] injectors =
(SingleParameterInjector<V>[])
injector.getParametersInjectors(dependenciesForKey, errors);
perKeyDatas[i] = new PerKeyData<>(entry.getKey(), bindingsArray, injectors);
i++;
}
dependencies = dependenciesBuilder.build();
}
示例5: testMultibindingProviderDependencies
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
public void testMultibindingProviderDependencies() {
final Annotation setAnn = Names.named("foo");
Injector injector =
Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
Multibinder<String> multibinder =
Multibinder.newSetBinder(binder(), String.class, setAnn);
multibinder.addBinding().toInstance("a");
multibinder.addBinding().toInstance("b");
}
});
HasDependencies providerBinding =
(HasDependencies) injector.getBinding(new Key<Collection<Provider<String>>>(setAnn) {});
HasDependencies setBinding =
(HasDependencies) injector.getBinding(new Key<Set<String>>(setAnn) {});
// sanity check the size
assertEquals(setBinding.getDependencies().toString(), 2, setBinding.getDependencies().size());
Set<Dependency<?>> expected = Sets.newHashSet();
for (Dependency<?> dep : setBinding.getDependencies()) {
Key key = dep.getKey();
Dependency<?> providerDependency =
Dependency.get(key.ofType(Types.providerOf(key.getTypeLiteral().getType())));
expected.add(providerDependency);
}
assertEquals(expected, providerBinding.getDependencies());
}