[seam-dev] Need for Common Annotation-attribute scanning/parsing utility (or CDI API/SPI)

Pete Muir pmuir at redhat.com
Wed Apr 14 14:07:49 EDT 2010


On 14 Apr 2010, at 18:59, Dan Allen wrote:

> /**
>    * Inspect AnnoatedElement <b>element</b> for a specific <b>type</b> of annotation. This
>    * also discovers annotations defined through a @ {@link Stereotype} and the CDI SPI. Having found
>    * the annotation, it is inspected for a member with name <b>memberName</b>.
>    *
>    * @param element The element to inspect
>    * @param annotationType The annotation type to check for
>    * @param memberName The name of the member to look for
>    * @param expectedMemberType The expectedType of the member
>    * @param metaAnnotation Whether the annotation may be used as a meta-annotation or not
>    *
>    * @return The annotation member's value or null if no matching annotation was found
>    * @throws IllegalArgumentException if element, annotationType, memberName or expectedMemberType is null
>    * @throws IllegalArgumentException if the annotationType does not have a member of memberName
>    * @throws ClassCastException if the value of memberName cannot be cast to expectedMemberType
>    */
>   public static <V> V getAnnotationMemberValue(AnnotatedElement element, final Class<A> annotationType, String memberName, Class<V> expectedMemberType, boolean metaAnnotation)
> 
> WDYT?
> 
> I'm not sure I understand why we need a separate method to get an annotation member value. It requires specifying a string name. Why can't we simply return the annotation instance and then allow the value to be read by invoking the member method?

Actually, I agree with you here, but Lincoln complained mightily about this last night so I relented. Ok, let's strike this method.

> I'll admit I was excited about the more fluent method names that Lincoln had in his code. Do we really need to have these long method names? Seems like pomp and circumstance to me. I suppose that this is what Java has always been about, so why take the garb off the queen? Boo.

I believe the consistency with the Java Reflection API is important (BTW Lincoln's API wasn't really fluent, just had shorter names).


More information about the seam-dev mailing list