protected Binding(String provideKey, String membersKey, boolean singleton, Object requiredBy) { if (singleton && provideKey == null) { throw new InvalidBindingException(Keys.getClassName(membersKey), "is exclusively members injected and therefore cannot be scoped"); } this.provideKey = provideKey; this.membersKey = membersKey; this.requiredBy = requiredBy; this.bits = (singleton ? SINGLETON : 0); }
@Test public void testGetClassName() throws NoSuchFieldException { assertThat(Keys.getClassName(fieldKey("className"))) .isEqualTo("java.lang.String"); }
@Test public void testGetClassNameWithoutAnnotation() throws NoSuchFieldException { assertThat(Keys.getClassName(fieldKey("classNameWithAnnotation"))) .isEqualTo("java.lang.String"); }
@Test public void testGetClassParameterized() throws NoSuchFieldException { assertThat(Keys.getClassName(fieldKey("classNameParameterized"))).isNull(); }
@Test public void testGetClassNameArray() throws NoSuchFieldException { assertThat(Keys.getClassName(fieldKey("classNameArray"))).isNull(); }
String className = Keys.getClassName(key); if (className == null) { throw new InvalidBindingException(key,
/** * Creates a just-in-time binding for the key in {@code deferred}. The type of binding * to be created depends on the key's type: * <ul> * <li>Injections of {@code Provider<Foo>}, {@code MembersInjector<Bar>}, and * {@code Lazy<Blah>} will delegate to the bindings of {@code Foo}, {@code Bar}, and * {@code Blah} respectively. * <li>Injections of other types will use the injectable constructors of those classes. * </ul> */ private Binding<?> createJitBinding(String key, Object requiredBy, boolean mustBeInjectable) throws ClassNotFoundException { String builtInBindingsKey = Keys.getBuiltInBindingsKey(key); if (builtInBindingsKey != null) { return new BuiltInBinding<Object>(key, requiredBy, builtInBindingsKey); } String lazyKey = Keys.getLazyKey(key); if (lazyKey != null) { return new LazyBinding<Object>(key, requiredBy, lazyKey); } String className = Keys.getClassName(key); if (className != null && !Keys.isAnnotated(key)) { Binding<?> atInjectBinding = plugin.getAtInjectBinding(key, className, mustBeInjectable); if (atInjectBinding != null) { return atInjectBinding; } } throw new IllegalArgumentException("No binding for " + key); }