Hi Nigel,

Check the error message, I think it's not the same method you referenced it. However I would like to see @WithAnnotations or a similar solution for other Process* types.

Best Regards,

George Gastaldi

Em 14/08/2015 09:04, "Nigel Deakin" <nigel.deakin@oracle.com> escreveu:
I'm writing a portable extension, and my Extension class includes the following observer method

   public <X> void processInjectionTarget(
       @Observes ProcessInjectionTarget<X> event) {

When I start the server (Glassfish) I see this warning in the log:

   WELD-000411: Observer method [BackedAnnotatedMethod] public com.foo.MyExtension.processAnnotatedType(@Observes
ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using
@WithAnnotations or a generic type with bounds.]]

I thought "OK, fair enough. I only want to receive ProcessInjectionTarget events for classes that have a specific
annotation. So I'll do what it suggests and @WithAnnotations to restrict the events received."

However if I look up the javadocs for WithAnnotations it says "WithAnnotations may be applied to any portable extension
observer method with an event parameter type of ProcessAnnotatedType to filter the events delivered."

And if I try using WithAnnotations on the above method, I indeed get an error at runtime.

So the warning message WELD-000411 is incorrect, since it suggests doing something that is not allowed.

@WithAnnotations would have been perfect for my needs. Why is it not allowed when observing ProcessInjectionTarget events?

So it looks as if I will simply have to receive every such event and check whether it has the required annotation:

   public <X> void processInjectionTarget(
       @Observes ProcessInjectionTarget<X> event) {

      if (!event.getAnnotatedType().isAnnotationPresent(MyAnnotation.class)) {
         return;
     }

This doesn't look very efficient to me, since there will be a lot of irrelevant events. Is there a better way?

Nigel


_______________________________________________
cdi-dev mailing list
cdi-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.