@Override public void applyTo(Binder binder) { getScoping().applyTo(binder.withSource(getSource()).bind(getKey()).to(getLinkedKey())); }
@Override public BindingImpl<T> withScoping(Scoping scoping) { return new LinkedBindingImpl<T>(getSource(), getKey(), scoping, targetKey); }
Injector injector = linkedBinding.getInjector(); if (injector != null) { binding = injector.getBinding(linkedBinding.getLinkedKey()); continue;
@Override public BindingImpl<T> withKey(Key<T> key) { return new LinkedBindingImpl<T>(getSource(), key, getScoping(), targetKey); }
@Override public int hashCode() { return Objects.hashCode(getKey(), getScoping(), targetKey); } }
@Override public String toString() { return MoreObjects.toStringHelper(LinkedKeyBinding.class) .add("key", getKey()) .add("source", getSource()) .add("scope", getScoping()) .add("target", targetKey) .toString(); }
private boolean isEagerSingleton(InjectorImpl injector, BindingImpl<?> binding, Stage stage) { if (binding.getScoping().isEagerSingleton(stage)) { return true; } // handle a corner case where a child injector links to a binding in a parent injector, and // that binding is singleton. We won't catch this otherwise because we only iterate the child's // bindings. if (binding instanceof LinkedBindingImpl) { Key<?> linkedBinding = ((LinkedBindingImpl<?>) binding).getLinkedKey(); return isEagerSingleton(injector, injector.getBinding(linkedBinding), stage); } return false; }
@Override public BindingBuilder<T> to(Key<? extends T> linkedKey) { checkNotNull(linkedKey, "linkedKey"); checkNotTargetted(); BindingImpl<T> base = getBinding(); setBinding( new LinkedBindingImpl<T>(base.getSource(), base.getKey(), base.getScoping(), linkedKey)); return this; }
@Override public String toString() { return MoreObjects.toStringHelper(LinkedKeyBinding.class) .add("key", getKey()) .add("source", getSource()) .add("scope", getScoping()) .add("target", targetKey) .toString(); }
@Override public BindingImpl<T> withKey(Key<T> key) { return new LinkedBindingImpl<T>(getSource(), key, getScoping(), targetKey); }
@Override public boolean equals(Object obj) { if (obj instanceof LinkedBindingImpl) { LinkedBindingImpl<?> o = (LinkedBindingImpl<?>) obj; return getKey().equals(o.getKey()) && getScoping().equals(o.getScoping()) && Objects.equal(targetKey, o.targetKey); } else { return false; } }
private <X> By getSelectorFromComponent(Class<X> component) { By selector = null; if (component.isAnnotationPresent( PageObjectInterface.class)) { Binding<?> binding = pageObjectInjector.getOriginalInjector().getBinding(component); if (binding instanceof LinkedBindingImpl) { selector = PageObjectProviderHelper .retrieveSelectorFromPageObjectInterface( ((LinkedBindingImpl) binding).getLinkedKey().getTypeLiteral().getRawType()); } } else { selector = PageObjectProviderHelper.retrieveSelectorFromPageObjectInterface(component); } return selector; } }
/** Creates a binding for a type annotated with @ImplementedBy. */ private <T> BindingImpl<T> createImplementedByBinding( Key<T> key, Scoping scoping, ImplementedBy implementedBy, Errors errors) throws ErrorsException { Class<?> rawType = key.getTypeLiteral().getRawType(); Class<?> implementationType = implementedBy.value(); // Make sure it's not the same type. TODO: Can we check for deeper cycles? if (implementationType == rawType) { throw errors.recursiveImplementationType().toException(); } // Make sure implementationType extends type. if (!rawType.isAssignableFrom(implementationType)) { throw errors.notASubtype(implementationType, rawType).toException(); } @SuppressWarnings("unchecked") // After the preceding check, this cast is safe. Class<? extends T> subclass = (Class<? extends T>) implementationType; // Look up the target binding. final Key<? extends T> targetKey = Key.get(subclass); Object source = rawType; FactoryProxy<T> factory = new FactoryProxy<>(this, key, targetKey, source); factory.notify(errors); // causes the factory to initialize itself internally return new LinkedBindingImpl<T>( this, key, source, Scoping.<T>scope(key, this, factory, source, scoping), scoping, targetKey); }
@Override public void applyTo(Binder binder) { getScoping().applyTo(binder.withSource(getSource()).bind(getKey()).to(getLinkedKey())); }
@Override public String toString() { return MoreObjects.toStringHelper(LinkedKeyBinding.class) .add("key", getKey()) .add("source", getSource()) .add("scope", getScoping()) .add("target", targetKey) .toString(); }
@Override public BindingImpl<T> withScoping(Scoping scoping) { return new LinkedBindingImpl<T>(getSource(), getKey(), scoping, targetKey); }
@Override public BindingImpl<T> withKey(Key<T> key) { return new LinkedBindingImpl<T>(getSource(), key, getScoping(), targetKey); }
Injector injector = linkedBinding.getInjector(); if (injector != null) { binding = injector.getBinding(linkedBinding.getLinkedKey()); continue;
@Override public int hashCode() { return Objects.hashCode(getKey(), getScoping(), targetKey); } }
protected <X> By getSelectorFromComponent(Class<X> component) { By selector = null; if (component.isAnnotationPresent( PageObjectInterface.class)) { Binding<?> binding = pageObjectInjector.getOriginalInjector().getBinding(component); if (binding instanceof LinkedBindingImpl) { selector = PageObjectProviderHelper .retrieveSelectorFromPageObjectInterface( ((LinkedBindingImpl) binding).getLinkedKey().getTypeLiteral().getRawType()); } } else { selector = PageObjectProviderHelper.retrieveSelectorFromPageObjectInterface(component); } return selector; }