public class AnnotationInfo extends Object implements Comparable<AnnotationInfo>, HasName
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(AnnotationInfo o) |
boolean |
equals(Object obj) |
ClassInfo |
getClassInfo()
Return the
ClassInfo object for the annotation class. |
AnnotationParameterValueList |
getDefaultParameterValues()
Get the default parameter values.
|
String |
getName()
Get the name.
|
AnnotationParameterValueList |
getParameterValues()
Get the parameter values.
|
AnnotationParameterValueList |
getParameterValues(boolean includeDefaultValues)
Get the parameter values.
|
int |
hashCode() |
boolean |
isInherited()
Checks if the annotation is inherited.
|
Annotation |
loadClassAndInstantiate()
Load the
Annotation class corresponding to this AnnotationInfo object, by calling
getClassInfo().loadClass(), then create a new instance of the annotation, with the annotation
parameter values obtained from this AnnotationInfo object, possibly overriding default annotation
parameter values obtained from calling getClassInfo() then
ClassInfo.getAnnotationDefaultParameterValues(). |
String |
toString()
Render to string.
|
String |
toStringWithSimpleNames()
Render to string, using only simple
names for classes.
|
public String getName()
public boolean isInherited()
Inherited.public AnnotationParameterValueList getDefaultParameterValues()
public AnnotationParameterValueList getParameterValues(boolean includeDefaultValues)
includeDefaultValues - if true, include default values for any annotation parameter value that is missing.public AnnotationParameterValueList getParameterValues()
public ClassInfo getClassInfo()
ClassInfo object for the annotation class.ClassInfo object for the referenced class.public Annotation loadClassAndInstantiate()
Annotation class corresponding to this AnnotationInfo object, by calling
getClassInfo().loadClass(), then create a new instance of the annotation, with the annotation
parameter values obtained from this AnnotationInfo object, possibly overriding default annotation
parameter values obtained from calling getClassInfo() then
ClassInfo.getAnnotationDefaultParameterValues().
Note that the returned Annotation will have some sort of InvocationHandler proxy type, such
as io.github.classgraph.features.$Proxy4 or com.sun.proxy.$Proxy6. This is an unavoidable
side effect of the fact that concrete Annotation 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 and instanceof: you are able to cast the returned proxy
instance to the annotation type, and instanceof 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 call ClassInfo.loadClass(), and read
the annotations directly from the returned Class object.
Annotation instance, as a dynamic proxy object that can be cast to the expected
annotation type.public int compareTo(AnnotationInfo o)
compareTo in interface Comparable<AnnotationInfo>public String toStringWithSimpleNames()
Copyright © 2022. All rights reserved.