本文整理汇总了Java中com.google.inject.spi.Dependency类的典型用法代码示例。如果您正苦于以下问题:Java Dependency类的具体用法?Java Dependency怎么用?Java Dependency使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Dependency类属于com.google.inject.spi包,在下文中一共展示了Dependency类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ModuleDependencyTransformer
import com.google.inject.spi.Dependency; //导入依赖的package包/类
public ModuleDependencyTransformer(TypeLiteral<M> type) {
final ModuleDescription annotation = type.getRawType().getAnnotation(ModuleDescription.class);
if(annotation == null) {
requiresKeys = ImmutableSet.of();
dependsKeys = followsKeys = ImmutableSet.of();
} else {
requiresKeys = Keys.get(annotation.requires());
dependsKeys = Keys.optional(annotation.depends());
followsKeys = Keys.optional(annotation.follows());
}
dependencies = Streams.concat(requiresKeys.stream(),
dependsKeys.stream(),
followsKeys.stream())
.map(Dependency::get)
.collect(Collectors.toImmutableSet());
}
示例2: newPassType
import com.google.inject.spi.Dependency; //导入依赖的package包/类
public static PassType newPassType(String name, Class<? extends Pass> cls)
{
ImmutableList.Builder<TypeLiteral<?>> inputs = ImmutableList.builder();
ImmutableList.Builder<TypeLiteral<?>> outputs = ImmutableList.builder();
InjectionPoint passCtor = InjectionPoint.forConstructorOf(cls);
for (Dependency<?> dep : passCtor.getDependencies()) {
Key key = dep.getKey();
if (key.getAnnotation() instanceof PassInput) {
inputs.add(key.getTypeLiteral());
}
else if (key.getAnnotation() instanceof PassOutput) {
checkState(key.getTypeLiteral().getRawType() == Consumer.class);
ParameterizedType parameterized = (ParameterizedType) key.getTypeLiteral().getType();
java.lang.reflect.Type outputType = parameterized.getActualTypeArguments()[0];
outputs.add(TypeLiteral.get(outputType));
}
}
return new PassType(name, cls, inputs.build(), outputs.build());
}
示例3: initialize
import com.google.inject.spi.Dependency; //导入依赖的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);
}
示例4: EventualProvider
import com.google.inject.spi.Dependency; //导入依赖的package包/类
EventualProvider(
Invokable<T, ?> method,
boolean exposedBinding,
List<Dependency<ListenableFuture<?>>> dependencies,
Key<ListenableFuture<?>> bindingKey,
@Nullable Class<? extends Annotation> scopeAnnotation,
Object source) {
this.method = method;
this.source = source;
this.exposedBinding = exposedBinding;
this.bindingKey = bindingKey;
this.scopeAnnotation = scopeAnnotation;
this.dependencies = ImmutableList.copyOf(dependencies);
this.dependencySet = ImmutableSet.<Dependency<?>>builder()
.addAll(dependencies)
.add(Dependency.get(Key.get(Injector.class)))
.add(Dependency.get(Key.get(type.getRawType())))
.build();
}
示例5: onProvision
import com.google.inject.spi.Dependency; //导入依赖的package包/类
@Override
public <T> void onProvision(ProvisionInvocation<T> provision) {
for (DependencyAndSource dependencyAndSource : provision.getDependencyChain()) {
Dependency<?> dependency = dependencyAndSource.getDependency();
if (dependency != null && key.equals(dependency.getKey())) {
try {
ProviderAdapter.pushContext(dependency.getInjectionPoint());
provision.provision();
} finally {
ProviderAdapter.popContext();
}
break;
}
}
}
示例6: isValidForOptimizedAssistedInject
import com.google.inject.spi.Dependency; //导入依赖的package包/类
/**
* Returns true if all dependencies are suitable for the optimized version of AssistedInject. The
* optimized version caches the binding & uses a ThreadLocal Provider, so can only be applied if
* the assisted bindings are immediately provided. This looks for hints that the values may be
* lazily retrieved, by looking for injections of Injector or a Provider for the assisted values.
*/
private boolean isValidForOptimizedAssistedInject(Set<Dependency<?>> dependencies,
Class<?> implementation, TypeLiteral<?> factoryType) {
Set<Dependency<?>> badDeps = null; // optimization: create lazily
for (Dependency<?> dep : dependencies) {
if (isInjectorOrAssistedProvider(dep)) {
if (badDeps == null) {
badDeps = Sets.newHashSet();
}
badDeps.add(dep);
}
}
if (badDeps != null && !badDeps.isEmpty()) {
logger.log(Level.WARNING, "AssistedInject factory {0} will be slow "
+ "because {1} has assisted Provider dependencies or injects the Injector. "
+ "Stop injecting @Assisted Provider<T> (instead use @Assisted T) "
+ "or Injector to speed things up. (It will be a ~6500% speed bump!) "
+ "The exact offending deps are: {2}",
new Object[] {factoryType, implementation, badDeps} );
return false;
}
return true;
}
示例7: isValidForOptimizedAssistedInject
import com.google.inject.spi.Dependency; //导入依赖的package包/类
/**
* Returns true if all dependencies are suitable for the optimized version of AssistedInject. The
* optimized version caches the binding & uses a ThreadLocal Provider, so can only be applied if
* the assisted bindings are immediately provided. This looks for hints that the values may be
* lazily retrieved, by looking for injections of Injector or a Provider for the assisted values.
*/
private boolean isValidForOptimizedAssistedInject(
Set<Dependency<?>> dependencies, Class<?> implementation, TypeLiteral<?> factoryType) {
Set<Dependency<?>> badDeps = null; // optimization: create lazily
for (Dependency<?> dep : dependencies) {
if (isInjectorOrAssistedProvider(dep)) {
if (badDeps == null) {
badDeps = Sets.newHashSet();
}
badDeps.add(dep);
}
}
if (badDeps != null && !badDeps.isEmpty()) {
logger.log(
Level.WARNING,
"AssistedInject factory {0} will be slow "
+ "because {1} has assisted Provider dependencies or injects the Injector. "
+ "Stop injecting @Assisted Provider<T> (instead use @Assisted T) "
+ "or Injector to speed things up. (It will be a ~6500% speed bump!) "
+ "The exact offending deps are: {2}",
new Object[] {factoryType, implementation, badDeps});
return false;
}
return true;
}
示例8: testFactoryBindingDependencies
import com.google.inject.spi.Dependency; //导入依赖的package包/类
public void testFactoryBindingDependencies() {
Injector injector =
Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
bind(Double.class).toInstance(5.0d);
bind(ColoredCarFactory.class)
.toProvider(FactoryProvider.newFactory(ColoredCarFactory.class, Mustang.class));
}
});
Binding<?> binding = injector.getBinding(ColoredCarFactory.class);
HasDependencies hasDependencies = (HasDependencies) binding;
assertEquals(
ImmutableSet.<Dependency<?>>of(Dependency.get(Key.get(double.class))),
hasDependencies.getDependencies());
}
示例9: doInitialize
import com.google.inject.spi.Dependency; //导入依赖的package包/类
@Override
protected void doInitialize(InjectorImpl injector, Errors errors) throws ErrorsException {
@SuppressWarnings("unchecked")
K[] keysArray = (K[]) new Object[bindingSelection.getMapBindings().size()];
keys = keysArray;
ImmutableSet.Builder<Dependency<?>> dependenciesBuilder = ImmutableSet.builder();
int i = 0;
for (Map.Entry<K, Binding<V>> entry : bindingSelection.getMapBindings().entrySet()) {
dependenciesBuilder.add(Dependency.get(entry.getValue().getKey()));
keys[i] = entry.getKey();
i++;
}
ImmutableSet<Dependency<?>> localDependencies = dependenciesBuilder.build();
dependencies = localDependencies;
List<Dependency<?>> dependenciesList = localDependencies.asList();
// We know the type because we built up our own sets of dependencies, it's just
// that the interface uses a "?" generic
@SuppressWarnings("unchecked")
SingleParameterInjector<V>[] typedInjectors =
(SingleParameterInjector<V>[]) injector.getParametersInjectors(dependenciesList, errors);
injectors = typedInjectors;
}
示例10: CheckedProviderMethod
import com.google.inject.spi.Dependency; //导入依赖的package包/类
CheckedProviderMethod(
Key<T> key,
Method method,
Object instance,
ImmutableSet<Dependency<?>> dependencies,
List<Provider<?>> parameterProviders,
Class<? extends Annotation> scopeAnnotation,
Class<? extends CheckedProvider> checkedProvider,
List<TypeLiteral<?>> exceptionTypes,
boolean scopeExceptions) {
this.key = key;
this.scopeAnnotation = scopeAnnotation;
this.instance = instance;
this.dependencies = dependencies;
this.method = method;
this.parameterProviders = parameterProviders;
this.exposed = method.isAnnotationPresent(Exposed.class);
this.checkedProvider = checkedProvider;
this.exceptionTypes = exceptionTypes;
this.scopeExceptions = scopeExceptions;
method.setAccessible(true);
}
示例11: get
import com.google.inject.spi.Dependency; //导入依赖的package包/类
@Override
public T get(final InternalContext context, final Dependency<?> dependency, boolean linked)
throws InternalProvisionException {
if (provisionCallback == null) {
return doProvision(context, dependency);
} else {
return provisionCallback.provision(
context,
new ProvisionCallback<T>() {
@Override
public T call() throws InternalProvisionException {
return doProvision(context, dependency);
}
});
}
}
示例12: initialize
import com.google.inject.spi.Dependency; //导入依赖的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;
}
示例13: testMultibinderDependencies
import com.google.inject.spi.Dependency; //导入依赖的package包/类
/**
* We just want to make sure that multibinder's binding depends on each of its values. We don't
* really care about the underlying structure of those bindings, which are implementation details.
*/
public void testMultibinderDependencies() {
Injector injector =
Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
Multibinder<String> multibinder = Multibinder.newSetBinder(binder(), String.class);
multibinder.addBinding().toInstance("A");
multibinder.addBinding().to(Key.get(String.class, Names.named("b")));
bindConstant().annotatedWith(Names.named("b")).to("B");
}
});
Binding<Set<String>> binding = injector.getBinding(new Key<Set<String>>() {});
HasDependencies withDependencies = (HasDependencies) binding;
Set<String> elements = Sets.newHashSet();
for (Dependency<?> dependency : withDependencies.getDependencies()) {
elements.add((String) injector.getInstance(dependency.getKey()));
}
assertEquals(ImmutableSet.of("A", "B"), elements);
}
示例14: provision
import com.google.inject.spi.Dependency; //导入依赖的package包/类
@Override
protected T provision(javax.inject.Provider<? extends T> provider, Errors errors,
Dependency<?> dependency, ConstructionContext<T> constructionContext)
throws ErrorsException {
try {
Object o = super.provision(provider, errors, dependency, constructionContext);
if (o != null && !rawType.isInstance(o)) {
throw errors.subtypeNotProvided(providerType, rawType).toException();
}
@SuppressWarnings("unchecked") // protected by isInstance() check above
T t = (T) o;
return t;
} catch (RuntimeException e) {
throw errors.errorInProvider(e).toException();
}
}
示例15: doProvision
import com.google.inject.spi.Dependency; //导入依赖的package包/类
@Override
protected Optional<T> doProvision(InternalContext context, Dependency<?> currentDependency)
throws InternalProvisionException {
InternalFactory<? extends T> local = delegate;
if (local == null) {
return Optional.absent();
}
Dependency<?> localDependency = targetDependency;
T result;
Dependency previous = context.pushDependency(localDependency, getSource());
try {
// currentDependency is Optional<? super T>, so we really just need to set the target
// dependency to ? super T, but we are currently setting it to T. We could hypothetically
// make it easier for our delegate to generate proxies by modifying the dependency, but that
// would also require us to rewrite the key on each call. So for now we don't do it.
result = local.get(context, localDependency, false);
} catch (InternalProvisionException ipe) {
throw ipe.addSource(localDependency);
} finally {
context.popStateAndSetDependency(previous);
}
return Optional.fromNullable(result);
}