Package jodd.util
Class AnnotationParser
- java.lang.Object
-
- jodd.util.AnnotationParser
-
public class AnnotationParser extends java.lang.ObjectAnnotation 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classAnnotationParser.Reader
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Class<? extends java.lang.annotation.Annotation>annotationClassprotected java.lang.annotation.AnnotationdefaultAnnotation
-
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.booleanhasAnnotationOn(java.lang.reflect.AnnotatedElement annotatedElement)Returnstrueif annotation is present on given annotated element.AnnotationParser.Readerof(java.lang.reflect.AnnotatedElement annotatedElement)Returns an annotation reader of annotated element.
-
-
-
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 fromdefaultAnnotationClass- 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)
Returnstrueif 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.
-
-