public class AnnotationMetadataReadingVisitor extends ClassVisitor implements AnnotationMetadata
AnnotationMetadata
interface.Modifier and Type | Field and Description |
---|---|
protected Set<String> |
annotationSet |
protected LinkedMultiValueMap<String,AnnotationAttributes> |
attributesMap
Declared as a
LinkedMultiValueMap instead of a MultiValueMap
to ensure that the hierarchical ordering of the entries is preserved. |
protected ClassLoader |
classLoader |
protected Map<String,Set<String>> |
metaAnnotationMap |
protected Set<MethodMetadata> |
methodMetadataSet |
api, cv
Constructor and Description |
---|
AnnotationMetadataReadingVisitor(ClassLoader classLoader) |
Modifier and Type | Method and Description |
---|---|
MultiValueMap<String,Object> |
getAllAnnotationAttributes(String annotationType)
Retrieve all attributes of all annotations of the given type, if any (i.e.
|
MultiValueMap<String,Object> |
getAllAnnotationAttributes(String annotationType,
boolean classValuesAsString)
Retrieve all attributes of all annotations of the given type, if any (i.e.
|
Set<MethodMetadata> |
getAnnotatedMethods(String annotationType)
Retrieve the method metadata for all methods that are annotated
(or meta-annotated) with the given annotation type.
|
AnnotationAttributes |
getAnnotationAttributes(String annotationType)
Retrieve the attributes of the annotation of the given type, if any (i.e.
|
AnnotationAttributes |
getAnnotationAttributes(String annotationType,
boolean classValuesAsString)
Retrieve the attributes of the annotation of the given type, if any (i.e.
|
Set<String> |
getAnnotationTypes()
Return the names of all annotation types that are present on the
underlying class.
|
String |
getClassName()
Return the name of the underlying class.
|
String |
getEnclosingClassName()
Return the name of the enclosing class of the underlying class,
or
null if the underlying class is a top-level class. |
String[] |
getInterfaceNames()
Return the names of all interfaces that the underlying class
implements, or an empty array if there are none.
|
String[] |
getMemberClassNames()
Return the names of all classes declared as members of the class represented by
this ClassMetadata object.
|
Set<String> |
getMetaAnnotationTypes(String annotationType)
Return the names of all meta-annotation types present on the
given annotation type on the underlying class.
|
String |
getSuperClassName()
Return the name of the super class of the underlying class,
or
null if there is no super class defined. |
boolean |
hasAnnotatedMethods(String annotationType)
Determine whether the underlying class has any methods that are
annotated (or meta-annotated) with the given annotation type.
|
boolean |
hasAnnotation(String annotationType)
Determine whether an annotation of the given type is present on
the underlying class.
|
boolean |
hasEnclosingClass()
Return whether the underlying class has an enclosing class
(i.e.
|
boolean |
hasMetaAnnotation(String metaAnnotationType)
Determine whether the underlying class has an annotation that is itself
annotated with the meta-annotation of the given type.
|
boolean |
hasSuperClass()
Return whether the underlying class has a super class.
|
boolean |
isAbstract()
Return whether the underlying class is marked as abstract.
|
boolean |
isAnnotated(String annotationType)
Determine whether the underlying element has an annotation or meta-annotation
of the given type defined.
|
boolean |
isAnnotation()
Return whether the underlying class represents an annotation.
|
boolean |
isConcrete()
Return whether the underlying class represents a concrete class,
i.e.
|
boolean |
isFinal()
Return whether the underlying class is marked as 'final'.
|
boolean |
isIndependent()
Determine whether the underlying class is independent,
i.e.
|
boolean |
isInterface()
Return whether the underlying class represents an interface.
|
void |
visit(int version,
int access,
String name,
String signature,
String supername,
String[] interfaces)
Visits the header of the class.
|
AnnotationVisitor |
visitAnnotation(String desc,
boolean visible)
Visits an annotation of the class.
|
void |
visitAttribute(Attribute attr)
Visits a non standard attribute of the class.
|
void |
visitEnd()
Visits the end of the class.
|
FieldVisitor |
visitField(int access,
String name,
String desc,
String signature,
Object value)
Visits a field of the class.
|
void |
visitInnerClass(String name,
String outerName,
String innerName,
int access)
Visits information about an inner class.
|
MethodVisitor |
visitMethod(int access,
String name,
String desc,
String signature,
String[] exceptions)
Visits a method of the class.
|
void |
visitOuterClass(String owner,
String name,
String desc)
Visits the enclosing class of the class.
|
void |
visitSource(String source,
String debug)
Visits the source of the class.
|
visitTypeAnnotation
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getClassName, getEnclosingClassName, getInterfaceNames, getMemberClassNames, getSuperClassName, hasEnclosingClass, hasSuperClass, isAbstract, isAnnotation, isConcrete, isFinal, isIndependent, isInterface
protected final ClassLoader classLoader
protected final LinkedMultiValueMap<String,AnnotationAttributes> attributesMap
LinkedMultiValueMap
instead of a MultiValueMap
to ensure that the hierarchical ordering of the entries is preserved.AnnotationReadingVisitorUtils.getMergedAnnotationAttributes(org.springframework.util.LinkedMultiValueMap<java.lang.String, org.springframework.core.annotation.AnnotationAttributes>, java.util.Map<java.lang.String, java.util.Set<java.lang.String>>, java.lang.String)
protected final Set<MethodMetadata> methodMetadataSet
public AnnotationMetadataReadingVisitor(ClassLoader classLoader)
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
ClassVisitor
MethodVisitor
instance (or null) each time it is called,
i.e., it should not return a previously returned visitor.access
- the method's access flags (see Opcodes
). This
parameter also indicates if the method is synthetic and/or
deprecated.name
- the method's name.desc
- the method's descriptor (see Type
).signature
- the method's signature. May be null if the method
parameters, return type and exceptions do not use generic
types.exceptions
- the internal names of the method's exception classes (see
getInternalName
). May be
null.public AnnotationVisitor visitAnnotation(String desc, boolean visible)
ClassVisitor
desc
- the class descriptor of the annotation class.visible
- true if the annotation is visible at runtime.public Set<String> getAnnotationTypes()
AnnotationMetadata
getAnnotationTypes
in interface AnnotationMetadata
public Set<String> getMetaAnnotationTypes(String annotationType)
AnnotationMetadata
getMetaAnnotationTypes
in interface AnnotationMetadata
annotationType
- the meta-annotation type to look forpublic boolean hasAnnotation(String annotationType)
AnnotationMetadata
hasAnnotation
in interface AnnotationMetadata
annotationType
- the annotation type to look forpublic boolean hasMetaAnnotation(String metaAnnotationType)
AnnotationMetadata
hasMetaAnnotation
in interface AnnotationMetadata
metaAnnotationType
- the meta-annotation type to look forpublic boolean isAnnotated(String annotationType)
AnnotatedTypeMetadata
If this method returns true
, then
AnnotatedTypeMetadata.getAnnotationAttributes(java.lang.String)
will return a non-null Map.
isAnnotated
in interface AnnotatedTypeMetadata
annotationType
- the annotation type to look forpublic AnnotationAttributes getAnnotationAttributes(String annotationType)
AnnotatedTypeMetadata
getAnnotationAttributes
in interface AnnotatedTypeMetadata
annotationType
- the annotation type to look fornull
if no matching annotation is defined.public AnnotationAttributes getAnnotationAttributes(String annotationType, boolean classValuesAsString)
AnnotatedTypeMetadata
getAnnotationAttributes
in interface AnnotatedTypeMetadata
annotationType
- the annotation type to look forclassValuesAsString
- whether to convert class references to String
class names for exposure as values in the returned Map, instead of Class
references which might potentially have to be loaded firstnull
if no matching annotation is defined.public MultiValueMap<String,Object> getAllAnnotationAttributes(String annotationType)
AnnotatedTypeMetadata
getAllAnnotationAttributes
in interface AnnotatedTypeMetadata
annotationType
- the annotation type to look fornull
if no matching annotation is defined.AnnotatedTypeMetadata.getAllAnnotationAttributes(String, boolean)
public MultiValueMap<String,Object> getAllAnnotationAttributes(String annotationType, boolean classValuesAsString)
AnnotatedTypeMetadata
getAllAnnotationAttributes
in interface AnnotatedTypeMetadata
annotationType
- the annotation type to look forclassValuesAsString
- whether to convert class references to Stringnull
if no matching annotation is defined.AnnotatedTypeMetadata.getAllAnnotationAttributes(String)
public boolean hasAnnotatedMethods(String annotationType)
AnnotationMetadata
hasAnnotatedMethods
in interface AnnotationMetadata
public Set<MethodMetadata> getAnnotatedMethods(String annotationType)
AnnotationMetadata
For any returned method, AnnotatedTypeMetadata.isAnnotated(java.lang.String)
will
return true
for the given annotation type.
getAnnotatedMethods
in interface AnnotationMetadata
annotationType
- the annotation type to look forMethodMetadata
for methods that have a matching
annotation. The return value will be an empty set if no methods match
the annotation type.public void visit(int version, int access, String name, String signature, String supername, String[] interfaces)
ClassVisitor
visit
in class ClassVisitor
version
- the class version.access
- the class's access flags (see Opcodes
). This parameter
also indicates if the class is deprecated.name
- the internal name of the class (see
getInternalName
).signature
- the signature of this class. May be null if the class
is not a generic one, and does not extend or implement generic
classes or interfaces.supername
- the internal of name of the super class (see
getInternalName
). For
interfaces, the super class is Object
. May be
null, but only for the Object
class.interfaces
- the internal names of the class's interfaces (see
getInternalName
). May be
null.public void visitOuterClass(String owner, String name, String desc)
ClassVisitor
visitOuterClass
in class ClassVisitor
owner
- internal name of the enclosing class of the class.name
- the name of the method that contains the class, or
null if the class is not enclosed in a method of its
enclosing class.desc
- the descriptor of the method that contains the class, or
null if the class is not enclosed in a method of its
enclosing class.public void visitInnerClass(String name, String outerName, String innerName, int access)
ClassVisitor
visitInnerClass
in class ClassVisitor
name
- the internal name of an inner class (see
getInternalName
).outerName
- the internal name of the class to which the inner class
belongs (see getInternalName
).
May be null for not member classes.innerName
- the (simple) name of the inner class inside its enclosing
class. May be null for anonymous inner classes.access
- the access flags of the inner class as originally declared in
the enclosing class.public void visitSource(String source, String debug)
ClassVisitor
visitSource
in class ClassVisitor
source
- the name of the source file from which the class was compiled.
May be null.debug
- additional debug information to compute the correspondance
between source and compiled elements of the class. May be
null.public void visitAttribute(Attribute attr)
ClassVisitor
visitAttribute
in class ClassVisitor
attr
- an attribute.public FieldVisitor visitField(int access, String name, String desc, String signature, Object value)
ClassVisitor
visitField
in class ClassVisitor
access
- the field's access flags (see Opcodes
). This parameter
also indicates if the field is synthetic and/or deprecated.name
- the field's name.desc
- the field's descriptor (see Type
).signature
- the field's signature. May be null if the field's
type does not use generic types.value
- the field's initial value. This parameter, which may be
null if the field does not have an initial value,
must be an Integer
, a Float
, a Long
, a
Double
or a String
(for int,
float, long or String fields
respectively). This parameter is only used for static
fields. Its value is ignored for non static fields, which
must be initialized through bytecode instructions in
constructors or methods.public void visitEnd()
ClassVisitor
visitEnd
in class ClassVisitor
public String getClassName()
ClassMetadata
getClassName
in interface ClassMetadata
public boolean isInterface()
ClassMetadata
isInterface
in interface ClassMetadata
public boolean isAnnotation()
ClassMetadata
isAnnotation
in interface ClassMetadata
public boolean isAbstract()
ClassMetadata
isAbstract
in interface ClassMetadata
public boolean isConcrete()
ClassMetadata
isConcrete
in interface ClassMetadata
public boolean isFinal()
ClassMetadata
isFinal
in interface ClassMetadata
public boolean isIndependent()
ClassMetadata
isIndependent
in interface ClassMetadata
public boolean hasEnclosingClass()
ClassMetadata
If this method returns false
, then the
underlying class is a top-level class.
hasEnclosingClass
in interface ClassMetadata
public String getEnclosingClassName()
ClassMetadata
null
if the underlying class is a top-level class.getEnclosingClassName
in interface ClassMetadata
public boolean hasSuperClass()
ClassMetadata
hasSuperClass
in interface ClassMetadata
public String getSuperClassName()
ClassMetadata
null
if there is no super class defined.getSuperClassName
in interface ClassMetadata
public String[] getInterfaceNames()
ClassMetadata
getInterfaceNames
in interface ClassMetadata
public String[] getMemberClassNames()
ClassMetadata
getMemberClassNames
in interface ClassMetadata