use of org.elasticsearch.common.inject.spi.InjectionPoint in project elasticsearch by elastic.
the class ConstructorInjectorStore method createConstructor.
private <T> ConstructorInjector<T> createConstructor(TypeLiteral<T> type, Errors errors) throws ErrorsException {
int numErrorsBefore = errors.size();
InjectionPoint injectionPoint;
try {
injectionPoint = InjectionPoint.forConstructorOf(type);
} catch (ConfigurationException e) {
errors.merge(e.getErrorMessages());
throw errors.toException();
}
SingleParameterInjector<?>[] constructorParameterInjectors = injector.getParametersInjectors(injectionPoint.getDependencies(), errors);
MembersInjectorImpl<T> membersInjector = injector.membersInjectorStore.get(type, errors);
ConstructionProxyFactory<T> factory = new DefaultConstructionProxyFactory<>(injectionPoint);
errors.throwIfNewErrors(numErrorsBefore);
return new ConstructorInjector<>(membersInjector.getInjectionPoints(), factory.create(), constructorParameterInjectors, membersInjector);
}
use of org.elasticsearch.common.inject.spi.InjectionPoint in project elasticsearch by elastic.
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.spi.InjectionPoint in project elasticsearch by elastic.
the class Errors method formatSource.
public static void formatSource(Formatter formatter, Object source) {
if (source instanceof Dependency) {
Dependency<?> dependency = (Dependency<?>) source;
InjectionPoint injectionPoint = dependency.getInjectionPoint();
if (injectionPoint != null) {
formatInjectionPoint(formatter, dependency, injectionPoint);
} else {
formatSource(formatter, dependency.getKey());
}
} else if (source instanceof InjectionPoint) {
formatInjectionPoint(formatter, null, (InjectionPoint) source);
} else if (source instanceof Class) {
formatter.format(" at %s%n", StackTraceElements.forType((Class<?>) source));
} else if (source instanceof Member) {
formatter.format(" at %s%n", StackTraceElements.forMember((Member) source));
} else if (source instanceof TypeLiteral) {
formatter.format(" while locating %s%n", source);
} else if (source instanceof Key) {
Key<?> key = (Key<?>) source;
formatter.format(" while locating %s%n", convert(key));
} else {
formatter.format(" at %s%n", source);
}
}
use of org.elasticsearch.common.inject.spi.InjectionPoint in project elasticsearch by elastic.
the class MembersInjectorStore method createWithListeners.
/**
* Creates a new members injector and attaches both injection listeners and method aspects.
*/
private <T> MembersInjectorImpl<T> createWithListeners(TypeLiteral<T> type, Errors errors) throws ErrorsException {
int numErrorsBefore = errors.size();
Set<InjectionPoint> injectionPoints;
try {
injectionPoints = InjectionPoint.forInstanceMethodsAndFields(type);
} catch (ConfigurationException e) {
errors.merge(e.getErrorMessages());
injectionPoints = e.getPartialValue();
}
List<SingleMemberInjector> injectors = getInjectors(injectionPoints, errors);
errors.throwIfNewErrors(numErrorsBefore);
EncounterImpl<T> encounter = new EncounterImpl<>(errors, injector.lookups);
for (TypeListenerBinding typeListener : typeListenerBindings) {
if (typeListener.getTypeMatcher().matches(type)) {
try {
typeListener.getListener().hear(type, encounter);
} catch (RuntimeException e) {
errors.errorNotifyingTypeListener(typeListener, type, e);
}
}
}
encounter.invalidate();
errors.throwIfNewErrors(numErrorsBefore);
return new MembersInjectorImpl<>(injector, type, encounter, injectors);
}
Aggregations