本文整理汇总了Java中com.google.inject.internal.ProviderMethodsModule类的典型用法代码示例。如果您正苦于以下问题:Java ProviderMethodsModule类的具体用法?Java ProviderMethodsModule怎么用?Java ProviderMethodsModule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProviderMethodsModule类属于com.google.inject.internal包,在下文中一共展示了ProviderMethodsModule类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scanForAnnotatedMethods
import com.google.inject.internal.ProviderMethodsModule; //导入依赖的package包/类
/**
* Applies all scanners to the modules we've installed. We skip certain PrivateModules because
* store them in more than one Modules map and only want to process them through one of the
* maps. (They're stored in both maps to prevent a module from being installed more than once.)
*/
void scanForAnnotatedMethods() {
for (ModuleAnnotatedMethodScanner scanner : scanners) {
// Note: we must iterate over a copy of the modules because calling install(..)
// will mutate modules, otherwise causing a ConcurrentModificationException.
for (Map.Entry<Module, ModuleInfo> entry : Maps.newLinkedHashMap(modules).entrySet()) {
Module module = entry.getKey();
ModuleInfo info = entry.getValue();
if (info.skipScanning) {
continue;
}
moduleSource = entry.getValue().moduleSource;
try {
info.binder.install(ProviderMethodsModule.forModule(module, scanner));
} catch (RuntimeException e) {
Collection<Message> messages = Errors.getMessagesFromThrowable(e);
if (!messages.isEmpty()) {
elements.addAll(messages);
} else {
addError(e);
}
}
}
}
moduleSource = null;
}
示例2: install
import com.google.inject.internal.ProviderMethodsModule; //导入依赖的package包/类
public void install(Module module) {
if (modules.add(module)) {
Binder binder = this;
if (module instanceof PrivateModule) {
binder = binder.newPrivateBinder();
}
try {
module.configure(binder);
} catch (RuntimeException e) {
Collection<Message> messages = Errors.getMessagesFromThrowable(e);
if (!messages.isEmpty()) {
elements.addAll(messages);
} else {
addError(e);
}
}
binder.install(ProviderMethodsModule.forModule(module));
}
}
示例3: configure
import com.google.inject.internal.ProviderMethodsModule; //导入依赖的package包/类
public void configure(Binder binder) {
// For Guice error reporting, ignore the adapters
binder = binder.skipSources(GinModuleAdapter.class, BinderAdapter.class,
AbstractGinModule.class);
ginModule.configure(new BinderAdapter(binder, bindings));
// Install provider methods from the GinModule
binder.install(ProviderMethodsModule.forObject(ginModule));
}
示例4: configure
import com.google.inject.internal.ProviderMethodsModule; //导入依赖的package包/类
public void configure() {
Binder binder = binder().skipSources(PrivateGinModuleAdapter.class,
BinderAdapter.class, PrivateBinderAdapter.class, PrivateGinModule.class);
ginModule.configure(new PrivateBinderAdapter((PrivateBinder) binder,
bindings == null ? null : bindings.createChildGinjectorBindings(ginModule.getClass())));
// Install provider methods from the GinModule
binder.install(ProviderMethodsModule.forObject(ginModule));
}
示例5: testNonModuleProviderMethods
import com.google.inject.internal.ProviderMethodsModule; //导入依赖的package包/类
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());
}
示例6: install
import com.google.inject.internal.ProviderMethodsModule; //导入依赖的package包/类
public void install(Module module) {
if (modules.add(module)) {
Binder binder = this;
// Update the module source for the new module
if (!(module instanceof ProviderMethodsModule)) {
moduleSource = getModuleSource(module);
}
if (module instanceof PrivateModule) {
binder = binder.newPrivateBinder();
}
try {
module.configure(binder);
} catch (RuntimeException e) {
Collection<Message> messages = Errors.getMessagesFromThrowable(e);
if (!messages.isEmpty()) {
elements.addAll(messages);
} else {
addError(e);
}
}
binder.install(ProviderMethodsModule.forModule(module));
// We are done with this module, so undo module source change
if (!(module instanceof ProviderMethodsModule)) {
moduleSource = moduleSource.getParent();
}
}
}
示例7: testNonModuleProviderMethods
import com.google.inject.internal.ProviderMethodsModule; //导入依赖的package包/类
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();
assertEquals(ProviderMethod.class, provider.getClass());
assertEquals(methodsObject, ((ProviderMethod) provider).getInstance());
assertSame(provider, binding.getProviderInstance());
}
示例8: testNonModuleProviderMethods
import com.google.inject.internal.ProviderMethodsModule; //导入依赖的package包/类
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;
Provider provider = binding.getProviderInstance();
assertEquals(ProviderMethod.class, provider.getClass());
assertEquals(methodsObject, ((ProviderMethod) provider).getInstance());
}
示例9: configure
import com.google.inject.internal.ProviderMethodsModule; //导入依赖的package包/类
@Override
public void configure(Binder binder) {
for (Object module : daggerModuleObjects) {
binder.install(ProviderMethodsModule.forModule(module, DaggerMethodScanner.INSTANCE));
}
}
示例10: install
import com.google.inject.internal.ProviderMethodsModule; //导入依赖的package包/类
@Override
public void install(Module module) {
if (!modules.containsKey(module)) {
RecordingBinder binder = this;
boolean unwrapModuleSource = false;
// Update the module source for the new module
if (module instanceof ProviderMethodsModule) {
// There are two reason's we'd want to get the module source in a ProviderMethodsModule.
// ModuleAnnotatedMethodScanner lets users scan their own modules for @Provides-like
// bindings. If they install the module at a top-level, then moduleSource can be null.
// Also, if they pass something other than 'this' to it, we'd have the wrong source.
Object delegate = ((ProviderMethodsModule) module).getDelegateModule();
if (moduleSource == null
|| !moduleSource.getModuleClassName().equals(delegate.getClass().getName())) {
moduleSource = getModuleSource(delegate);
unwrapModuleSource = true;
}
} else {
moduleSource = getModuleSource(module);
unwrapModuleSource = true;
}
boolean skipScanning = false;
if (module instanceof PrivateModule) {
binder = (RecordingBinder) binder.newPrivateBinder();
// Store the module in the private binder too so we scan for it.
binder.modules.put(module, new ModuleInfo(binder, moduleSource, false));
skipScanning = true; // don't scan this module in the parent's module set.
}
// Always store this in the parent binder (even if it was a private module)
// so that we know not to process it again, and so that scanners inherit down.
modules.put(module, new ModuleInfo(binder, moduleSource, skipScanning));
try {
module.configure(binder);
} catch (RuntimeException e) {
Collection<Message> messages = Errors.getMessagesFromThrowable(e);
if (!messages.isEmpty()) {
elements.addAll(messages);
} else {
addError(e);
}
}
binder.install(ProviderMethodsModule.forModule(module));
// We are done with this module, so undo module source change
if (unwrapModuleSource) {
moduleSource = moduleSource.getParent();
}
}
}
示例11: providerMethodsModule
import com.google.inject.internal.ProviderMethodsModule; //导入依赖的package包/类
/**
* HACK!
*
* Scan the given module for methods annotated with {@link ProvidesGeneric} and generate provider methods
* from them. This works exactly like Guice's built-in provider methods, except that the owner type can
* be specified explicitly, allowing for generic provider methods.
*
* HACK: Reflectively change the module type in ProviderMethodsModule, before it scans for provider methods.
* This allows the actual type of a generic module to be provided at runtime.
*/
public static <T extends Module> Module providerMethodsModule(T hostModule, TypeLiteral<T> type) {
final ProviderMethodsModule module = (ProviderMethodsModule) ProviderMethodsModule.forModule(hostModule, SCANNER);
ProviderMethodsModule_typeLiteral.set(module, type);
return module;
}