Class AnnotationParser

java.lang.Object
jodd.util.AnnotationParser

public class AnnotationParser extends 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 Details

    • defaultAnnotation

      protected final Annotation defaultAnnotation
    • annotationClass

      protected final Class<? extends Annotation> annotationClass
  • Constructor Details

    • AnnotationParser

      public AnnotationParser(Class<? extends Annotation> annotationClass)
    • AnnotationParser

      public AnnotationParser(Class<? extends Annotation> annotationClass, Class<? extends 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 Details

    • getAnnotationType

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

      public boolean hasAnnotationOn(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(AnnotatedElement annotatedElement)
      Returns an annotation reader of annotated element.