Skip to content

Commit

Permalink
ArC: EventMetadata - implement the getInjectionPoint() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Feb 10, 2023
1 parent 3adb5f6 commit b6cc783
Show file tree
Hide file tree
Showing 15 changed files with 425 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.function.Supplier;

import jakarta.enterprise.inject.spi.DefinitionException;
import jakarta.enterprise.inject.spi.InjectionPoint;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
Expand Down Expand Up @@ -242,10 +243,36 @@ private static void generateEventBytecode(GeneratorContext ctx) {
}
}
ResultHandle parameterizedType = Types.getTypeHandle(ctx.constructor, ctx.injectionPoint.getType());
ResultHandle annotations = BeanGenerator.collectInjectionPointAnnotations(ctx.classOutput, ctx.clazzCreator,
ctx.beanDeployment,
ctx.constructor, ctx.injectionPoint, ctx.annotationLiterals, ctx.injectionPointAnnotationsPredicate);
ResultHandle javaMember = BeanGenerator.getJavaMemberHandle(ctx.constructor, ctx.injectionPoint,
ctx.reflectionRegistration);
boolean isTransient = ctx.injectionPoint.isField()
&& Modifier.isTransient(ctx.injectionPoint.getTarget().asField().flags());
ResultHandle bean;
switch (ctx.targetInfo.kind()) {
case OBSERVER:
// For observers the first argument is always the declaring bean
bean = ctx.constructor.invokeInterfaceMethod(
MethodDescriptors.SUPPLIER_GET, ctx.constructor.getMethodParam(0));
break;
case BEAN:
bean = ctx.constructor.getThis();
break;
default:
throw new IllegalStateException("Unsupported target info: " + ctx.targetInfo);
}

ResultHandle injectionPoint = ctx.constructor.newInstance(MethodDescriptors.INJECTION_POINT_IMPL_CONSTRUCTOR,
parameterizedType, parameterizedType, qualifiers, bean, annotations, javaMember,
ctx.constructor.load(ctx.injectionPoint.getPosition()),
ctx.constructor.load(isTransient));

ResultHandle eventProvider = ctx.constructor.newInstance(
MethodDescriptor.ofConstructor(EventProvider.class, java.lang.reflect.Type.class,
Set.class),
parameterizedType, qualifiers);
Set.class, InjectionPoint.class),
parameterizedType, qualifiers, injectionPoint);
ResultHandle eventProviderSupplier = ctx.constructor.newInstance(
MethodDescriptors.FIXED_VALUE_SUPPLIER_CONSTRUCTOR, eventProvider);
ctx.constructor.writeInstanceField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.quarkus.arc.impl.DecoratorDelegateProvider;
import io.quarkus.arc.impl.FixedValueSupplier;
import io.quarkus.arc.impl.InjectableReferenceProviders;
import io.quarkus.arc.impl.InjectionPointImpl;
import io.quarkus.arc.impl.Instances;
import io.quarkus.arc.impl.InterceptedMethodMetadata;
import io.quarkus.arc.impl.InterceptorInvocation;
Expand Down Expand Up @@ -278,6 +279,10 @@ public final class MethodDescriptors {
"toString", String.class,
InjectableBean.class);

public static final MethodDescriptor INJECTION_POINT_IMPL_CONSTRUCTOR = MethodDescriptor.ofConstructor(
InjectionPointImpl.class,
Type.class, Type.class, Set.class, InjectableBean.class, Set.class, Member.class, int.class, boolean.class);

private MethodDescriptors() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ default Bean<?> getDeclaringBean() {

default void notify(T event) {
notify(new EventContextImpl<>(event,
new EventMetadataImpl(getObservedQualifiers(), event.getClass())));
new EventMetadataImpl(getObservedQualifiers(), event.getClass(), null)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public List<RemovedBean> get() {
public void init() {
// Fire an event with qualifier @Initialized(ApplicationScoped.class)
Set<Annotation> qualifiers = Set.of(Initialized.Literal.APPLICATION, Any.Literal.INSTANCE);
EventImpl.createNotifier(Object.class, Object.class, qualifiers, this, false)
EventImpl.createNotifier(Object.class, Object.class, qualifiers, this, false, null)
.notify("@Initialized(ApplicationScoped.class)");
// Configure CDIProvider used for CDI.current()
CDI.setCDIProvider(new ArcCDIProvider());
Expand Down Expand Up @@ -234,7 +234,6 @@ public <X> InstanceHandle<X> instance(Type type, Annotation... qualifiers) {
return instanceHandle(type, qualifiers);
}

@SuppressWarnings("unchecked")
@Override
public <T> Supplier<InstanceHandle<T>> beanInstanceSupplier(Class<T> type, Annotation... qualifiers) {
return createInstanceSupplier(false, type, qualifiers);
Expand Down Expand Up @@ -268,6 +267,7 @@ private <T> Supplier<InstanceHandle<T>> createInstanceSupplier(boolean resolveAm
throw new AmbiguousResolutionException("Beans: " + resolvedBeans);
}
}
@SuppressWarnings("unchecked")
InjectableBean<T> bean = filteredBean.size() != 1 ? null
: (InjectableBean<T>) filteredBean.iterator().next();
if (bean == null) {
Expand Down Expand Up @@ -385,7 +385,8 @@ public synchronized void shutdown() {
beforeDestroyQualifiers.add(BeforeDestroyed.Literal.APPLICATION);
beforeDestroyQualifiers.add(Any.Literal.INSTANCE);
try {
EventImpl.createNotifier(Object.class, Object.class, beforeDestroyQualifiers, this, false).notify(toString());
EventImpl.createNotifier(Object.class, Object.class, beforeDestroyQualifiers, this, false, null)
.notify(toString());
} catch (Exception e) {
LOGGER.warn("An error occurred during delivery of the @BeforeDestroyed(ApplicationScoped.class) event", e);
}
Expand All @@ -396,7 +397,7 @@ public synchronized void shutdown() {
destroyQualifiers.add(Destroyed.Literal.APPLICATION);
destroyQualifiers.add(Any.Literal.INSTANCE);
try {
EventImpl.createNotifier(Object.class, Object.class, destroyQualifiers, this, false).notify(toString());
EventImpl.createNotifier(Object.class, Object.class, destroyQualifiers, this, false, null).notify(toString());
} catch (Exception e) {
LOGGER.warn("An error occurred during delivery of the @Destroyed(ApplicationScoped.class) event", e);
}
Expand Down Expand Up @@ -444,7 +445,7 @@ InstanceHandle<Object> getResource(Type type, Set<Annotation> annotations) {

private Notifier<Object> notifierOrNull(Set<Annotation> qualifiers) {
Notifier<Object> notifier = EventImpl.createNotifier(Object.class, Object.class,
qualifiers, this, false);
qualifiers, this, false, null);
return notifier.isEmpty() ? null : notifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public <T> InterceptionFactory<T> createInterceptionFactory(CreationalContext<T>

@Override
public Event<Object> getEvent() {
return new EventImpl<>(Object.class, new HashSet<>());
return new EventImpl<>(Object.class, new HashSet<>(), null);
}

@Override
Expand Down
Loading

0 comments on commit b6cc783

Please sign in to comment.