Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-472

Support @WithAnnotations as type annotation of lifecycle events

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Obsolete
    • Icon: Major Major
    • None
    • None
    • None
    • None

      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:

      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));
      }
      

      One could write directly:

      <@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));
      }
      

              Unassigned Unassigned
              astefanu@redhat.com Antonin Stefanutti
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: