use of io.quarkus.arc.processor.InjectionPointInfo in project camel-quarkus by apache.
the class InjectionPointsProcessor method injectedComponents.
@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep
void injectedComponents(CombinedIndexBuildItem index, InjectionPointsRecorder recorder, BeanRegistrationPhaseBuildItem beanRegistrationPhase, BuildProducer<SyntheticBeanBuildItem> syntheticBeans, BuildProducer<CamelRuntimeTaskBuildItem> runtimeTasks, BuildProducer<BeanRegistrationPhaseBuildItem.BeanConfiguratorBuildItem> beanConfigurator) {
final Collection<ClassInfo> components = index.getIndex().getAllKnownImplementors(INTERFACE_NAME_COMPONENT);
final Set<String> created = new HashSet<>();
for (InjectionPointInfo injectionPoint : beanRegistrationPhase.getContext().get(BuildExtension.Key.INJECTION_POINTS)) {
if (injectionPoint.getTarget().kind() == AnnotationTarget.Kind.FIELD) {
FieldInfo target = injectionPoint.getTarget().asField();
if (!created.add(target.type().name().toString())) {
continue;
}
if (components.stream().anyMatch(ci -> Objects.equals(ci.name(), target.type().name()))) {
final AnnotationInstance named = target.annotation(ANNOTATION_NAME_NAMED);
final String componentName = named == null ? target.name() : named.value().asString();
final Supplier<?> creator = recorder.componentSupplier(componentName, target.type().toString());
LOGGER.debugf("Creating synthetic component bean [name=%s, type=%s]", componentName, target.type().name());
syntheticBeans.produce(syntheticBean(target.type().name(), creator));
}
}
if (injectionPoint.getTarget().kind() == AnnotationTarget.Kind.METHOD) {
final MethodInfo target = injectionPoint.getTarget().asMethod();
final List<Type> types = target.parameters();
for (int i = 0; i < types.size(); i++) {
Type type = types.get(0);
if (!created.add(type.name().toString())) {
continue;
}
if (components.stream().anyMatch(ci -> Objects.equals(ci.name(), type.name()))) {
final AnnotationInstance named = target.annotation(ANNOTATION_NAME_NAMED);
final String componentName = named == null ? target.parameterName(i) : named.value().asString();
final Supplier<?> creator = recorder.componentSupplier(componentName, type.toString());
LOGGER.debugf("Creating synthetic component bean [name=%s, type=%s]", componentName, type.name());
syntheticBeans.produce(syntheticBean(type.name(), creator));
}
}
}
}
// Ensure the task is executed before the runtime is assembled
runtimeTasks.produce(new CamelRuntimeTaskBuildItem("components-injection"));
// Methods using BeanRegistrationPhaseBuildItem should return/produce a BeanConfiguratorBuildItem
// otherwise the build step may be processed at the wrong time.
//
// See BeanRegistrationPhaseBuildItem javadoc
beanConfigurator.produce(new BeanRegistrationPhaseBuildItem.BeanConfiguratorBuildItem());
}
use of io.quarkus.arc.processor.InjectionPointInfo in project myfaces by apache.
the class ManagedPropertyBuildStep method build.
public static void build(BeanRegistrationPhaseBuildItem beanRegistrationPhase, BuildProducer<BeanRegistrationPhaseBuildItem.BeanConfiguratorBuildItem> beanConfigurators) {
for (InjectionPointInfo injectionPoint : beanRegistrationPhase.getContext().get(BuildExtension.Key.INJECTION_POINTS)) {
if (injectionPoint.hasDefaultedQualifier()) {
// Defaulted qualifier means no @ManagedProperty
continue;
}
AnnotationInstance managedProperty = injectionPoint.getRequiredQualifier(DotName.createSimple(ManagedProperty.class.getName()));
if (managedProperty != null) {
AnnotationValue value = managedProperty.value("value");
if (value == null) {
continue;
}
Type requiredType = injectionPoint.getRequiredType();
beanConfigurators.produce(new BeanRegistrationPhaseBuildItem.BeanConfiguratorBuildItem(beanRegistrationPhase.getContext().configure(requiredType.name()).qualifiers(managedProperty).scope(BuiltinScope.DEPENDENT.getInfo()).types(requiredType).creator(ManagedPropertyBeanCreator.class).name(UUID.randomUUID().toString().replace("-", "")).defaultBean().param(ManagedPropertyBeanCreator.EXPRESSION, value.asString())));
}
}
}
Aggregations