Top Description Inners Fields Constructors Methods
io.github.classgraph

public Class AnnotationInfo

extends ScanResultObject
implements Comparable<AnnotationInfo>, HasName
Class Inheritance
All Implemented Interfaces
io.github.classgraph.HasName, java.lang.Comparable
Imports
java.lang.annotation.Annotation, .IncompleteAnnotationException, .Inherited, java.lang.reflect.InvocationHandler, .Method, .Proxy, java.util.Arrays, .HashMap, .Map, .Map.Entry, .Set, nonapi.io.github.classgraph.reflection.ReflectionUtils, nonapi.io.github.classgraph.utils.LogNode

Holds metadata about a specific annotation instance on a class, method, method parameter or field.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private AnnotationParameterValueList
annotationParamValues

The annotation param values.

private transient boolean
annotationParamValuesHasBeenConvertedToPrimitive

Set to true once any Object[] arrays of boxed types in annotationParamValues have been lazily converted to primitive arrays.

private transient AnnotationParameterValueList
annotationParamValuesWithDefaults

The annotation param values with defaults.

private String
name

The name.

Inherited from io.github.classgraph.ScanResultObject:
classRefscanResult

Constructor Summary

AccessConstructor and Description
pack-priv
AnnotationInfo()

Default constructor for deserialization.

