com.google.inject.internal.UntargettedBindingProcessor Maven / Gradle / Ivy
package com.google.inject.internal;
import com.google.inject.Binding;
import com.google.inject.spi.UntargettedBinding;
/**
* Processes just UntargettedBindings.
*
*/
class UntargettedBindingProcessor extends AbstractBindingProcessor {
UntargettedBindingProcessor(Errors errors, ProcessedBindingData bindingData) {
super(errors, bindingData);
}
@Override
public Boolean visit(Binding binding) {
return binding.acceptTargetVisitor(new Processor((BindingImpl) binding) {
@Override
public Boolean visit(UntargettedBinding extends T> untargetted) {
prepareBinding();
// Error: Missing implementation.
// Example: bind(Date.class).annotatedWith(Red.class);
// We can't assume abstract types aren't injectable. They may have an
// @ImplementedBy annotation or something.
if (key.getAnnotationType() != null) {
errors.missingImplementation(key);
putBinding(invalidBinding(injector, key, source));
return true;
}
// This cast is safe after the preceeding check.
try {
BindingImpl binding = injector.createUninitializedBinding(
key, scoping, source, errors, false);
scheduleInitialization(binding);
putBinding(binding);
} catch (ErrorsException e) {
errors.merge(e.getErrors());
putBinding(invalidBinding(injector, key, source));
}
return true;
}
@Override
protected Boolean visitOther(Binding extends T> binding) {
return false;
}
});
}
}