Class AnnotationParser
java.lang.Object
jodd.util.AnnotationParser
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Class<? extends Annotation> protected final Annotation -
Constructor Summary
ConstructorsConstructorDescriptionAnnotationParser(Class<? extends Annotation> annotationClass) AnnotationParser(Class<? extends Annotation> annotationClass, Class<? extends Annotation> defaultAnnotationClass) Creates new annotation data reader using annotation definition from class generics. -
Method Summary
Modifier and TypeMethodDescriptionClass<? extends Annotation> Returns annotation type of this parser.booleanhasAnnotationOn(AnnotatedElement annotatedElement) Returnstrueif annotation is present on given annotated element.of(AnnotatedElement annotatedElement) Returns an annotation reader of annotated element.
-
Field Details
-
defaultAnnotation
-
annotationClass
-
-
Constructor Details
-
AnnotationParser
-
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 fromdefaultAnnotationClass- optional default annotation type, used to annotate the annotation class.
-
-
Method Details
-
getAnnotationType
Returns annotation type of this parser. -
hasAnnotationOn
Returnstrueif annotation is present on given annotated element. Should be called first, before using the read methods. -
of
Returns an annotation reader of annotated element.
-