public boolean containsElement(com.google.inject.spi.Element element) { if (mapBinder.containsElement(element)) { return true; } else { Key<?> elementKey; if (element instanceof Binding) { elementKey = ((Binding<?>) element).getKey(); } else if (element instanceof ProviderLookup) { elementKey = ((ProviderLookup<?>) element).getKey(); } else { return false; // cannot match; } return elementKey.equals(optionalKey) || elementKey.equals(optionalProviderKey) || elementKey.equals(optionalJavaxProviderKey) || matchesTypeKey(element, elementKey) || matchesUserBinding(elementKey); } }
boolean containsElement(com.google.inject.spi.Element element) { if (entrySetBinder.containsElement(element)) { return true; } else { Key<?> key; if (element instanceof Binding) { key = ((Binding<?>)element).getKey(); } else if (element instanceof ProviderLookup) { key = ((ProviderLookup<?>)element).getKey(); } else { return false; // cannot match; } return key.equals(mapKey) || key.equals(providerMapKey) || key.equals(javaxProviderMapKey) || key.equals(multimapKey) || key.equals(providerMultimapKey) || key.equals(entrySetBinder.getSetKey()) || matchesValueKey(key); } }
@Override public <T> Void visit(ProviderLookup<T> providerLookup) { dependencyAnalyzer.addDependency(providerLookup.getKey()); providerLookup.applyTo(binder); return null; }
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(); }
@Override public <T> Boolean visit(ProviderLookup<T> lookup) { // ensure the provider can be created try { Provider<T> provider = injector.getProviderOrThrow(lookup.getDependency(), errors); lookup.initializeDelegate(provider); } catch (ErrorsException e) { errors.merge(e.getErrors()); // TODO: source } return true; }
@Override public <T> Boolean visit(ProviderLookup<T> lookup) { // ensure the provider can be created try { Provider<T> provider = injector.getProviderOrThrow(lookup.getKey(), errors); lookup.initializeDelegate(provider); } catch (ErrorsException e) { errors.merge(e.getErrors()); // TODO: source } return true; }
@Override public <T> V visit(ProviderLookup<T> lookup) { return message(lookup, "Looking up provider " + lookup.getProvider() + " for key " + lookup.getKey()); }
@Override public <T> Object visit(ProviderLookup<T> providerLookup) { processDependency(providerLookup.getDependency()); return super.visit(providerLookup); }
public <T> Void visit(ProviderLookup<T> providerLookup) { // Ignore provider lookups for now // TODO(bstoler): I guess we should error if you try to lookup a provider // that is not bound? return null; }
@Override public <T> Provider<T> getProvider(Key<T> key) { ProviderLookup<T> lookup = new ProviderLookup<>(key, key); lookups.add(lookup); return lookup.getProvider(); }
public <T> Provider<T> getProvider(Key<T> key) { ProviderLookup<T> lookup = new ProviderLookup<T>(key, key); lookups.add(lookup); return lookup.getProvider(); }