本文整理汇总了Java中com.google.inject.spi.ProviderInstanceBinding类的典型用法代码示例。如果您正苦于以下问题:Java ProviderInstanceBinding类的具体用法?Java ProviderInstanceBinding怎么用?Java ProviderInstanceBinding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProviderInstanceBinding类属于com.google.inject.spi包,在下文中一共展示了ProviderInstanceBinding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public Void visit(ProviderInstanceBinding<? extends T> providerInstanceBinding) {
// Detect provider methods and handle them
// TODO(bstoler): Update this when the SPI explicitly has a case for
// provider methods
Provider<? extends T> provider = providerInstanceBinding.getProviderInstance();
if (provider instanceof ProviderMethod) {
Context context = Context.forElement(providerInstanceBinding);
bindingsCollection.addBinding(targetKey,
bindingFactory.getProviderMethodBinding((ProviderMethod<?>) provider, context));
return null;
}
if (provider instanceof GwtDotCreateProvider) {
addImplicitBinding(providerInstanceBinding);
return null;
}
// OTt, use the normal default handler (and error)
return super.visit(providerInstanceBinding);
}
示例2: instantiation
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
private static String instantiation(Binding<?> binding) {
if (binding instanceof InstanceBinding<?>) {
return instanceLiteral((InstanceBinding<?>) binding);
} else if (binding instanceof ProviderKeyBinding<?>) {
return providerCall(((ProviderKeyBinding<?>) binding).getProviderKey()) + ".get()";
} else if (binding instanceof LinkedKeyBinding<?>) {
return providerCall(((LinkedKeyBinding<?>) binding).getLinkedKey());
} else if (binding instanceof ConstructorBinding<?>) {
return constructorCall((ConstructorBinding<?>) binding);
} else if (binding instanceof ProviderBinding<?>) {
return provider((ProviderBinding<?>) binding);
} else if (binding instanceof ProviderInstanceBinding<?>) {
return instantiation((ProviderInstanceBinding<?>) binding);
} else {
throw new DeguicifierException();
}
}
示例3: providesMethodCall
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
private static String providesMethodCall(ProviderInstanceBinding<?> binding,
ProviderMethod<?> provider) {
Method providesMethod = provider.getMethod();
Class<?> moduleClass = providesMethod.getDeclaringClass();
if (moduleClass.isLocalClass()) {
throw new DeguicifierException();
}
try {
moduleClass.getConstructor();
} catch (NoSuchMethodException e) {
throw new DeguicifierException(e);
}
String statement =
"new " + moduleClass.getCanonicalName() + "()." + providesMethod.getName() + "("
+ argumentList(binding) + ")";
return statement;
}
示例4: testGetInstanceName_providerMethod
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public void testGetInstanceName_providerMethod() throws Exception {
final ProviderMethod<?>[] methodHolder = new ProviderMethod[1];
Injector injector = Guice.createInjector(new ProvidingModule());
injector
.getBinding(Integer.class)
.acceptTargetVisitor(
new DefaultBindingTargetVisitor<Object, Void>() {
@SuppressWarnings("unchecked")
@Override
public Void visit(ProviderInstanceBinding<?> binding) {
methodHolder[0] = (ProviderMethod) binding.getUserSuppliedProvider();
return null;
}
});
assertEquals(
"Method provider should pretty print as the method signature",
"#provideInteger(String)",
nameFactory.getInstanceName(methodHolder[0]));
}
示例5: containsElement
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
/** Implementation of {@link OptionalBinderBinding#containsElement}. */
boolean containsElement(Element element) {
// All of our bindings are ProviderInstanceBindings whose providers extend
// RealOptionalBinderProviderWithDependencies and have 'this' as its binding selection.
if (element instanceof ProviderInstanceBinding) {
javax.inject.Provider<?> providerInstance =
((ProviderInstanceBinding<?>) element).getUserSuppliedProvider();
if (providerInstance instanceof RealOptionalBinderProviderWithDependencies) {
return ((RealOptionalBinderProviderWithDependencies<?, ?>) providerInstance)
.bindingSelection.equals(this);
}
}
if (element instanceof Binding) {
Key<?> elementKey = ((Binding) element).getKey();
// if it isn't one of the things we bound directly it might be an actual or default key
return elementKey.equals(getKeyForActualBinding())
|| elementKey.equals(getKeyForDefaultBinding());
}
return false; // cannot match;
}
示例6: initialize
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
/**
* This will get the authoritative {@link BindingSelection} from the map provider. This
* guarantees that everyone has the same instance of the bindingSelection and sees consistent
* state.
*/
@Override
final void initialize(InjectorImpl injector, Errors errors) throws ErrorsException {
Binding<Map<K, V>> mapBinding = injector.getExistingBinding(mapKey);
ProviderInstanceBinding<Map<K, V>> providerInstanceBinding =
(ProviderInstanceBinding<Map<K, V>>) mapBinding;
@SuppressWarnings("unchecked")
RealMapProvider<K, V> mapProvider =
(RealMapProvider<K, V>) providerInstanceBinding.getUserSuppliedProvider();
this.bindingSelection = mapProvider.getBindingSelection();
if (bindingSelection.tryInitialize(injector, errors)) {
doInitialize(injector, errors);
}
}
示例7: getProviderMapEntry
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
/**
* Will find and return the {@link com.google.inject.spi.Element} that is a {@link
* ProviderMapEntry} with a key that matches the one supplied by the user in {@code k}.
*
* <p>Will return {@code null} if it cannot be found.
*/
private static com.google.inject.spi.Element getProviderMapEntry(
Object kToFind, Iterable<com.google.inject.spi.Element> elements) {
for (com.google.inject.spi.Element element : elements) {
if (element instanceof ProviderInstanceBinding) {
javax.inject.Provider<?> usp =
((ProviderInstanceBinding<?>) element).getUserSuppliedProvider();
if (usp instanceof ProviderMapEntry) {
ProviderMapEntry<?, ?> pme = (ProviderMapEntry<?, ?>) usp;
// Check if the key from the ProviderMapEntry matches the one we're looking for
if (kToFind.equals(pme.getKey())) {
return element;
}
}
}
}
// No matching ProviderMapEntry found
return null;
}
示例8: acceptExtensionVisitor
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public <B, V> V acceptExtensionVisitor(BindingTargetVisitor<B, V> visitor,
ProviderInstanceBinding<? extends B> binding) {
if(visitor instanceof ServletModuleTargetVisitor) {
if(servletInstance != null) {
return ((ServletModuleTargetVisitor<B, V>)visitor).visit(
new InstanceServletBindingImpl(initParams,
pattern,
servletInstance,
patternMatcher));
} else {
return ((ServletModuleTargetVisitor<B, V>)visitor).visit(
new LinkedServletBindingImpl(initParams,
pattern,
servletKey,
patternMatcher));
}
} else {
return visitor.visit(binding);
}
}
示例9: acceptExtensionVisitor
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public <B, V> V acceptExtensionVisitor(BindingTargetVisitor<B, V> visitor,
ProviderInstanceBinding<? extends B> binding) {
if(visitor instanceof ServletModuleTargetVisitor) {
if(filterInstance != null) {
return ((ServletModuleTargetVisitor<B, V>)visitor).visit(
new InstanceFilterBindingImpl(initParams,
pattern,
filterInstance,
patternMatcher));
} else {
return ((ServletModuleTargetVisitor<B, V>)visitor).visit(
new LinkedFilterBindingImpl(initParams,
pattern,
filterKey,
patternMatcher));
}
} else {
return visitor.visit(binding);
}
}
示例10: testGetInstanceName_providerMethod
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public void testGetInstanceName_providerMethod() throws Exception {
final ProviderMethod<?>[] methodHolder = new ProviderMethod[1];
Injector injector = Guice.createInjector(new ProvidingModule());
injector.getBinding(Integer.class).acceptTargetVisitor(
new DefaultBindingTargetVisitor<Object, Void>() {
@SuppressWarnings("unchecked") @Override
public Void visit(ProviderInstanceBinding<?> binding) {
methodHolder[0] = (ProviderMethod) binding.getUserSuppliedProvider();
return null;
}
});
assertEquals("Method provider should pretty print as the method signature",
"#provideInteger(String)", nameFactory.getInstanceName(methodHolder[0]));
}
示例11: testGetInstanceName_providerMethod
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public void testGetInstanceName_providerMethod() throws Exception {
final ProviderMethod<?>[] methodHolder = new ProviderMethod[1];
Injector injector = Guice.createInjector(new ProvidingModule());
injector.getBinding(Integer.class).acceptTargetVisitor(
new DefaultBindingTargetVisitor<Object, Void>() {
@SuppressWarnings("unchecked") @Override
public Void visit(ProviderInstanceBinding<?> binding) {
methodHolder[0] = (ProviderMethod) binding.getProviderInstance();
return null;
}
});
assertEquals("Method provider should pretty print as the method signature",
"#provideInteger(String)", nameFactory.getInstanceName(methodHolder[0]));
}
示例12: acceptExtensionVisitor
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
/**
* This is needed for 'initialize(injector)' below to be called so the provider
* can get the injector after it is instantiated.
*/
@Override
public <B, V> V acceptExtensionVisitor(
BindingTargetVisitor<B, V> visitor,
ProviderInstanceBinding<? extends B> binding) {
return visitor.visit(binding);
}
示例13: binds_provider_instance
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
@Test
public void binds_provider_instance() {
given(module = new AbstractModule() {
@Override
protected void configure() {
bind(Interface.class).toProvider(new InterfaceProvider());
}
});
given(injector = Guice.createInjector(module));
when(injector.getBinding(Interface.class));
thenReturned(instanceOf(ProviderInstanceBinding.class));
}
示例14: binds_provider_instance_from_method
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
@Test
public void binds_provider_instance_from_method() {
given(module = new AbstractModule() {
@Override
protected void configure() {}
@Provides
public Interface provide() {
return new Implementation();
}
});
given(injector = Guice.createInjector(module));
when(injector.getBinding(Interface.class));
thenReturned(instanceOf(ProviderInstanceBinding.class));
}
示例15: acceptExtensionVisitor
import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
@SuppressWarnings("unchecked") // The real type of B must be T
@Override
public <B, V> V acceptExtensionVisitor(BindingTargetVisitor<B, V> visitor, ProviderInstanceBinding<? extends B> binding) {
if (visitor instanceof ContextSensitiveBindingVisitor) {
return ((ContextSensitiveBindingVisitor<T, V>)visitor).visit(this);
} else {
return visitor.visit(binding);
}
}