pack-priv
AnnotationInfo(final String
The name of the annotation.
name
,
final AnnotationParameterValueList
The annotation parameter values, or null if none.
annotationParamValues
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(final AnnotationInfo
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

pack-priv void
convertWrapperArraysToPrimitiveArrays()

Convert wrapper arrays to primitive arrays.

public boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

protected void
findReferencedClassInfo(final Map<String, ClassInfo>
the map from class name to ClassInfo.
classNameToClassInfo
,
final Set<ClassInfo>
the referenced class info
refdClassInfo
,
final LogNode
the log
log
)

Overrides io.github.classgraph.ScanResultObject.findReferencedClassInfo.

Get ClassInfo objects for any classes referenced in the type descriptor or type signature.

public ClassInfo
getClassInfo()

Overrides io.github.classgraph.ScanResultObject.getClassInfo.

Return the ClassInfo object for the annotation class.

protected String

Returns:

the class name
getClassName
()

Implements abstract io.github.classgraph.ScanResultObject.getClassName.

Get the name of the annotation class, for getClassInfo().

public AnnotationParameterValueList

Returns:

the list of default parameter values for this annotation, or the empty list if none.
getDefaultParameterValues
()

Get the default parameter values.

public String

Returns:

The name of the annotation class.
getName
()

Implements io.github.classgraph.HasName.getName.

Get the name.

public AnnotationParameterValueList

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
(final boolean
if true, include default values for any annotation parameter value that is missing.
includeDefaultValues
)

Get the parameter values.

public AnnotationParameterValueList

Returns:

The parameter values of this annotation, including any default parameter values inherited from the annotation class definition, or the empty list if none.
getParameterValues
()

Get the parameter values.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

true if this annotation is meta-annotated with Inherited.
isInherited
()

Checks if the annotation is inherited.

public Annotation

Returns:

The new Annotation instance, as a dynamic proxy object that can be cast to the expected annotation type.
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 AnnotationInfo#getClassInfo() then ClassInfo#getAnnotationDefaultParameterValues().

pack-priv void
setScanResult(final ScanResult
the scan result
scanResult
)

Overrides io.github.classgraph.ScanResultObject.setScanResult.

Set ScanResult backreferences in info objects after scan has completed.

protected void
toString(final boolean
if true, use just the simple name of each class.
useSimpleNames
,
final StringBuilder
the buf
buf
)

Implements abstract io.github.classgraph.ScanResultObject.toString.

Render to string.

Inherited from io.github.classgraph.ScanResultObject:
findReferencedClassInfoloadClassloadClassloadClassloadClasstoStringtoStringtoStringWithSimpleNames

Field Detail

annotationParamValuesback to summary
private AnnotationParameterValueList annotationParamValues

The annotation param values.

annotationParamValuesHasBeenConvertedToPrimitiveback to summary
private transient boolean annotationParamValuesHasBeenConvertedToPrimitive

Set to true once any Object[] arrays of boxed types in annotationParamValues have been lazily converted to primitive arrays.

annotationParamValuesWithDefaultsback to summary
private transient AnnotationParameterValueList annotationParamValuesWithDefaults

The annotation param values with defaults.

nameback to summary
private String name

The name.

Constructor Detail

AnnotationInfoback to summary
pack-priv AnnotationInfo()

Default constructor for deserialization.

AnnotationInfoback to summary
pack-priv AnnotationInfo(final String name, final AnnotationParameterValueList annotationParamValues)

Constructor.

Parameters
name:String

The name of the annotation.

annotationParamValues:AnnotationParameterValueList

The annotation parameter values, or null if none.

Method Detail

compareToback to summary
public int compareTo(final AnnotationInfo o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
o:AnnotationInfo

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
convertWrapperArraysToPrimitiveArraysback to summary
pack-priv void convertWrapperArraysToPrimitiveArrays()

Convert wrapper arrays to primitive arrays.

equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
findReferencedClassInfoback to summary
protected void findReferencedClassInfo(final Map<String, ClassInfo> classNameToClassInfo, final Set<ClassInfo> refdClassInfo, final LogNode log)

Overrides io.github.classgraph.ScanResultObject.findReferencedClassInfo.

Get ClassInfo objects for any classes referenced in the type descriptor or type signature.

Parameters
classNameToClassInfo:Map<String, ClassInfo>

the map from class name to ClassInfo.

refdClassInfo:Set<ClassInfo>

the referenced class info

log:LogNode

Doc from io.github.classgraph.ScanResultObject.findReferencedClassInfo.

the log

Annotations
@Override
getClassInfoback to summary
public ClassInfo getClassInfo()

Overrides io.github.classgraph.ScanResultObject.getClassInfo.

Return the ClassInfo object for the annotation class.

Returns:ClassInfo

Doc from io.github.classgraph.ScanResultObject.getClassInfo.

The ClassInfo object for the referenced class.

Annotations
@Override
getClassNameback to summary
protected String getClassName()

Implements abstract io.github.classgraph.ScanResultObject.getClassName.

Get the name of the annotation class, for getClassInfo().

Returns:String

the class name

Annotations
@Override
getDefaultParameterValuesback to summary
public AnnotationParameterValueList getDefaultParameterValues()

Get the default parameter values.

Returns:AnnotationParameterValueList

the list of default parameter values for this annotation, or the empty list if none.

getNameback to summary
public String getName()

Implements io.github.classgraph.HasName.getName.

Get the name.

Returns:String

The name of the annotation class.

Annotations
@Override
getParameterValuesback to summary
public AnnotationParameterValueList getParameterValues(final boolean includeDefaultValues)

Get the parameter values.

Parameters
includeDefaultValues:boolean

if true, include default values for any annotation parameter value that is missing.

Returns:AnnotationParameterValueList

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.

getParameterValuesback to summary
public AnnotationParameterValueList getParameterValues()

Get the parameter values.

Returns:AnnotationParameterValueList

The parameter values of this annotation, including any default parameter values inherited from the annotation class definition, or the empty list if none.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isInheritedback to summary
public boolean isInherited()

Checks if the annotation is inherited.

Returns:boolean

true if this annotation is meta-annotated with Inherited.

loadClassAndInstantiateback to summary
public 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 AnnotationInfo#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.

Returns:Annotation

The new Annotation instance, as a dynamic proxy object that can be cast to the expected annotation type.

setScanResultback to summary
pack-priv void setScanResult(final ScanResult scanResult)

Overrides io.github.classgraph.ScanResultObject.setScanResult.

Doc from io.github.classgraph.ScanResultObject.setScanResult.

Set ScanResult backreferences in info objects after scan has completed.

Parameters
scanResult:ScanResult

the scan result

Annotations
@Override
toStringback to summary
protected void toString(final boolean useSimpleNames, final StringBuilder buf)

Implements abstract io.github.classgraph.ScanResultObject.toString.

Doc from io.github.classgraph.ScanResultObject.toString.

Render to string.

Parameters
useSimpleNames:boolean

if true, use just the simple name of each class.

buf:StringBuilder

the buf

Annotations
@Override
io.github.classgraph back to summary

private Class AnnotationInfo.AnnotationInvocationHandler

extends Object
implements InvocationHandler
Class Inheritance
  • java.lang.Object
  • io.github.classgraph.AnnotationInfo.AnnotationInvocationHandler
All Implemented Interfaces
java.lang.reflect.InvocationHandler

InvocationHandler for dynamically instantiating an Annotation object.

Field Summary

Modifier and TypeField and Description
private final Class<? extends Annotation>
annotationClass

The annotation class.

private final AnnotationInfo
annotationInfo

The AnnotationInfo object for this annotation.

private final Map<String, Object>
annotationParameterValuesInstantiated

The annotation parameter values instantiated.

Constructor Summary

AccessConstructor and Description
pack-priv
AnnotationInvocationHandler(final Class<? extends Annotation>
the annotation class
annotationClass
,
final AnnotationInfo
the annotation info
annotationInfo
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public Object
invoke(final Object
the proxy instance that the method was invoked on
proxy
,
final Method
the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
method
,
final Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
args
)

Implements java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotationClassback to summary
private final Class<? extends Annotation> annotationClass

The annotation class.

annotationInfoback to summary
private final AnnotationInfo annotationInfo

The AnnotationInfo object for this annotation.

annotationParameterValuesInstantiatedback to summary
private final Map<String, Object> annotationParameterValuesInstantiated

The annotation parameter values instantiated.

Constructor Detail

AnnotationInvocationHandlerback to summary
pack-priv AnnotationInvocationHandler(final Class<? extends Annotation> annotationClass, final AnnotationInfo annotationInfo)

Constructor.

Parameters
annotationClass:Class<? extends Annotation>

the annotation class

annotationInfo:AnnotationInfo

the annotation info

Method Detail

invokeback to summary
public Object invoke(final Object proxy, final Method method, final Object[] args)

Implements java.lang.reflect.InvocationHandler.invoke.

Doc from java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.

Parameters
proxy:Object

the proxy instance that the method was invoked on

method:Method

the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.

args:Object[]

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.

Returns:Object

the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.

Annotations
@Override