@Override public Indexer.IndexedBinding visit(ProviderInstanceBinding<? extends Object> binding) { return new Indexer.IndexedBinding( binding, BindingType.PROVIDER_INSTANCE, scope(binding), binding.getUserSuppliedProvider()); }
/** * 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); } }
ProviderMapEntry<K, V> entry = (ProviderMapEntry) entryBinding.getUserSuppliedProvider(); K key = entry.getKey();
(Provider<Map.Entry<K, Provider<V>>>) entryBinding.getUserSuppliedProvider(); Provider<Map.Entry<K, Provider<V>>> userSuppliedProvider = typedProvider;
/** 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; }
if (Void.class.equals(rawType)) { if (command instanceof ProviderInstanceBinding && ((ProviderInstanceBinding) command).getUserSuppliedProvider() instanceof ProviderMethod) { errors.voidProviderMethod();
@Override public Boolean visit(ProviderInstanceBinding<? extends T> binding) { prepareBinding(); javax.inject.Provider<? extends T> provider = binding.getUserSuppliedProvider(); if (provider instanceof InternalProviderInstanceBindingImpl.Factory) { @SuppressWarnings("unchecked") InternalProviderInstanceBindingImpl.Factory<T> asProviderMethod = (InternalProviderInstanceBindingImpl.Factory<T>) provider; return visitInternalProviderInstanceBindingFactory(asProviderMethod); } Set<InjectionPoint> injectionPoints = binding.getInjectionPoints(); Initializable<? extends javax.inject.Provider<? extends T>> initializable = initializer.<javax.inject.Provider<? extends T>>requestInjection( injector, provider, null, source, injectionPoints); // always visited with Binding<T> @SuppressWarnings("unchecked") InternalFactory<T> factory = new InternalFactoryToInitializableAdapter<T>( initializable, source, injector.provisionListenerStore.get((ProviderInstanceBinding<T>) binding)); InternalFactory<? extends T> scopedFactory = Scoping.scope(key, injector, factory, source, scoping); putBinding( new ProviderInstanceBindingImpl<T>( injector, key, source, scopedFactory, scoping, provider, injectionPoints)); return true; }
/** * Returns true if the key & element indicate they were bound by this OptionalBinder. */ private boolean matchesTypeKey(Element element, Key<?> elementKey) { // Just doing .equals(typeKey) isn't enough, because the user can bind that themselves. return elementKey.equals(typeKey) && element instanceof ProviderInstanceBinding && (((ProviderInstanceBinding) element) .getUserSuppliedProvider() instanceof RealOptionalBinderProviderWithDependencies); }
@SuppressWarnings("unchecked") @Override public Void visit(ProviderInstanceBinding<?> binding) { methodHolder[0] = (ProviderMethod) binding.getUserSuppliedProvider(); return null; } });
/** * Same as {@link #visit(InstanceBinding)}, but the binding edge is {@link * BindingEdgeType#PROVIDER}. */ @Override public Collection<Node> visit(ProviderInstanceBinding<?> binding) { return ImmutableList.<Node>of( newInterfaceNode(binding), newInstanceNode(binding, binding.getUserSuppliedProvider())); }
@Override public Indexer.IndexedBinding visit(ProviderInstanceBinding<? extends Object> binding) { return new Indexer.IndexedBinding( binding, BindingType.PROVIDER_INSTANCE, scope(binding), binding.getUserSuppliedProvider()); }
@Override public Indexer.IndexedBinding visit(ProviderInstanceBinding<? extends Object> binding) { return new Indexer.IndexedBinding( binding, BindingType.PROVIDER_INSTANCE, scope(binding), binding.getUserSuppliedProvider()); }
@Override public IndexedBinding visit(ProviderInstanceBinding<? extends Object> binding) { return new IndexedBinding(binding, BindingType.PROVIDER_INSTANCE, scope(binding), binding.getUserSuppliedProvider()); }
/** * 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); } }
/** * 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); } }
/** 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; }
/** 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; }
@Override public <T> Void visit(Binding<T> binding) { if (binding instanceof InstanceBinding) { InstanceBinding<T> instanceBinding = (InstanceBinding<T>) binding; // configuration listener if (instanceBinding.getInstance() instanceof ConfigurationBindingListenerHolder) { addConfigurationBindingListener(((ConfigurationBindingListenerHolder) instanceBinding.getInstance()).getConfigurationBindingListener()); } // config defaults if (instanceBinding.getInstance() instanceof ConfigDefaultsHolder) { registerConfigDefaults((ConfigDefaultsHolder<?>) instanceBinding.getInstance()); } } // configuration provider if (binding instanceof ProviderInstanceBinding) { ProviderInstanceBinding<?> providerInstanceBinding = (ProviderInstanceBinding<?>) binding; Provider<?> provider = providerInstanceBinding.getUserSuppliedProvider(); if (provider instanceof ConfigurationProvider) { registerConfigurationProvider((ConfigurationProvider<?>) provider, Optional.of(binding.getSource())); } } return null; } });
@Override public <T> Void visit(Binding<T> binding) { if (binding instanceof InstanceBinding) { InstanceBinding<T> instanceBinding = (InstanceBinding<T>) binding; // configuration listener if (instanceBinding.getInstance() instanceof ConfigurationBindingListenerHolder) { addConfigurationBindingListener(((ConfigurationBindingListenerHolder) instanceBinding.getInstance()).getConfigurationBindingListener()); } // config defaults if (instanceBinding.getInstance() instanceof ConfigDefaultsHolder) { registerConfigDefaults((ConfigDefaultsHolder<?>) instanceBinding.getInstance()); } } // configuration provider if (binding instanceof ProviderInstanceBinding) { ProviderInstanceBinding<?> providerInstanceBinding = (ProviderInstanceBinding<?>) binding; Provider<?> provider = providerInstanceBinding.getUserSuppliedProvider(); if (provider instanceof ConfigurationProvider) { registerConfigurationProvider((ConfigurationProvider<?>) provider, Optional.of(binding.getSource())); } } return null; } });
@Override public Boolean visit(ProviderInstanceBinding<? extends T> binding) { prepareBinding(); javax.inject.Provider<? extends T> provider = binding.getUserSuppliedProvider(); Set<InjectionPoint> injectionPoints = binding.getInjectionPoints(); Initializable<? extends javax.inject.Provider<? extends T>> initializable = initializer.<javax.inject.Provider<? extends T>>requestInjection( injector, provider, null, source, injectionPoints); // always visited with Binding<T> @SuppressWarnings("unchecked") InternalFactory<T> factory = new InternalFactoryToInitializableAdapter<T>( initializable, source, injector.provisionListenerStore.get((ProviderInstanceBinding<T>) binding)); InternalFactory<? extends T> scopedFactory = Scoping.scope(key, injector, factory, source, scoping); putBinding(new ProviderInstanceBindingImpl<T>(injector, key, source, scopedFactory, scoping, provider, injectionPoints)); return true; }