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

Improve producer method signature capability by accepting qualifier annotations

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Obsolete
    • Icon: Optional Optional
    • None
    • None
    • Beans
    • None

      CDI supports producer methods which accept the InjectionPoint as argument which allows to access all metadata to the injection point. The InjectionPoint approach adds a certain complexity which is not needed when only qualifier metadata has to be processed. I propose to allow annotation types within the producer method signatures. Code example for a use case:

      @HttpParam("username") @Inject String username
      
      import javax.enterprise.inject.Produces;
      import javax.enterprise.inject.spi.InjectionPoint;
      
      class HttpParams
        @Produces
      
        String getParamValue(HttpParam httpParam) {
      
           ServletRequest request = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
      	  
           return request.getParameter(httpParam.value());
      	  
           // current support looks like:
           // String getParamValue(InjectionPoint ip) {
           // return request.getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value());
      
        }
      }
      

      Producer methods accepting qualifier annotations ensure to have always an annotation instance, this helps to prevent null pointer access since InjectionPoint.getAnnotated().getAnnotation(java.lang.Class<T>) may return null.

            Unassigned Unassigned
            mpaluch@paluch.biz Mark Paluch (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: