key = Key.get(beanBinding.type, i.next());
}
else {
key = Key.get(beanBinding.type);
}
LinkedBindingBuilder b = bind(key);
//
ScopedBindingBuilder c;
if (beanBinding instanceof BeanBinding.ToInstance) {
BeanBinding.ToInstance d = (BeanBinding.ToInstance)beanBinding;
b.toInstance(d.instance);
c = b;
}
else if (beanBinding instanceof BeanBinding.ToProviderInstance) {
BeanBinding.ToProviderInstance d = (BeanBinding.ToProviderInstance)beanBinding;
c = b.toProvider(d);
if (beanBinding.scopeType != null) {
c.in(beanBinding.scopeType);
}
}
else {
if (beanBinding instanceof BeanBinding.ToProviderType) {
BeanBinding.ToProviderType d = (BeanBinding.ToProviderType)beanBinding;
c = b.toProvider(d.provider);
}
else {
BeanBinding.ToType d = (BeanBinding.ToType)beanBinding;
if (d.qualifiers != null) {
if (d.implementationType != null) {
c = b.to(d.implementationType);
// Guice trick : need to bind alias so the implementation type will be bound with the qualifier
bind(Key.get(d.implementationType, key.getAnnotation())).toProvider(new BeanAlias(key));
}
else {
c = b.to(beanBinding.type);
}
}
else {
if (d.implementationType != null) {
c = b.to(d.implementationType);
}
else {
c = b;
}
}