[seam-issues] [JBoss JIRA] Commented: (SOLDER-52) Add methods to AnnotationIntrospector that operate on Annotated (from CDI)

Dan Allen (JIRA) jira-events at lists.jboss.org
Thu Dec 9 23:40:52 EST 2010


    [ https://issues.jboss.org/browse/SOLDER-52?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12569150#comment-12569150 ] 

Dan Allen commented on SOLDER-52:
---------------------------------

Proposed methods:

public static <A extends Annotation> boolean isAnnotationPresent(Annotated annotated, final Class<A> annotationType, BeanManager beanManager)
{
   if (annotated.isAnnotationPresent(annotationType))
   {
      return true;
   }
   
   for (Annotation candidate : annotated.getAnnotations())
   {
      if (beanManager.isStereotype(candidate.annotationType()))
      {
         for (Annotation stereotyped : beanManager.getStereotypeDefinition(candidate.annotationType()))
         {
            if (stereotyped.annotationType().equals(annotationType))
            {
               return true;
            }
         }
      }
   }
   return false;
}

public static <A extends Annotation> boolean getAnnotation(Annotated annotated, final Class<A> annotationType, BeanManager beanManager)
{
   Annotation found = annotated.getAnnotation(annotationType); 
   if (found != null)
   {
      return annotationType.cast(found);
   }
   
   for (Annotation candidate : annotated.getAnnotations())
   {
      if (beanManager.isStereotype(candidate.annotationType()))
      {
         for (Annotation stereotyped : beanManager.getStereotypeDefinition(candidate.annotationType()))
         {
            if (stereotyped.annotationType().equals(annotationType))
            {
               return annotationType.cast(stereotyped);
            }
         }
      }
   }
   return null;
}

Though we should probably expand this to handle three flags:

1. Only look on Annotated
2. Look on Annotated or stereotypes
3. Look on Annotated or as meta-annotation

There are holes in the scenarios covered by the existing methods as well.  

> Add methods to AnnotationIntrospector that operate on Annotated (from CDI)
> --------------------------------------------------------------------------
>
>                 Key: SOLDER-52
>                 URL: https://issues.jboss.org/browse/SOLDER-52
>             Project: Seam Solder
>          Issue Type: Feature Request
>            Reporter: Dan Allen
>
> The AnnotationIntrospector works on java.lang.reflect.AnnotatedElement types. However, in an extension, you are most often dealing with an Annotated. Therefore, the AnnotationIntrospector should provide parallel utilities for retrieving/checking an annotation on Annotated or any stereotype on Annotated.  

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the seam-issues mailing list