Class AnnotationInfo
- java.lang.Object
-
- io.github.classgraph.ScanResultObject
-
- io.github.classgraph.AnnotationInfo
-
- All Implemented Interfaces:
HasName,java.lang.Comparable<AnnotationInfo>
public class AnnotationInfo extends ScanResultObject implements java.lang.Comparable<AnnotationInfo>, HasName
Holds metadata about a specific annotation instance on a class, method, method parameter or field.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classAnnotationInfo.AnnotationInvocationHandlerInvocationHandlerfor dynamically instantiating anAnnotationobject.
-
Field Summary
Fields Modifier and Type Field Description private AnnotationParameterValueListannotationParamValuesThe annotation param values.private booleanannotationParamValuesHasBeenConvertedToPrimitiveSet to true once any Object[] arrays of boxed types in annotationParamValues have been lazily converted to primitive arrays.private AnnotationParameterValueListannotationParamValuesWithDefaultsThe annotation param values with defaults.private java.lang.StringnameThe name.-
Fields inherited from class io.github.classgraph.ScanResultObject
classRef, scanResult
-
-
Constructor Summary
Constructors Constructor Description AnnotationInfo()Default constructor for deserialization.AnnotationInfo(java.lang.String name, AnnotationParameterValueList annotationParamValues)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(AnnotationInfo o)(package private) voidconvertWrapperArraysToPrimitiveArrays()Convert wrapper arrays to primitive arrays.booleanequals(java.lang.Object obj)protected voidfindReferencedClassInfo(java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo, java.util.Set<ClassInfo> refdClassInfo, LogNode log)GetClassInfoobjects for any classes referenced in the type descriptor or type signature.ClassInfogetClassInfo()Return theClassInfoobject for the annotation class.protected java.lang.StringgetClassName()Get the name of the annotation class, forgetClassInfo().AnnotationParameterValueListgetDefaultParameterValues()Get the default parameter values.java.lang.StringgetName()Get the name.AnnotationParameterValueListgetParameterValues()Get the parameter values.AnnotationParameterValueListgetParameterValues(boolean includeDefaultValues)Get the parameter values.inthashCode()booleanisInherited()Checks if the annotation is inherited.java.lang.annotation.AnnotationloadClassAndInstantiate()Load theAnnotationclass corresponding to thisAnnotationInfoobject, by callinggetClassInfo().loadClass(), then create a new instance of the annotation, with the annotation parameter values obtained from thisAnnotationInfoobject, possibly overriding default annotation parameter values obtained from callinggetClassInfo()thenClassInfo.getAnnotationDefaultParameterValues().(package private) voidsetScanResult(ScanResult scanResult)Set ScanResult backreferences in info objects after scan has completed.protected voidtoString(boolean useSimpleNames, java.lang.StringBuilder buf)Render to string.-
Methods inherited from class io.github.classgraph.ScanResultObject
findReferencedClassInfo, loadClass, loadClass, loadClass, loadClass, toString, toString, toStringWithSimpleNames
-
-
-
-
Field Detail
-
name
private java.lang.String name
The name.
-
annotationParamValues
private AnnotationParameterValueList annotationParamValues
The annotation param values.
-
annotationParamValuesHasBeenConvertedToPrimitive
private transient boolean annotationParamValuesHasBeenConvertedToPrimitive
Set to true once any Object[] arrays of boxed types in annotationParamValues have been lazily converted to primitive arrays.
-
annotationParamValuesWithDefaults
private transient AnnotationParameterValueList annotationParamValuesWithDefaults
The annotation param values with defaults.
-
-
Constructor Detail
-
AnnotationInfo
AnnotationInfo()
Default constructor for deserialization.
-
AnnotationInfo
AnnotationInfo(java.lang.String name, AnnotationParameterValueList annotationParamValues)Constructor.- Parameters:
name- The name of the annotation.annotationParamValues- The annotation parameter values, or null if none.
-
-
Method Detail
-
getName
public java.lang.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(boolean includeDefaultValues)
Get the parameter values.- Parameters:
includeDefaultValues- if true, include default values for any annotation parameter value that is missing.- Returns:
- The parameter values of this annotation, including any default parameter values inherited from the annotation class definition (if requested), 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.
-
getClassName
protected java.lang.String getClassName()
Get the name of the annotation class, forgetClassInfo().- Specified by:
getClassNamein classScanResultObject- Returns:
- the class name
-
setScanResult
void setScanResult(ScanResult scanResult)
Description copied from class:ScanResultObjectSet ScanResult backreferences in info objects after scan has completed.- Overrides:
setScanResultin classScanResultObject- Parameters:
scanResult- the scan result
-
findReferencedClassInfo
protected void findReferencedClassInfo(java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo, java.util.Set<ClassInfo> refdClassInfo, LogNode log)
GetClassInfoobjects for any classes referenced in the type descriptor or type signature.- Overrides:
findReferencedClassInfoin classScanResultObject- Parameters:
classNameToClassInfo- the map from class name toClassInfo.refdClassInfo- the referenced class infolog- the log
-
getClassInfo
public ClassInfo getClassInfo()
Return theClassInfoobject for the annotation class.- Overrides:
getClassInfoin classScanResultObject- Returns:
- The
ClassInfoobject for the referenced class.
-
loadClassAndInstantiate
public java.lang.annotation.Annotation loadClassAndInstantiate()
Load theAnnotationclass corresponding to thisAnnotationInfoobject, by callinggetClassInfo().loadClass(), then create a new instance of the annotation, with the annotation parameter values obtained from thisAnnotationInfoobject, possibly overriding default annotation parameter values obtained from callinggetClassInfo()thenClassInfo.getAnnotationDefaultParameterValues().Note that the returned
Annotationwill have some sort ofInvocationHandlerproxy type, such asio.github.classgraph.features.$Proxy4orcom.sun.proxy.$Proxy6. This is an unavoidable side effect of the fact that concreteAnnotationinstances 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, andinstanceofchecks against the annotation class will succeed.Of course another option you have for getting the concrete annotations, rather than instantiating the annotations on a
ClassInfoobject via this method, is to callClassInfo.loadClass(), and read the annotations directly from the returnedClassobject.- Returns:
- The new
Annotationinstance, as a dynamic proxy object that can be cast to the expected annotation type.
-
convertWrapperArraysToPrimitiveArrays
void convertWrapperArraysToPrimitiveArrays()
Convert wrapper arrays to primitive arrays.
-
compareTo
public int compareTo(AnnotationInfo o)
- Specified by:
compareToin interfacejava.lang.Comparable<AnnotationInfo>
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
protected void toString(boolean useSimpleNames, java.lang.StringBuilder buf)Description copied from class:ScanResultObjectRender to string.- Specified by:
toStringin classScanResultObject- Parameters:
useSimpleNames- if true, use just the simple name of each class.buf- the buf
-
-