[cdi-dev] WithAnnotations with ProcessInjectionTarget events
Nigel Deakin
nigel.deakin at oracle.com
Fri Aug 14 09:20:33 EDT 2015
George,
Yes, you're right. That warning refers to a different method of the same extension (which is obvious now). Thanks for
pointing that out. So the WELD message is correct.
So that just leaves me asking whether it would be desirable to support @WithAnnotations with ProcessInjectionTarget
events, to avoid the need to call isAnnotationPresent() on every injection target.
Nigel
On 14/08/2015 13:52, George Gastaldi wrote:
>
> 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 at oracle.com <mailto:nigel.deakin at 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 at lists.jboss.org <mailto:cdi-dev at 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.
>
>
>
> _______________________________________________
> cdi-dev mailing list
> cdi-dev at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20150814/6e8e704a/attachment-0001.html
More information about the cdi-dev
mailing list