2 Replies Latest reply on Feb 13, 2008 7:42 AM by Adrian Brock

    Adding MetaData.isAnnotationPresent(String annotationType)

    Kabir Khan Master

      http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4127320#4127320

      Following from this discussion, would it be possible to add the following to the MetaData spi?

      /**
       * Is the annotation present?
       *
       * @param annotationType the stringfied annotation type
       * @return true when present
       */
       boolean isAnnotationPresent(String annotationType);
      



        • 1. Re: Adding MetaData.isAnnotationPresent(String annotationTyp
          Adrian Brock Master

          It already exists:

           /**
           * Is the metadata present
           *
           * @param name the name of the meta data
           * @return true when the metadata is present
           */
           boolean isMetaDataPresent(String name);
          


          If you're not going to check whether the name is really an annotation class
          then they are the same thing.

          Of course, you might want to implement it like this, just to make doubly sure :-)

          public boolean isAnnotationPresent(String name)
          {
           Object test = getMetaData(name);
           return test != null && (test instanceof Annotation);
          }
          


          But such a non-annotation using the name of annotation class would break
          the assumption of how the annotation stuff works in the metadata. :-)

          • 2. Re: Adding MetaData.isAnnotationPresent(String annotationTyp
            Adrian Brock Master

            Of course, the above was pseudo code.

            What I really mean is that you don't need to change the MetaData api,
            you could just have a static helper method (real code):

            public static boolean isAnnotationPresent(MetaData metaData, String name)
            {
             if (metaData == null)
             throw new IllegalArgumentException("Null metadata");
            
             Object test = metaData.getMetaData(name);
             return test != null && (test instanceof Annotation);
            }