use of com.google.inject.internal.ProviderMethod in project google-gin by gwtplus.
the class GuiceBindingVisitor method visit.
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);
}
use of com.google.inject.internal.ProviderMethod in project roboguice by roboguice.
the class ProviderMethodsTest method testNonModuleProviderMethods.
public void testNonModuleProviderMethods() {
final Object methodsObject = new Object() {
@Provides
@Named("foo")
String provideFoo() {
return "foo-value";
}
};
Module module = new AbstractModule() {
@Override
protected void configure() {
install(ProviderMethodsModule.forObject(methodsObject));
}
};
Injector injector = Guice.createInjector(module);
Key<String> key = Key.get(String.class, Names.named("foo"));
assertEquals("foo-value", injector.getInstance(key));
// Test the provider method object itself. This makes sure getInstance works, since GIN uses it
List<Element> elements = Elements.getElements(module);
assertEquals(1, elements.size());
Element element = elements.get(0);
assertTrue(element + " instanceof ProviderInstanceBinding", element instanceof ProviderInstanceBinding);
ProviderInstanceBinding binding = (ProviderInstanceBinding) element;
javax.inject.Provider provider = binding.getUserSuppliedProvider();
assertTrue(provider instanceof ProviderMethod);
assertEquals(methodsObject, ((ProviderMethod) provider).getInstance());
assertSame(provider, binding.getProviderInstance());
}
Aggregations