Class AnnotationInfo
- java.lang.Object
-
- io.github.classgraph.AnnotationInfo
-
- All Implemented Interfaces:
HasName
,Comparable<AnnotationInfo>
public class AnnotationInfo extends Object implements Comparable<AnnotationInfo>, HasName
Holds metadata about a specific annotation instance on a class, method, method parameter or field.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(AnnotationInfo o)
boolean
equals(Object obj)
ClassInfo
getClassInfo()
Return theClassInfo
object for the annotation class.AnnotationParameterValueList
getDefaultParameterValues()
Get the default parameter values.String
getName()
Get the name.AnnotationParameterValueList
getParameterValues()
Get the parameter values.int
hashCode()
boolean
isInherited()
Checks if the annotation is inherited.Annotation
loadClassAndInstantiate()
Load theAnnotation
class corresponding to thisAnnotationInfo
object, by callinggetClassInfo().loadClass()
, then create a new instance of the annotation, with the annotation parameter values obtained from thisAnnotationInfo
object, possibly overriding default annotation parameter values obtained from callinggetClassInfo()
thenClassInfo.getAnnotationDefaultParameterValues()
.String
toString()
-
-
-
Method Detail
-
getName
public String getName()
Get the name.
-
isInherited
public boolean isInherited()
Checks if the annotation is inherited.- Returns:
- true if this annotation is meta-annotated with
Inherited
.
-
getDefaultParameterValues
public AnnotationParameterValueList getDefaultParameterValues()
Get the default parameter values.- Returns:
- the list of default parameter values for this annotation, or the empty list if none.
-
getParameterValues
public AnnotationParameterValueList getParameterValues()
Get the parameter values.- Returns:
- The parameter values of this annotation, including any default parameter values inherited from the annotation class definition, or the empty list if none.
-
loadClassAndInstantiate
public Annotation loadClassAndInstantiate()
Load theAnnotation
class corresponding to thisAnnotationInfo
object, by callinggetClassInfo().loadClass()
, then create a new instance of the annotation, with the annotation parameter values obtained from thisAnnotationInfo
object, possibly overriding default annotation parameter values obtained from callinggetClassInfo()
thenClassInfo.getAnnotationDefaultParameterValues()
.Note that the returned
Annotation
will have some sort ofInvocationHandler
proxy type, such asio.github.classgraph.features.$Proxy4
orcom.sun.proxy.$Proxy6
. This is an unavoidable side effect of the fact that concreteAnnotation
instances cannot be instantiated directly. (ClassGraph uses the same approach that the JDK uses to instantiate annotations from a map.) However, proxy instances are handled specially when it comes to casting andinstanceof
: you are able to cast the returned proxy instance to the annotation type, andinstanceof
checks against the annotation class will succeed.Of course another option you have for getting the concrete annotations, rather than instantiating the annotations on a
ClassInfo
object via this method, is to callClassInfo.loadClass()
, and read the annotations directly from the returnedClass
object.- Returns:
- The new
Annotation
instance, as a dynamic proxy object that can be cast to the expected annotation type.
-
compareTo
public int compareTo(AnnotationInfo o)
- Specified by:
compareTo
in interfaceComparable<AnnotationInfo>
-
-