use of org.elasticsearch.common.inject.internal.ErrorsException in project crate by crate.
the class InjectorImpl method createJustInTimeBinding.
/**
* Returns a new just-in-time binding created by resolving {@code key}. The strategies used to
* create just-in-time bindings are:
* <ol>
* <li>Internalizing Providers. If the requested binding is for {@code Provider<T>}, we delegate
* to the binding for {@code T}.
* <li>Converting constants.
* <li>ImplementedBy and ProvidedBy annotations. Only for unannotated keys.
* <li>The constructor of the raw type. Only for unannotated keys.
* </ol>
*
* @throws org.elasticsearch.common.inject.internal.ErrorsException
* if the binding cannot be created.
*/
<T> BindingImpl<T> createJustInTimeBinding(Key<T> key, Errors errors) throws ErrorsException {
if (state.isBlacklisted(key)) {
throw errors.childBindingAlreadySet(key).toException();
}
// Handle cases where T is a Provider<?>.
if (isProvider(key)) {
// These casts are safe. We know T extends Provider<X> and that given Key<Provider<X>>,
// createProviderBinding() will return BindingImpl<Provider<X>>.
@SuppressWarnings("unchecked") BindingImpl binding = createProviderBinding((Key) key, errors);
return binding;
}
// Handle cases where T is a MembersInjector<?>
if (isMembersInjector(key)) {
// These casts are safe. T extends MembersInjector<X> and that given Key<MembersInjector<X>>,
// createMembersInjectorBinding() will return BindingImpl<MembersInjector<X>>.
@SuppressWarnings("unchecked") BindingImpl binding = createMembersInjectorBinding((Key) key, errors);
return binding;
}
// Try to convert a constant string binding to the requested type.
BindingImpl<T> convertedBinding = convertConstantStringBinding(key, errors);
if (convertedBinding != null) {
return convertedBinding;
}
// If the key has an annotation...
if (key.hasAnnotationType()) {
// Look for a binding without annotation attributes or return null.
if (key.hasAttributes()) {
try {
Errors ignored = new Errors();
return getBindingOrThrow(key.withoutAttributes(), ignored);
} catch (ErrorsException ignored) {
// throw with a more appropriate message below
}
}
throw errors.missingImplementation(key).toException();
}
Object source = key.getTypeLiteral().getRawType();
BindingImpl<T> binding = createUnitializedBinding(key, Scoping.UNSCOPED, source, errors);
initializeBinding(binding, errors);
return binding;
}
use of org.elasticsearch.common.inject.internal.ErrorsException in project crate by crate.
the class MembersInjectorStore method getInjectors.
/**
* Returns the injectors for the specified injection points.
*/
List<SingleMemberInjector> getInjectors(Set<InjectionPoint> injectionPoints, Errors errors) {
List<SingleMemberInjector> injectors = new ArrayList<>();
for (InjectionPoint injectionPoint : injectionPoints) {
try {
Errors errorsForMember = injectionPoint.isOptional() ? new Errors(injectionPoint) : errors.withSource(injectionPoint);
SingleMemberInjector injector = injectionPoint.getMember() instanceof Field ? new SingleFieldInjector(this.injector, injectionPoint, errorsForMember) : new SingleMethodInjector(this.injector, injectionPoint, errorsForMember);
injectors.add(injector);
} catch (ErrorsException ignoredForNow) {
// ignored for now
}
}
return Collections.unmodifiableList(injectors);
}
use of org.elasticsearch.common.inject.internal.ErrorsException in project crate by crate.
the class MembersInjectorImpl method injectMembers.
@Override
public void injectMembers(T instance) {
Errors errors = new Errors(typeLiteral);
try {
injectAndNotify(instance, errors);
} catch (ErrorsException e) {
errors.merge(e.getErrors());
}
errors.throwProvisionExceptionIfErrorsExist();
}
Aggregations