Class ClassInfo
- All Implemented Interfaces:
AnnotationTarget
Global information including the parent class, implemented methodParameters, and access flags are also provided since this information is often necessary.
Note that a parent class and interface may exist outside of the scope of the index (e.g. classes in a different jar) so the references are stored as names instead of direct references. It is expected that multiple indexes may need to be queried to assemble a full hierarchy in a complex multi-jar environment (e.g. an application server).
Thread-Safety
This class is immutable and can be shared between threads without safe publication.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Provides information on the enclosing method or constructor for a local or anonymous class, if available.private static final class
static enum
Describes the form of nesting used by a classNested classes/interfaces inherited from interface org.jboss.jandex.AnnotationTarget
AnnotationTarget.Kind
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map
<DotName, List<AnnotationInstance>> private static final byte[]
private byte[]
private FieldInternal[]
private short
private boolean
private Type[]
private static final int
private byte[]
private MethodInternal[]
private static final int
private final DotName
private ClassInfo.NestingInfo
private byte[]
private RecordComponentInternal[]
private Type
private Type[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Map
<DotName, List<AnnotationInstance>> Returns a map indexed by annotation name, with a value list of annotation instances.asClass()
Casts and returns this target as aClassInfo
if it is of kindCLASS
asField()
Casts and returns this target as aFieldInfo
if it is of kindFIELD
asMethod()
Casts and returns this target as aMethodInfo
if it is of kindMETHOD
Casts and returns this target as aMethodParameterInfo
if it is of kindMETHOD_PARAMETER
Casts and returns this target as aRecordComponentInfo
if it is of kindRECORD_COMPONENT
asType()
Casts and returns this target as aTypeTarget
if it is of kindTYPE
final AnnotationInstance
classAnnotation
(DotName name) Returns the annotation with the specified name directly declared on this class.final Collection
<AnnotationInstance> Returns a list of all annotations directly declared on this class.final List
<AnnotationInstance> classAnnotationsWithRepeatable
(DotName name, IndexView index) Retrieves annotation instances declared on this class, by the name of the annotation.final List
<MethodInfo> Returns a list of all constructors declared in this class (which the JVM names "<init>").(package private) final Type[]
static ClassInfo
create
(DotName name, DotName superName, short flags, DotName[] interfaces, Map<DotName, List<AnnotationInstance>> annotations, boolean hasNoArgsConstructor) Deprecated.Returns the enclosing class if this is an inner class, or null if this is an anonymous, a local, or a top level class.Returns the enclosing method of this class if it is a local, or anonymous class, and it is declared within the body of a method or constructor.final FieldInfo
Retrieves a field by the given name.(package private) final FieldInternal[]
(package private) final byte[]
fields()
Returns a list of all available fields.final MethodInfo
firstMethod
(String name) Retrieves the "first" occurrence of a method by the given name.final short
flags()
Returns the access flags for this class.final boolean
Returns a boolean indicating the presence of a no-arg constructor, if supported by the underlying index store.Returns a list of names for all interfaces this class implements.final DotName[]
Deprecated.(package private) final Type[]
Returns the list of types in the implements clause of this class.final boolean
final boolean
isEnum()
final boolean
isModule()
final boolean
isRecord()
final boolean
final AnnotationTarget.Kind
kind()
Returns the kind of object this target represents.final MethodInfo
Retrieves a method based on its signature, which includes a method name and an argument list.(package private) final MethodInternal[]
(package private) final byte[]
final List
<MethodInfo> methods()
Returns a list of all methods declared in this class.module()
Returns the module information from this class if it is a module descriptor, i.e.final DotName
name()
Returns the name of the class(package private) String
Returns the nesting type of this class, which could either be a standard top level class, an inner class, an anonymous class, or a local class.final RecordComponentInfo
recordComponent
(String name) Retrieves a record component by the given name.(package private) final RecordComponentInternal[]
(package private) final byte[]
final List
<RecordComponentInfo> Returns a list of all record components declared by this class.(package private) final void
setAnnotations
(Map<DotName, List<AnnotationInstance>> annotations) (package private) void
setEnclosingMethod
(ClassInfo.EnclosingMethodInfo enclosingMethod) (package private) void
setFieldArray
(FieldInternal[] fields) (package private) void
setFieldPositionArray
(byte[] fieldPositions) (package private) void
(package private) void
setFlags
(short flags) (package private) void
setHasNoArgsConstructor
(boolean hasNoArgsConstructor) (package private) void
setInnerClassInfo
(DotName enclosingClass, String simpleName, boolean knownInnerClass) (package private) void
setInterfaceTypes
(Type[] interfaceTypes) (package private) void
setMethodArray
(MethodInternal[] methods) (package private) void
setMethodPositionArray
(byte[] methodPositions) (package private) void
setMethods
(List<MethodInfo> methods, NameTable names) (package private) void
setModule
(ModuleInfo module) (package private) void
setRecordComponentArray
(RecordComponentInternal[] recordComponents) (package private) void
setRecordComponentPositionArray
(byte[] recordComponentPositions) (package private) void
setRecordComponents
(List<RecordComponentInfo> recordComponents, NameTable names) (package private) void
setSuperClassType
(Type superClassType) (package private) void
setTypeParameters
(Type[] typeParameters) Returns the source declared name of this class if it is an inner class, or a local class.(package private) static <T> byte[]
sortAndGetPositions
(T[] internals, Comparator<T> comparator, NameTable names) Sorts the array of internals using the provided comparator and returns an array of offsets in the original order of internals.final Type
Returns a super type represented by the extends clause of this class.final DotName
Returns the name of the super class declared by the extends clause of this class.toString()
(package private) final Type[]
final List
<TypeVariable> Returns the generic type parameters of this class, if any.final List
<MethodInfo> final List
<RecordComponentInfo>
-
Field Details
-
MODULE
private static final int MODULE- See Also:
-
MAX_POSITIONS
private static final int MAX_POSITIONS- See Also:
-
EMPTY_POSITIONS
private static final byte[] EMPTY_POSITIONS -
name
-
annotations
-
flags
private short flags -
interfaceTypes
-
superClassType
-
typeParameters
-
methods
-
fields
-
recordComponents
-
methodPositions
private byte[] methodPositions -
fieldPositions
private byte[] fieldPositions -
recordComponentPositions
private byte[] recordComponentPositions -
hasNoArgsConstructor
private boolean hasNoArgsConstructor -
nestingInfo
-
-
Constructor Details
-
ClassInfo
-
ClassInfo
-
-
Method Details
-
create
@Deprecated public static ClassInfo create(DotName name, DotName superName, short flags, DotName[] interfaces, Map<DotName, List<AnnotationInstance>> annotations, boolean hasNoArgsConstructor) Deprecated.Constructs a "mock" ClassInfo using the passed values. All passed values MUST NOT BE MODIFIED AFTER THIS CALL. Otherwise the resulting object would not conform to the contract outlined above.- Parameters:
name
- the name of this classsuperName
- the name of the parent classflags
- the class attributesinterfaces
- the methodParameters this class implementsannotations
- the annotations on this classhasNoArgsConstructor
- whether this class has a no arg constructor- Returns:
- a new mock class representation
-
kind
Description copied from interface:AnnotationTarget
Returns the kind of object this target represents.- Specified by:
kind
in interfaceAnnotationTarget
- Returns:
- the target kind.
-
toString
-
name
Returns the name of the class- Returns:
- the name of the class
-
flags
public final short flags()Returns the access flags for this class. The standardModifier
can be used to decode the value.- Returns:
- the access flags
-
isSynthetic
public final boolean isSynthetic()- Returns:
true
if this class is a synthetic class
-
isEnum
public final boolean isEnum()- Returns:
true
if this class was declared as an enum
-
isAnnotation
public final boolean isAnnotation()- Returns:
true
if this class object represents an annotation type
-
isRecord
public final boolean isRecord()- Returns:
true
if this class was declared as a record
-
isModule
public final boolean isModule()- Returns:
true
if this class object represents a Java module descriptor
-
superName
Returns the name of the super class declared by the extends clause of this class. This information is also available from thesuperClassType
method. For all classes, with the one exception ofjava.lang.Object
, which is the one class in the Java language without a super-type, this method will always return a non-null value.- Returns:
- the name of the super class of this class, or null if this class is
java.lang.Object
-
interfaces
Deprecated.Returns an array of interface names implemented by this class. Every call to this method performs a defensive copy, sointerfaceNames()
should be used instead.- Returns:
- an array of interface names implemented by this class
-
annotations
Returns a map indexed by annotation name, with a value list of annotation instances. The annotation instances in this map correspond to both annotations on the class, and every nested element of the class (fields, types, methods, etc).The target of the annotation instance can be used to determine the location of the annotation usage.
- Returns:
- the annotations specified on this class and its elements
-
setAnnotations
-
classAnnotations
Returns a list of all annotations directly declared on this class.- Returns:
- the list of annotations declared on this class
-
classAnnotation
Returns the annotation with the specified name directly declared on this class.- Parameters:
name
- the annotation name to look for- Returns:
- the declared annotation or null if not found
-
classAnnotationsWithRepeatable
Retrieves annotation instances declared on this class, by the name of the annotation. If the specified annotation is repeatable (JLS 9.6), then attempt to result contains the values from the containing annotation.- Parameters:
name
- the name of the annotationindex
- the index used to obtain the annotation class- Returns:
- the annotation instances declared on this field, or an empty list if none
-
methods
Returns a list of all methods declared in this class. This includes constructors and static initializer blocks which have the special JVM assigned names of "<init>" and "<clinit>", respectively. It does not, however, include inherited methods. These must be discovered by traversing the class hierarchy.This list may be empty, but never null.
- Returns:
- the list of methods declared in this class
-
unsortedMethods
-
constructors
Returns a list of all constructors declared in this class (which the JVM names "<init>"). It does not include inherited methods. These must be discovered by traversing the class hierarchy.This list may never be null.
- Returns:
- the list of constructors declared in this class
-
methodArray
-
methodPositionArray
final byte[] methodPositionArray() -
method
Retrieves a method based on its signature, which includes a method name and an argument list. The argument list is compared based on the underlying raw type of the type arguments. As an example, a generic type parameter "T" is equivalent tojava.lang.Object
, since the raw form of a type parameter is its upper bound.Eligible methods include constructors and static initializer blocks which have the special JVM assigned names of "<init>" and "<clinit>", respectively. This does not, however, include inherited methods. These must be discovered by traversing the class hierarchy.
- Parameters:
name
- the name of the method to findparameters
- the type parameters of the method- Returns:
- the located method or null if not found
-
firstMethod
Retrieves the "first" occurrence of a method by the given name. Note that the order of methods is not defined, and may change in the future. Therefore, this method should not be used when overloading is possible. It's merely intended to provide a handy shortcut for throw away or test code.- Parameters:
name
- the name of the method- Returns:
- the first discovered method matching this name, or null if no match is found
-
field
Retrieves a field by the given name. Only fields declared in this class are available. Locating inherited fields requires traversing the class hierarchy.- Parameters:
name
- the name of the field- Returns:
- the field
-
fields
Returns a list of all available fields. Only fields declared in this class are available. Locating inherited fields requires traversing the class hierarchy. This list may be empty, but never null.- Returns:
- a list of fields
-
unsortedFields
-
fieldArray
-
fieldPositionArray
final byte[] fieldPositionArray() -
recordComponent
Retrieves a record component by the given name.- Parameters:
name
- the name of the record component- Returns:
- the record component
-
recordComponents
Returns a list of all record components declared by this class. This list may be empty, but never null.- Returns:
- a list of record components
-
unsortedRecordComponents
-
recordComponentArray
-
recordComponentPositionArray
final byte[] recordComponentPositionArray() -
interfaceNames
Returns a list of names for all interfaces this class implements. This list may be empty, but never null.Note that this information is also available on the
Type
instances returned byinterfaceTypes
- Returns:
- the list of names implemented by this class
-
interfaceTypes
Returns the list of types in the implements clause of this class. These types may be generic types. This list may be empty, but never null- Returns:
- the list of types declared in the implements clause of this class
-
interfaceTypeArray
-
copyInterfaceTypes
-
superClassType
Returns a super type represented by the extends clause of this class. This type might be a generic type.- Returns:
- the super class type definition in the extends clause
-
typeParameters
Returns the generic type parameters of this class, if any. These will be returned as resolved type variables, so if a parameter has a bound on another parameter, that information will be available.- Returns:
- the generic type parameters of this class
-
typeParameterArray
-
hasNoArgsConstructor
public final boolean hasNoArgsConstructor()Returns a boolean indicating the presence of a no-arg constructor, if supported by the underlying index store. This information is available in indexes produced by Jandex 1.2.0 and later.- Returns:
true
in case of the Java class has a no-copyParameters constructor,false
if it does not, or it is not known- Since:
- 1.2.0
-
nestingType
Returns the nesting type of this class, which could either be a standard top level class, an inner class, an anonymous class, or a local class.For historical reasons, static nested classes are returned as
INNER
. You can differentiate between a non-static nested class (inner class) and a static nested class by callingModifier.isStatic(int)
on the return offlags()
- Returns:
- the nesting type of this class
-
simpleName
Returns the source declared name of this class if it is an inner class, or a local class. Otherwise this method will return null.- Returns:
- the simple name of a top-level, local, or inner class, or null if this is an anonymous class
-
nestingSimpleName
String nestingSimpleName() -
enclosingClass
Returns the enclosing class if this is an inner class, or null if this is an anonymous, a local, or a top level class.- Returns:
- the enclosing class if this class is an inner class
-
enclosingMethod
Returns the enclosing method of this class if it is a local, or anonymous class, and it is declared within the body of a method or constructor. It will return null if this class is a top level, or an inner class. It will also return null if the local or anonymous class is on an initializer.- Returns:
- the enclosing method/constructor, if this class is local or anonymous, and it is within a method/constructor
-
module
Returns the module information from this class if it is a module descriptor, i.e. module-info.- Returns:
- the module descriptor for module classes, otherwise null
-
asClass
Description copied from interface:AnnotationTarget
Casts and returns this target as aClassInfo
if it is of kindCLASS
- Specified by:
asClass
in interfaceAnnotationTarget
- Returns:
- this instance cast to a class
-
asField
Description copied from interface:AnnotationTarget
Casts and returns this target as aFieldInfo
if it is of kindFIELD
- Specified by:
asField
in interfaceAnnotationTarget
- Returns:
- this instance cast to a field
-
asMethod
Description copied from interface:AnnotationTarget
Casts and returns this target as aMethodInfo
if it is of kindMETHOD
- Specified by:
asMethod
in interfaceAnnotationTarget
- Returns:
- this instance cast to a method
-
asMethodParameter
Description copied from interface:AnnotationTarget
Casts and returns this target as aMethodParameterInfo
if it is of kindMETHOD_PARAMETER
- Specified by:
asMethodParameter
in interfaceAnnotationTarget
- Returns:
- this instance cast to a method parameter
-
asType
Description copied from interface:AnnotationTarget
Casts and returns this target as aTypeTarget
if it is of kindTYPE
- Specified by:
asType
in interfaceAnnotationTarget
- Returns:
- this instance cast to a type target
-
asRecordComponent
Description copied from interface:AnnotationTarget
Casts and returns this target as aRecordComponentInfo
if it is of kindRECORD_COMPONENT
- Specified by:
asRecordComponent
in interfaceAnnotationTarget
- Returns:
- this instance cast to a record component
-
setHasNoArgsConstructor
void setHasNoArgsConstructor(boolean hasNoArgsConstructor) -
setFields
-
setFieldArray
-
setFieldPositionArray
void setFieldPositionArray(byte[] fieldPositions) -
setMethodArray
-
setMethodPositionArray
void setMethodPositionArray(byte[] methodPositions) -
setMethods
-
setRecordComponentArray
-
setRecordComponentPositionArray
void setRecordComponentPositionArray(byte[] recordComponentPositions) -
setRecordComponents
-
sortAndGetPositions
Sorts the array of internals using the provided comparator and returns an array of offsets in the original order of internals.- Type Parameters:
T
- An internal member type, FieldInternal or MethodInternal- Parameters:
internals
- Array of internal types set on the ClassInfo instancecomparator
- Comparator used to sort internals and locate original positionsnames
- NameTable used to intern byte arrays of member positions- Returns:
- an array offsets in the array of internals in the order prior to sorting
-
setSuperClassType
-
setInterfaceTypes
-
setTypeParameters
-
setInnerClassInfo
-
setEnclosingMethod
-
setModule
-
setFlags
void setFlags(short flags)
-