Package jodd.util

Class AnnotationParser


  • public class AnnotationParser
    extends java.lang.Object
    Annotation parser process an annotated elements and annotations. Can be used to simulate annotation inheritance, as such does not exist in Java.

    There are 3 ways how this class can be used. First, it can be used on single annotation, but that does not make much sense.

    Second way is with child and parent annotation. The parent annotation is default one, like a base class. Child annotation contains some predefined values different from parent. Note that child annotation does NOT have to specify all elements - all missing elements will be read from default parent annotation. So child annotation behaves like it is overriding the parent one.

    Third way is similar, except the child annotation is also annotated with parent annotation! Besides overriding features and default values, this way we can finalize some element value and prevent it from being modified by user.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass  
      protected java.lang.annotation.Annotation defaultAnnotation  
    • Constructor Summary

      Constructors 
      Constructor Description
      AnnotationParser​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)  
      AnnotationParser​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, java.lang.Class<? extends java.lang.annotation.Annotation> defaultAnnotationClass)
      Creates new annotation data reader using annotation definition from class generics.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Class<? extends java.lang.annotation.Annotation> getAnnotationType()
      Returns annotation type of this parser.
      boolean hasAnnotationOn​(java.lang.reflect.AnnotatedElement annotatedElement)
      Returns true if annotation is present on given annotated element.
      AnnotationParser.Reader of​(java.lang.reflect.AnnotatedElement annotatedElement)
      Returns an annotation reader of annotated element.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • defaultAnnotation

        protected final java.lang.annotation.Annotation defaultAnnotation
      • annotationClass

        protected final java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass
    • Constructor Detail

      • AnnotationParser

        public AnnotationParser​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      • AnnotationParser

        public AnnotationParser​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                java.lang.Class<? extends java.lang.annotation.Annotation> defaultAnnotationClass)
        Creates new annotation data reader using annotation definition from class generics. Moreover, allows annotation to be annotated with default annotation, for convenient and fail-back value reading.
        Parameters:
        annotationClass - annotation type to read from
        defaultAnnotationClass - optional default annotation type, used to annotate the annotation class.
    • Method Detail

      • getAnnotationType

        public java.lang.Class<? extends java.lang.annotation.Annotation> getAnnotationType()
        Returns annotation type of this parser.
      • hasAnnotationOn

        public boolean hasAnnotationOn​(java.lang.reflect.AnnotatedElement annotatedElement)
        Returns true if annotation is present on given annotated element. Should be called first, before using the read methods.
      • of

        public AnnotationParser.Reader of​(java.lang.reflect.AnnotatedElement annotatedElement)
        Returns an annotation reader of annotated element.