[cdi-dev] [JBoss JIRA] (CDI-472) Support @WithAnnotations as type annotation of lifecycle events

Antonin Stefanutti (JIRA) issues at jboss.org
Mon Sep 15 05:28:02 EDT 2014


Antonin Stefanutti created CDI-472:
--------------------------------------

             Summary: Support @WithAnnotations as type annotation of lifecycle events
                 Key: CDI-472
                 URL: https://issues.jboss.org/browse/CDI-472
             Project: CDI Specification Issues
          Issue Type: Feature Request
            Reporter: Antonin Stefanutti


As Java 8 introduces type annotations, generalizing the benefit of {{@WithAnnotations}} by using it as type annotation could improve a lot of recurring patterns that are usually implemented as a combination of {{ProcessAnnotatedType}} and other lifecycle events.

For example, instead of having to write that in a CDI extension:
{code}
Set<AnnotatedType<?>> camelBeans = new HashMap<>();

void camelAnnotations(@Observes @WithAnnotations({BeanInject.class, Consume.class, EndpointInject.class, Produce.class, PropertyInject.class}) ProcessAnnotatedType<?> pat) {
        camelBeans.add(pat.getAnnotatedType());
    }

<T> void camelBeansPostProcessor(@Observes ProcessInjectionTarget<T> pit, BeanManager manager) {
        if (camelBeans.contains(pit.getAnnotatedType()))
            pit.setInjectionTarget(new CdiCamelInjectionTarget<>(pit.getInjectionTarget(), manager));
    }
{code}

One could write directly:
{code}
<@WithAnnotations({BeanInject.class, Consume.class, EndpointInject.class, Produce.class, PropertyInject.class}) T> void camelBeansPostProcessor(@Observes ProcessInjectionTarget<T> pit, BeanManager manager) {
        pit.setInjectionTarget(new CdiCamelInjectionTarget<>(pit.getInjectionTarget(), manager));
    }
{code}



--
This message was sent by Atlassian JIRA
(v6.3.1#6329)


More information about the cdi-dev mailing list