RuntimeAnnotationReader
AbstractInlineAnnotationReaderImpl
, RuntimeInlineAnnotationReader
public interface AnnotationReader<T,C,F,M>
This is the lowest abstraction that encapsulates the difference between reading inline annotations and external binding files.
Because the former operates on a Field
and Method
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 implements Locatable
(so that it can
point to the place where the annotation is placed), and its
Locatable.getUpstream()
will return the given
Locatable
.
Errors found during reading annotations are reported through the error handler.
A valid ErrorHandler
must be registered before the AnnotationReader
is used.
Modifier and Type | Method | Description |
---|---|---|
java.lang.annotation.Annotation[] |
getAllFieldAnnotations(F field,
Locatable srcPos) |
Gets all the annotations on a field.
|
java.lang.annotation.Annotation[] |
getAllMethodAnnotations(M method,
Locatable srcPos) |
Gets all the annotations on a method.
|
<A extends java.lang.annotation.Annotation> |
getClassAnnotation(java.lang.Class<A> annotation,
C clazz,
Locatable srcpos) |
Reads an annotation on a class.
|
T[] |
getClassArrayValue(java.lang.annotation.Annotation a,
java.lang.String name) |
Similar to
getClassValue(Annotation, String) method but
obtains an array parameter. |
T |
getClassValue(java.lang.annotation.Annotation a,
java.lang.String name) |
Reads a value of an annotation that returns a Class object.
|
<A extends java.lang.annotation.Annotation> |
getFieldAnnotation(java.lang.Class<A> annotation,
F field,
Locatable srcpos) |
Reads an annotation on a property that consists of a field.
|
<A extends java.lang.annotation.Annotation> |
getMethodAnnotation(java.lang.Class<A> annotation,
M method,
Locatable srcpos) |
|
<A extends java.lang.annotation.Annotation> |
getMethodAnnotation(java.lang.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 java.lang.annotation.Annotation> |
getMethodParameterAnnotation(java.lang.Class<A> annotation,
M method,
int paramIndex,
Locatable srcPos) |
Reads an annotation on a parameter of the method.
|
<A extends java.lang.annotation.Annotation> |
getPackageAnnotation(java.lang.Class<A> annotation,
C clazz,
Locatable srcpos) |
Reads an annotation on the package that the given class belongs to.
|
boolean |
hasClassAnnotation(C clazz,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType) |
Checks if a class has the annotation.
|
boolean |
hasFieldAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
F field) |
Checks if the given field has an annotation.
|
boolean |
hasMethodAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
java.lang.String propertyName,
M getter,
M setter,
Locatable srcPos) |
Checks if the given method has an annotation.
|
boolean |
hasMethodAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
M method) |
|
void |
setErrorHandler(ErrorHandler errorHandler) |
Sets the error handler that receives errors found
during reading annotations.
|
void setErrorHandler(ErrorHandler errorHandler)
errorHandler
- must not be null.<A extends java.lang.annotation.Annotation> A getFieldAnnotation(java.lang.Class<A> annotation, F field, Locatable srcpos)
boolean hasFieldAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, F field)
boolean hasClassAnnotation(C clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
java.lang.annotation.Annotation[] getAllFieldAnnotations(F field, Locatable srcPos)
<A extends java.lang.annotation.Annotation> A getMethodAnnotation(java.lang.Class<A> annotation, M getter, M setter, Locatable srcpos)
boolean hasMethodAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.String propertyName, M getter, M setter, Locatable srcPos)
java.lang.annotation.Annotation[] getAllMethodAnnotations(M method, Locatable srcPos)
srcPos
- the location from which this annotation is read.<A extends java.lang.annotation.Annotation> A getMethodAnnotation(java.lang.Class<A> annotation, M method, Locatable srcpos)
boolean hasMethodAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, M method)
@Nullable <A extends java.lang.annotation.Annotation> A getMethodParameterAnnotation(java.lang.Class<A> annotation, M method, int paramIndex, Locatable srcPos)
@Nullable <A extends java.lang.annotation.Annotation> A getClassAnnotation(java.lang.Class<A> annotation, C clazz, Locatable srcpos)
@Nullable <A extends java.lang.annotation.Annotation> A getPackageAnnotation(java.lang.Class<A> annotation, C clazz, Locatable srcpos)
T getClassValue(java.lang.annotation.Annotation a, java.lang.String name)
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.
name
- The name of the annotation parameter to be read.T[] getClassArrayValue(java.lang.annotation.Annotation a, java.lang.String name)
getClassValue(Annotation, String)
method but
obtains an array parameter.Copyright © 2018 Oracle Corporation. All rights reserved.