com.google.inject.spi.DefaultElementVisitor Java Examples
The following examples show how to use
com.google.inject.spi.DefaultElementVisitor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModuleTester.java From mail-importer with Apache License 2.0 | 5 votes |
public void assertAllDependenciesDeclared() { List<Key> requiredKeys = new ArrayList<>(); List<Element> elements = Elements.getElements(module); for (Element element : elements) { element.acceptVisitor(new DefaultElementVisitor<Void>() { @Override public <T> Void visit(ProviderLookup<T> providerLookup) { // Required keys are the only ones with null injection points. if (providerLookup.getDependency().getInjectionPoint() == null) { requiredKeys.add(providerLookup.getKey()); } return null; } }); } Injector injector = Guice.createInjector(module, new AbstractModule() { @Override @SuppressWarnings("unchecked") protected void configure() { binder().disableCircularProxies(); binder().requireAtInjectOnConstructors(); binder().requireExactBindingAnnotations(); for (Key<?> key : requiredKeys) { bind((Key) key).toProvider(Providers.of(null)); } } }); injector.getAllBindings(); }