Interface AnnotationReader<T,C,F,M>
-
- All Known Subinterfaces:
RuntimeAnnotationReader
- All Known Implementing Classes:
AbstractInlineAnnotationReaderImpl
,InlineAnnotationReaderImpl
,RuntimeInlineAnnotationReader
public interface AnnotationReader<T,C,F,M>
Reads annotations for the given property.This is the lowest abstraction that encapsulates the difference between reading inline annotations and external binding files.
Because the former operates on a
Field
andMethod
while the latter operates on a "property", the methods defined on this interface takes both, and the callee gets to choose which to use.Most of the get method takes
Locatable
, which points to the place/context in which the annotation is read. The returned annotation also implementsLocatable
(so that it can point to the place where the annotation is placed), and itsLocatable.getUpstream()
will return the givenLocatable
.Errors found during reading annotations are reported through the error handler. A valid
ErrorHandler
must be registered before theAnnotationReader
is used.- Author:
- Kohsuke Kawaguchi ([email protected])
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Annotation[]
getAllFieldAnnotations(F field, Locatable srcPos)
Gets all the annotations on a field.Annotation[]
getAllMethodAnnotations(M method, Locatable srcPos)
Gets all the annotations on a method.<A extends Annotation>
AgetClassAnnotation(Class<A> annotation, C clazz, Locatable srcpos)
Reads an annotation on a class.T[]
getClassArrayValue(Annotation a, String name)
Similar togetClassValue(Annotation, String)
method but obtains an array parameter.T
getClassValue(Annotation a, String name)
Reads a value of an annotation that returns a Class object.<A extends Annotation>
AgetFieldAnnotation(Class<A> annotation, F field, Locatable srcpos)
Reads an annotation on a property that consists of a field.<A extends Annotation>
AgetMethodAnnotation(Class<A> annotation, M method, Locatable srcpos)
<A extends Annotation>
AgetMethodAnnotation(Class<A> annotation, M getter, M setter, Locatable srcpos)
Reads an annotation on a property that consists of a getter and a setter.<A extends Annotation>
AgetMethodParameterAnnotation(Class<A> annotation, M method, int paramIndex, Locatable srcPos)
Reads an annotation on a parameter of the method.<A extends Annotation>
AgetPackageAnnotation(Class<A> annotation, C clazz, Locatable srcpos)
Reads an annotation on the package that the given class belongs to.boolean
hasClassAnnotation(C clazz, Class<? extends Annotation> annotationType)
Checks if a class has the annotation.boolean
hasFieldAnnotation(Class<? extends Annotation> annotationType, F field)
Checks if the given field has an annotation.boolean
hasMethodAnnotation(Class<? extends Annotation> annotation, String propertyName, M getter, M setter, Locatable srcPos)
Checks if the given method has an annotation.boolean
hasMethodAnnotation(Class<? extends Annotation> annotation, M method)
void
setErrorHandler(ErrorHandler errorHandler)
Sets the error handler that receives errors found during reading annotations.
-
-
-
Method Detail
-
setErrorHandler
void setErrorHandler(ErrorHandler errorHandler)
Sets the error handler that receives errors found during reading annotations.- Parameters:
errorHandler
- must not be null.
-
getFieldAnnotation
<A extends Annotation> A getFieldAnnotation(Class<A> annotation, F field, Locatable srcpos)
Reads an annotation on a property that consists of a field.
-
hasFieldAnnotation
boolean hasFieldAnnotation(Class<? extends Annotation> annotationType, F field)
Checks if the given field has an annotation.
-
hasClassAnnotation
boolean hasClassAnnotation(C clazz, Class<? extends Annotation> annotationType)
Checks if a class has the annotation.
-
getAllFieldAnnotations
Annotation[] getAllFieldAnnotations(F field, Locatable srcPos)
Gets all the annotations on a field.
-
getMethodAnnotation
<A extends Annotation> A getMethodAnnotation(Class<A> annotation, M getter, M setter, Locatable srcpos)
Reads an annotation on a property that consists of a getter and a setter.
-
hasMethodAnnotation
boolean hasMethodAnnotation(Class<? extends Annotation> annotation, String propertyName, M getter, M setter, Locatable srcPos)
Checks if the given method has an annotation.
-
getAllMethodAnnotations
Annotation[] getAllMethodAnnotations(M method, Locatable srcPos)
Gets all the annotations on a method.- Parameters:
srcPos
- the location from which this annotation is read.
-
getMethodAnnotation
<A extends Annotation> A getMethodAnnotation(Class<A> annotation, M method, Locatable srcpos)
-
hasMethodAnnotation
boolean hasMethodAnnotation(Class<? extends Annotation> annotation, M method)
-
getMethodParameterAnnotation
@Nullable <A extends Annotation> A getMethodParameterAnnotation(Class<A> annotation, M method, int paramIndex, Locatable srcPos)
Reads an annotation on a parameter of the method.- Returns:
- null if the annotation was not found.
-
getClassAnnotation
@Nullable <A extends Annotation> A getClassAnnotation(Class<A> annotation, C clazz, Locatable srcpos)
Reads an annotation on a class.
-
getPackageAnnotation
@Nullable <A extends Annotation> A getPackageAnnotation(Class<A> annotation, C clazz, Locatable srcpos)
Reads an annotation on the package that the given class belongs to.
-
getClassValue
T getClassValue(Annotation a, String name)
Reads a value of an annotation that returns a Class object.Depending on the underlying reflection library, you can't always obtain the
Class
object directly (see the Annotation Processing MirrorTypeException for example), so use this method to avoid that.- Parameters:
name
- The name of the annotation parameter to be read.
-
getClassArrayValue
T[] getClassArrayValue(Annotation a, String name)
Similar togetClassValue(Annotation, String)
method but obtains an array parameter.
-
-