@Override public Object visit(InstanceBinding<?> binding) { return binding.getInstance(); }
@Override public Void visit(InstanceBinding<? extends T> binding) { Set<InjectionPoint> injectionPoints = binding.getInjectionPoints(); T instance = binding.getInstance(); Initializable<T> ref = initializer.requestInjection( injector, instance, source, injectionPoints); ConstantFactory<? extends T> factory = new ConstantFactory<>(ref); InternalFactory<? extends T> scopedFactory = Scopes.scope(key, injector, factory, scoping); putBinding(new InstanceBindingImpl<>(injector, key, source, scopedFactory, injectionPoints, instance)); return null; }
@Override public Object visit(InstanceBinding<?> binding) { return binding.getInstance(); }
@Override public Object visit(InstanceBinding<?> binding) { return binding.getInstance(); }
@Override public Object visit(InstanceBinding<?> binding) { return binding.getInstance(); }
@Override public Object visit(InstanceBinding<?> binding) { return binding.getInstance(); }
InstanceBinding binding = (InstanceBinding) element; if (binding.getKey().getRawType().equals(valueType)) { values.put(binding.getKey(), (V) binding.getInstance()); } else if (binding.getInstance() instanceof Map.Entry) { Map.Entry entry = (Map.Entry) binding.getInstance(); Object key = entry.getKey(); Object providerValue = entry.getValue();
/** * Like {@link #assertInstanceBinding(Module, Class, Predicate)}, but filters the * classes checked by the given annotation. */ public <T> void assertInstanceBindingWithAnnotation(Module module, Class<T> to, Predicate<T> tester, Class<? extends Annotation> annotation) { List<Element> elements = Elements.getElements(module); for (Element element : elements) { if (element instanceof InstanceBinding) { InstanceBinding binding = (InstanceBinding) element; if (to.equals(binding.getKey().getTypeLiteral().getType())) { if (annotation == null || annotation.equals(binding.getKey().getAnnotationType())) { assertTrue(tester.test(to.cast(binding.getInstance()))); return; } } } else if (element instanceof ProviderInstanceBinding) { ProviderInstanceBinding binding = (ProviderInstanceBinding) element; if (to.equals(binding.getKey().getTypeLiteral().getType())) { assertTrue(tester.test(to.cast(binding.getProviderInstance().get()))); return; } } } StringBuilder s = new StringBuilder(); for (Element element : elements) { s.append(element).append("\n"); } fail("Did not find any instance binding to " + to.getName() + ". Found these bindings:\n" + s); }
@Override public Void visit(InstanceBinding<? extends T> binding) { Set<InjectionPoint> injectionPoints = binding.getInjectionPoints(); T instance = binding.getInstance(); Initializable<T> ref = initializer.requestInjection( injector, instance, source, injectionPoints); ConstantFactory<? extends T> factory = new ConstantFactory<>(ref); InternalFactory<? extends T> scopedFactory = Scopes.scope(key, injector, factory, scoping); putBinding(new InstanceBindingImpl<>(injector, key, source, scopedFactory, injectionPoints, instance)); return null; }
@Override public Void visit(InstanceBinding<? extends T> binding) { Set<InjectionPoint> injectionPoints = binding.getInjectionPoints(); T instance = binding.getInstance(); Initializable<T> ref = initializer.requestInjection( injector, instance, source, injectionPoints); ConstantFactory<? extends T> factory = new ConstantFactory<>(ref); InternalFactory<? extends T> scopedFactory = Scopes.scope(key, injector, factory, scoping); putBinding(new InstanceBindingImpl<>(injector, key, source, scopedFactory, injectionPoints, instance)); return null; }
@Override public Void visit(InstanceBinding<? extends T> binding) { Set<InjectionPoint> injectionPoints = binding.getInjectionPoints(); T instance = binding.getInstance(); Initializable<T> ref = initializer.requestInjection( injector, instance, source, injectionPoints); ConstantFactory<? extends T> factory = new ConstantFactory<>(ref); InternalFactory<? extends T> scopedFactory = Scopes.scope(key, injector, factory, scoping); putBinding(new InstanceBindingImpl<>(injector, key, source, scopedFactory, injectionPoints, instance)); return null; }
@Override public Void visit(InstanceBinding<? extends T> binding) { Set<InjectionPoint> injectionPoints = binding.getInjectionPoints(); T instance = binding.getInstance(); Initializable<T> ref = initializer.requestInjection( injector, instance, source, injectionPoints); ConstantFactory<? extends T> factory = new ConstantFactory<>(ref); InternalFactory<? extends T> scopedFactory = Scopes.scope(key, injector, factory, scoping); putBinding(new InstanceBindingImpl<>(injector, key, source, scopedFactory, injectionPoints, instance)); return null; }
/** * Configures the module, and returns an instance bound to the "to" class. */ public static <T> T bindAndGetInstance(Module module, Class<T> to) { List<Element> elements = Elements.getElements(module); for (Element element : elements) { if (element instanceof InstanceBinding) { InstanceBinding binding = (InstanceBinding) element; if (to.equals(binding.getKey().getTypeLiteral().getType())) { return to.cast(binding.getInstance()); } } else if (element instanceof ProviderInstanceBinding) { ProviderInstanceBinding binding = (ProviderInstanceBinding) element; if (to.equals(binding.getKey().getTypeLiteral().getType())) { return to.cast(binding.getProviderInstance().get()); } } } fail("can't get instance for class " + to); return null; // won't happen ;) }