Class ClassInfo
- java.lang.Object
-
- org.jboss.jandex.ClassInfo
-
- All Implemented Interfaces:
AnnotationTarget
,Declaration
,Descriptor
,GenericSignature
public final class ClassInfo extends java.lang.Object implements Declaration, Descriptor, GenericSignature
Represents a class entry in an index. A ClassInfo is only a partial view of a Java class, it is not intended as a complete replacement for Java reflection.Global information including the parent class, implemented interfaces, and access flags are also provided since this information is often necessary. Implicitly declared (aka mandated) and synthetic members are included as well.
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 Classes Modifier and Type Class Description static class
ClassInfo.EnclosingMethodInfo
Provides information on the enclosing method or constructor for a local or anonymous class, if available.private static class
ClassInfo.ExtraInfo
private static class
ClassInfo.NestingInfo
static class
ClassInfo.NestingType
Describes the form of nesting used by a class-
Nested classes/interfaces inherited from interface org.jboss.jandex.AnnotationTarget
AnnotationTarget.Kind
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<DotName,java.util.List<AnnotationInstance>>
annotations
private static byte[]
EMPTY_POSITIONS
private ClassInfo.ExtraInfo
extra
private byte[]
fieldPositions
private FieldInternal[]
fields
private short
flags
private boolean
hasNoArgsConstructor
private Type[]
interfaceTypes
private static int
MAX_POSITIONS
private byte[]
methodPositions
private MethodInternal[]
methods
private DotName
name
private ClassInfo.NestingInfo
nestingInfo
private Type
superClassType
-
Fields inherited from interface org.jboss.jandex.Descriptor
NO_SUBSTITUTION
-
Fields inherited from interface org.jboss.jandex.GenericSignature
NO_SUBSTITUTION
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description AnnotationInstance
annotation(DotName name)
Returns the annotation instance with given name declared on this class, any of its members, or any type within the signature of the class or its members.java.util.List<AnnotationInstance>
annotations()
Returns the annotation instances declared on this class, any of its members, or any type within the signature of the class or its members.java.util.List<AnnotationInstance>
annotations(DotName name)
Returns the annotation instances with given name declared on this class, any of its members, or any type within the signature of the class or its members.java.util.Map<DotName,java.util.List<AnnotationInstance>>
annotations$$bridge()
java.util.Map<DotName,java.util.List<AnnotationInstance>>
annotationsMap()
Returns a map indexed by annotation name, with a value list of annotation instances.java.util.List<AnnotationInstance>
annotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this class, any of its members, or any type within the signature of the class or its members.ClassInfo
asClass()
Casts and returns this target as aClassInfo
if it is of kindCLASS
FieldInfo
asField()
Casts and returns this target as aFieldInfo
if it is of kindFIELD
MethodInfo
asMethod()
Casts and returns this target as aMethodInfo
if it is of kindMETHOD
MethodParameterInfo
asMethodParameter()
Casts and returns this target as aMethodParameterInfo
if it is of kindMETHOD_PARAMETER
RecordComponentInfo
asRecordComponent()
Casts and returns this target as aRecordComponentInfo
if it is of kindRECORD_COMPONENT
TypeTarget
asType()
Casts and returns this target as aTypeTarget
if it is of kindTYPE
MethodInfo
canonicalRecordConstructor()
Returns the canonical constructor of this record.AnnotationInstance
classAnnotation(DotName name)
Deprecated.java.util.Collection<AnnotationInstance>
classAnnotations()
Deprecated.java.util.List<AnnotationInstance>
classAnnotationsWithRepeatable(DotName name, IndexView index)
Deprecated.java.util.List<MethodInfo>
constructors()
Returns a list of all constructors declared in this class (which have the special name<init>
).(package private) Type[]
copyInterfaceTypes()
static ClassInfo
create(DotName name, DotName superName, short flags, DotName[] interfaces, java.util.Map<DotName,java.util.List<AnnotationInstance>> annotations, boolean hasNoArgsConstructor)
Deprecated.AnnotationInstance
declaredAnnotation(DotName name)
Returns the annotation instance with given name declared on this class.java.util.List<AnnotationInstance>
declaredAnnotations()
Returns the annotation instances declared on this class.java.util.List<AnnotationInstance>
declaredAnnotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this class.java.lang.String
descriptor(java.util.function.Function<java.lang.String,Type> typeVariableSubstitution)
Returns a bytecode descriptor of the type introduced by this class.DotName
enclosingClass()
Returns the enclosing class if this is a member class, ornull
if this is a top-level, local or anonymous class.ClassInfo.EnclosingMethodInfo
enclosingMethod()
Returns the enclosing method of this class if it is a local or anonymous class declared within the body of a method or constructor.(package private) int
enumConstantOrdinal(FieldInternal enumConstant)
java.util.List<FieldInfo>
enumConstants()
Returns a list of enum constants declared by this enum class, represented asFieldInfo
.FieldInfo
field(java.lang.String name)
Retrieves a field by the given name.(package private) FieldInternal[]
fieldArray()
(package private) byte[]
fieldPositionArray()
java.util.List<FieldInfo>
fields()
Returns a list of all available fields.java.util.List<FieldInfo>
fieldsInDeclarationOrder()
Returns a list of all fields declared in this class, in the declaration order.MethodInfo
firstMethod(java.lang.String name)
Retrieves the "first" occurrence of a method by the given name.short
flags()
Returns the access flags for this class.java.lang.String
genericSignature(java.util.function.Function<java.lang.String,Type> typeVariableSubstitution)
Returns a generic signature of this class, possibly without any generic-related information.boolean
hasAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this class, any of its members, or any type within the signature of the class or its members.boolean
hasDeclaredAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this class.boolean
hasNoArgsConstructor()
Returns whether this class declares a zero-parameter constructor.java.util.List<DotName>
interfaceNames()
Returns a list of names for all interfaces this class implements.DotName[]
interfaces()
Deprecated.(package private) Type[]
interfaceTypeArray()
java.util.List<Type>
interfaceTypes()
Returns the list of types in theimplements
clause of this class.boolean
isAbstract()
boolean
isAnnotation()
boolean
isEnum()
boolean
isFinal()
boolean
isInterface()
boolean
isModule()
boolean
isRecord()
boolean
isSealed()
boolean
isSynthetic()
AnnotationTarget.Kind
kind()
Returns the kind of object this target represents.java.util.Set<DotName>
memberClasses()
Returns a set of names of member classes declared in this class.MethodInfo
method(java.lang.String name, java.util.List<Type> parameters)
Retrieves a method based on its signature, which includes a method name and a parameter type list.MethodInfo
method(java.lang.String name, Type... parameters)
Retrieves a method based on its signature, which includes a method name and a parameter type list.(package private) MethodInternal[]
methodArray()
(package private) byte[]
methodPositionArray()
java.util.List<MethodInfo>
methods()
Returns a list of all methods declared in this class.java.util.List<MethodInfo>
methodsInDeclarationOrder()
Returns a list of all methods declared in this class, in the declaration order.ModuleInfo
module()
Returns the module information from this class if it is a module descriptor, i.e.DotName
name()
Returns the binary name of the class as aDotName
.(package private) java.lang.String
nestingSimpleName()
ClassInfo.NestingType
nestingType()
Returns the nesting type of this class, which could either be a standard top level class, a member class (NestingType.INNER
), an anonymous class, or a local class.java.util.Set<DotName>
permittedSubclasses()
Returns the set of permitted subclasses of thissealed
class (or interface).RecordComponentInfo
recordComponent(java.lang.String name)
Retrieves a record component by the given name.(package private) RecordComponentInternal[]
recordComponentArray()
(package private) byte[]
recordComponentPositionArray()
java.util.List<RecordComponentInfo>
recordComponents()
Returns a list of all record components declared by this class.java.util.List<RecordComponentInfo>
recordComponentsInDeclarationOrder()
Returns a list of all record components declared in this class, in the declaration order.boolean
requiresGenericSignature()
Returns whether this class must have a generic signature.(package private) void
setAnnotations(java.util.Map<DotName,java.util.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
setFields(java.util.List<FieldInfo> fields, NameTable names)
(package private) void
setFlags(short flags)
(package private) void
setHasNoArgsConstructor(boolean hasNoArgsConstructor)
(package private) void
setInnerClassInfo(DotName enclosingClass, java.lang.String simpleName, boolean knownInnerClass)
(package private) void
setInterfaceTypes(Type[] interfaceTypes)
(package private) void
setMemberClasses(java.util.Set<DotName> memberClasses)
(package private) void
setMethodArray(MethodInternal[] methods)
(package private) void
setMethodPositionArray(byte[] methodPositions)
(package private) void
setMethods(java.util.List<MethodInfo> methods, NameTable names)
(package private) void
setModule(ModuleInfo module)
(package private) void
setPermittedSubclasses(java.util.Set<DotName> permittedSubclasses)
(package private) void
setRecordComponentArray(RecordComponentInternal[] recordComponents)
(package private) void
setRecordComponentPositionArray(byte[] recordComponentPositions)
(package private) void
setRecordComponents(java.util.List<RecordComponentInfo> recordComponents, NameTable names)
(package private) void
setSuperClassType(Type superClassType)
(package private) void
setTypeParameters(Type[] typeParameters)
java.lang.String
simpleName()
Returns the source declared name of this class if it is a top-level class, member class or a local class.(package private) static <T> byte[]
sortAndGetPositions(T[] internals, java.util.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.Type
superClassType()
Returns a super type represented by the extends clause of this class.DotName
superName()
Returns the name of the super class declared by the extends clause of this class.java.lang.String
toString()
Returns the binary name of this class.(package private) Type[]
typeParameterArray()
java.util.List<TypeVariable>
typeParameters()
Returns the generic type parameters of this class, if any.java.util.List<FieldInfo>
unsortedFields()
Deprecated.java.util.List<MethodInfo>
unsortedMethods()
Deprecated.java.util.List<RecordComponentInfo>
unsortedRecordComponents()
Deprecated.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jboss.jandex.AnnotationTarget
annotation, annotation, annotations, annotations, annotationsWithRepeatable, annotationsWithRepeatable, declaredAnnotation, declaredAnnotation, declaredAnnotationsWithRepeatable, declaredAnnotationsWithRepeatable, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation
-
Methods inherited from interface org.jboss.jandex.Declaration
asDeclaration, isDeclaration
-
Methods inherited from interface org.jboss.jandex.Descriptor
descriptor
-
Methods inherited from interface org.jboss.jandex.GenericSignature
genericSignature, genericSignatureIfRequired, genericSignatureIfRequired
-
-
-
-
Field Detail
-
MAX_POSITIONS
private static final int MAX_POSITIONS
- See Also:
- Constant Field Values
-
EMPTY_POSITIONS
private static final byte[] EMPTY_POSITIONS
-
name
private final DotName name
-
annotations
private java.util.Map<DotName,java.util.List<AnnotationInstance>> annotations
-
flags
private short flags
-
hasNoArgsConstructor
private boolean hasNoArgsConstructor
-
interfaceTypes
private Type[] interfaceTypes
-
superClassType
private Type superClassType
-
methods
private MethodInternal[] methods
-
fields
private FieldInternal[] fields
-
methodPositions
private byte[] methodPositions
-
fieldPositions
private byte[] fieldPositions
-
nestingInfo
private ClassInfo.NestingInfo nestingInfo
-
extra
private ClassInfo.ExtraInfo extra
-
-
Method Detail
-
create
@Deprecated public static ClassInfo create(DotName name, DotName superName, short flags, DotName[] interfaces, java.util.Map<DotName,java.util.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 interfaces this class implementsannotations
- the annotations on this classhasNoArgsConstructor
- whether this class has a no arg constructor- Returns:
- a new mock class representation
-
kind
public final AnnotationTarget.Kind kind()
Description copied from interface:AnnotationTarget
Returns the kind of object this target represents.- Specified by:
kind
in interfaceAnnotationTarget
- Returns:
- the target kind.
-
toString
public java.lang.String toString()
Returns the binary name of this class.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the binary name of this class
-
name
public final DotName name()
Returns the binary name of the class as aDotName
.- Returns:
- the binary name of the class as a
DotName
-
flags
public final short flags()
Returns the access flags for this class. TheModifier
methods 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
-
isInterface
public final boolean isInterface()
- Returns:
true
if this class object represents an interface type
-
isFinal
public final boolean isFinal()
- Returns:
true
if this class object represents afinal
class; an interface is neverfinal
- Since:
- 3.2.0
-
isAbstract
public final boolean isAbstract()
- Returns:
true
if this class object represents anabstract
class; an interface is alwaysabstract
- Since:
- 3.2.0
-
isEnum
public final boolean isEnum()
- Returns:
true
if this class object represents an enum type
-
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 object represents a record type
-
isModule
public final boolean isModule()
- Returns:
true
if this class object represents a Java module descriptor
-
superName
public final DotName 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 public final DotName[] 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
-
hasAnnotation
public final boolean hasAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this class, any of its members, or any type within the signature of the class or its members.- Specified by:
hasAnnotation
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- Since:
- 3.0
- See Also:
annotation(DotName)
-
annotation
public final AnnotationInstance annotation(DotName name)
Returns the annotation instance with given name declared on this class, any of its members, or any type within the signature of the class or its members. Thetarget()
method of the returned annotation instance may be used to determine the exact location of the annotation instance.The following is a non-exhaustive list of examples of annotations returned by this method:
@MyClassAnnotation public class Foo<@MyTypeAnnotation T> { @MyFieldAnnotation public String foo; public List<@MyTypeAnnotation String> bar; @MyMethodAnnotation public void foo() {...} public void foo(@MyParamAnnotation int param) {...} public void foo(List<@MyTypeAnnotation String> list) {...} public <@MyTypeAnnotation T> void foo(T t) {...} }
In case an annotation with given name occurs more than once, the result of this method is not deterministic. For such situations,
annotations(DotName)
is preferable.- Specified by:
annotation
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - Since:
- 3.0
- See Also:
annotations(DotName)
-
annotations
public final java.util.List<AnnotationInstance> annotations(DotName name)
Returns the annotation instances with given name declared on this class, any of its members, or any type within the signature of the class or its members. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.The following is a non-exhaustive list of examples of annotations returned by this method:
@MyClassAnnotation public class Foo<@MyTypeAnnotation T> { @MyFieldAnnotation public String foo; public List<@MyTypeAnnotation String> bar; @MyMethodAnnotation public void foo() {...} public void foo(@MyParamAnnotation int param) {...} public void foo(List<@MyTypeAnnotation String> list) {...} public <@MyTypeAnnotation T> void foo(T t) {...} }
- Specified by:
annotations
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type, must not benull
- Returns:
- immutable list of annotation instances, never
null
- Since:
- 3.0
- See Also:
annotationsWithRepeatable(DotName, IndexView)
,annotations()
-
annotationsWithRepeatable
public final java.util.List<AnnotationInstance> annotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this class, any of its members, or any type within the signature of the class or its members. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the
AnnotationInstance.target()
returns the target of the container annotation instance.- Specified by:
annotationsWithRepeatable
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable list of annotation instances, never
null
- Throws:
java.lang.IllegalArgumentException
- if the index isnull
, if the index does not contain the annotation type or ifname
does not identify an annotation type- Since:
- 3.0
- See Also:
annotations(DotName)
,annotations()
-
annotations
public final java.util.List<AnnotationInstance> annotations()
Returns the annotation instances declared on this class, any of its members, or any type within the signature of the class or its members. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.The following is a non-exhaustive list of examples of annotations returned by this method:
@MyClassAnnotation public class Foo<@MyTypeAnnotation T> { @MyFieldAnnotation public String foo; public List<@MyTypeAnnotation String> bar; @MyMethodAnnotation public void foo() {...} public void foo(@MyParamAnnotation int param) {...} public void foo(List<@MyTypeAnnotation String> list) {...} public <@MyTypeAnnotation T> void foo(T t) {...} }
- Specified by:
annotations
in interfaceAnnotationTarget
- Returns:
- immutable list of annotation instances, never
null
- Since:
- 3.0
-
hasDeclaredAnnotation
public final boolean hasDeclaredAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this class.Unlike
hasAnnotation(DotName)
, this method ignores annotations declared on the class members and types within the signature of the class and its members.- Specified by:
hasDeclaredAnnotation
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- Since:
- 3.0
- See Also:
hasAnnotation(DotName)
-
declaredAnnotation
public final AnnotationInstance declaredAnnotation(DotName name)
Returns the annotation instance with given name declared on this class.Unlike
annotation(DotName)
, this method doesn't return annotations declared on the class members and types within the signature of the class and its members.- Specified by:
declaredAnnotation
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - Since:
- 3.0
- See Also:
annotation(DotName)
-
declaredAnnotationsWithRepeatable
public final java.util.List<AnnotationInstance> declaredAnnotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this class.If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the
AnnotationInstance.target()
returns the target of the container annotation instance.Unlike
annotationsWithRepeatable(DotName, IndexView)
, this method doesn't return annotations declared on the class members and types within the signature of the class and its members.- Specified by:
declaredAnnotationsWithRepeatable
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable list of annotation instances, never
null
- Throws:
java.lang.IllegalArgumentException
- if the index isnull
, if the index does not contain the annotation type or ifname
does not identify an annotation type- Since:
- 3.0
- See Also:
annotationsWithRepeatable(DotName, IndexView)
-
declaredAnnotations
public final java.util.List<AnnotationInstance> declaredAnnotations()
Returns the annotation instances declared on this class.Unlike
annotations()
, this method doesn't return annotations the class members and types within the signature of the class and its members.- Specified by:
declaredAnnotations
in interfaceAnnotationTarget
- Returns:
- immutable list of annotation instances, never
null
- Since:
- 3.0
- See Also:
annotations()
-
annotationsMap
public final java.util.Map<DotName,java.util.List<AnnotationInstance>> annotationsMap()
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:
- immutable map of annotations specified on this class and its elements, never
null
-
annotations$$bridge
public final java.util.Map<DotName,java.util.List<AnnotationInstance>> annotations$$bridge()
-
setAnnotations
final void setAnnotations(java.util.Map<DotName,java.util.List<AnnotationInstance>> annotations)
-
classAnnotations
@Deprecated public final java.util.Collection<AnnotationInstance> classAnnotations()
Deprecated.Returns a list of all annotations directly declared on this class.- Returns:
- immutable list of annotations declared on this class
-
classAnnotation
@Deprecated public final AnnotationInstance classAnnotation(DotName name)
Deprecated.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
@Deprecated public final java.util.List<AnnotationInstance> classAnnotationsWithRepeatable(DotName name, IndexView index)
Deprecated.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:
- immutable list of annotation instances declared on this class, or an empty list if none
-
methods
public final java.util.List<MethodInfo> methods()
Returns a list of all methods declared in this class. This includes constructors and static initializer blocks which have the special 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 is nevernull
.Note that the result doesn't have any guaranteed order. If you need declaration order, use
methodsInDeclarationOrder()
.- Returns:
- immutable list of methods
-
methodsInDeclarationOrder
public final java.util.List<MethodInfo> methodsInDeclarationOrder()
Returns a list of all methods declared in this class, in the declaration order. Seemethods()
for more information.Note that for the result to actually be in declaration order, the index must be produced by at least Jandex 2.4. Previous Jandex versions do not store method positions. At most 256 methods may be present; if there's more, order is undefined. This also assumes that the bytecode order corresponds to declaration order, which is not guaranteed, but practically always holds.
- Returns:
- immutable list of methods, in declaration order
- Since:
- 3.2.2
-
unsortedMethods
@Deprecated public final java.util.List<MethodInfo> unsortedMethods()
Deprecated.
-
constructors
public final java.util.List<MethodInfo> constructors()
Returns a list of all constructors declared in this class (which have the special name<init>
). It does not include inherited constructors. These must be discovered by traversing the class hierarchy.This list may be empty, but is never
null
.- Returns:
- the list of constructors declared in this class
-
canonicalRecordConstructor
public MethodInfo canonicalRecordConstructor()
Returns the canonical constructor of this record. If this class is not a record, returnsnull
.Note that this method has the same limitations as
recordComponentsInDeclarationOrder()
. That is, at most 256 record components may be present, and an assumption is made that bytecode order of record components corresponds to the declaration order.- Returns:
- the canonical constructor of this record, or
null
if this class is not a record - Since:
- 3.2.2
-
methodArray
final MethodInternal[] methodArray()
-
methodPositionArray
final byte[] methodPositionArray()
-
method
public final MethodInfo method(java.lang.String name, Type... parameters)
Retrieves a method based on its signature, which includes a method name and a parameter type list. The parameter type list is compared based on the underlying raw types. As an example, a generic type parameterT
is considered equal tojava.lang.Object
, since the raw form of a type variable is its upper bound.Eligible methods include constructors and static initializer blocks which have the special 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 parameter types of the method- Returns:
- the located method or
null
if not found
-
method
public final MethodInfo method(java.lang.String name, java.util.List<Type> parameters)
Retrieves a method based on its signature, which includes a method name and a parameter type list. The parameter type list is compared based on the underlying raw types. As an example, a generic type parameterT
is considered equal tojava.lang.Object
, since the raw form of a type variable is its upper bound.Eligible methods include constructors and static initializer blocks which have the special 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 parameter types of the method- Returns:
- the located method or
null
if not found
-
firstMethod
public final MethodInfo firstMethod(java.lang.String name)
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
public final FieldInfo field(java.lang.String name)
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
public final java.util.List<FieldInfo> 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 is nevernull
.Note that the result doesn't have any guaranteed order. If you need declaration order, use
fieldsInDeclarationOrder()
.- Returns:
- immutable list of fields
-
fieldsInDeclarationOrder
public final java.util.List<FieldInfo> fieldsInDeclarationOrder()
Returns a list of all fields declared in this class, in the declaration order. Seefields()
for more information.Note that for the result to actually be in declaration order, the index must be produced by at least Jandex 2.4. Previous Jandex versions do not store field positions. At most 256 fields may be present; if there's more, order is undefined. This also assumes that the bytecode order corresponds to declaration order, which is not guaranteed, but practically always holds.
- Returns:
- immutable list of fields, in declaration order
- Since:
- 3.2.2
-
unsortedFields
@Deprecated public final java.util.List<FieldInfo> unsortedFields()
Deprecated.
-
fieldArray
final FieldInternal[] fieldArray()
-
fieldPositionArray
final byte[] fieldPositionArray()
-
recordComponent
public final RecordComponentInfo recordComponent(java.lang.String name)
Retrieves a record component by the given name.- Parameters:
name
- the name of the record component- Returns:
- the record component
-
recordComponents
public final java.util.List<RecordComponentInfo> recordComponents()
Returns a list of all record components declared by this class. This list may be empty, but is nevernull
.If this class is not a record, returns an empty list.
Note that the result doesn't have any guaranteed order. If you need declaration order, use
recordComponentsInDeclarationOrder()
.- Returns:
- immutable list of record components
-
recordComponentsInDeclarationOrder
public final java.util.List<RecordComponentInfo> recordComponentsInDeclarationOrder()
Returns a list of all record components declared in this class, in the declaration order. SeerecordComponents()
for more information.Note that for the result to actually be in declaration order, the index must be produced by at least Jandex 2.4. Previous Jandex versions do not store record component positions. At most 256 record components may be present; if there's more, order is undefined. This also assumes that the bytecode order corresponds to declaration order, which is not guaranteed, but practically always holds.
- Returns:
- immutable list of record components, in declaration order
- Since:
- 3.2.2
-
unsortedRecordComponents
@Deprecated public final java.util.List<RecordComponentInfo> unsortedRecordComponents()
Deprecated.
-
recordComponentArray
final RecordComponentInternal[] recordComponentArray()
-
recordComponentPositionArray
final byte[] recordComponentPositionArray()
-
enumConstants
public final java.util.List<FieldInfo> enumConstants()
Returns a list of enum constants declared by this enum class, represented asFieldInfo
. Enum constants are returned in declaration order.If this class is not an enum, returns an empty list.
Note that for the result to actually be in declaration order, the index must be produced by at least Jandex 2.4. Previous Jandex versions do not store field positions. At most 256 fields may be present in the class; if there's more, order is undefined. This also assumes that the bytecode order corresponds to declaration order, which is not guaranteed, but practically always holds.
- Returns:
- immutable list of enum constants, never
null
- Since:
- 3.0.1
-
enumConstantOrdinal
final int enumConstantOrdinal(FieldInternal enumConstant)
-
interfaceNames
public final java.util.List<DotName> 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:
- immutable list of names of interfaces implemented by this class
-
interfaceTypes
public final java.util.List<Type> interfaceTypes()
Returns the list of types in theimplements
clause of this class. These types may be generic types. This list may be empty, but is nevernull
.- Returns:
- immutable list of types declared in the
implements
clause of this class
-
interfaceTypeArray
final Type[] interfaceTypeArray()
-
copyInterfaceTypes
final Type[] copyInterfaceTypes()
-
superClassType
public final Type 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
public final java.util.List<TypeVariable> 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:
- immutable list of generic type parameters of this class
-
typeParameterArray
final Type[] typeParameterArray()
-
hasNoArgsConstructor
public final boolean hasNoArgsConstructor()
Returns whether this class declares a zero-parameter constructor. This is determined from constructor descriptors, so mandated and synthetic parameters are also taken into account. In other words, for Java classes (other JVM languages may differ), this method never returnstrue
for inner classes (that is, non-static member classes, local classes and anonymous classes). In such case, a constructor may exist amongmethods()
that has noMethodInfo.parameters()
, butMethodInfo.descriptorParameterTypes()
would reveal that some implicitly declared (aka mandated) or synthetic parameters exist.This information is available in indexes produced by Jandex 1.2.0 and later.
- Returns:
true
if this class has a zero-parameter constructor,false
if it does not- Since:
- 1.2.0
-
nestingType
public ClassInfo.NestingType nestingType()
Returns the nesting type of this class, which could either be a standard top level class, a member class (NestingType.INNER
), an anonymous class, or a local class.For historical reasons, static member classes are also returned as
INNER
. You can differentiate between a non-static member class (inner class) and a static member class by callingModifier.isStatic(int)
on the return value offlags()
.- Returns:
- the nesting type of this class
-
simpleName
public java.lang.String simpleName()
Returns the source declared name of this class if it is a top-level class, member class or a local class. Otherwise returnsnull
.- Returns:
- the simple name of a top-level, member or local class, or
null
if this is an anonymous class
-
nestingSimpleName
java.lang.String nestingSimpleName()
-
enclosingClass
public DotName enclosingClass()
Returns the enclosing class if this is a member class, ornull
if this is a top-level, local or anonymous class.- Returns:
- the enclosing class if this class is a member class
-
enclosingMethod
public ClassInfo.EnclosingMethodInfo enclosingMethod()
Returns the enclosing method of this class if it is a local or anonymous class declared within the body of a method or constructor. Returnsnull
if this class is a top level or a member class or if the local or anonymous class is declared within a class or instance initializer.- Returns:
- the enclosing method/constructor, if this class is a local or anonymous class
declared within a method or constructor, otherwise
null
-
memberClasses
public java.util.Set<DotName> memberClasses()
Returns a set of names of member classes declared in this class. Member classes are classes directly enclosed in another class. That is, local classes and anonymous classes are not member classes.Member classes of member classes are not included in the returned set.
Never returns
null
, but may return an empty set.- Returns:
- immutable set of names of this class's member classes, never
null
-
module
public ModuleInfo 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
-
permittedSubclasses
public java.util.Set<DotName> permittedSubclasses()
Returns the set of permitted subclasses of thissealed
class (or interface). Returns an empty set if this class is notsealed
.- Returns:
- immutable set of names of this class's permitted subclasses, never
null
- Since:
- 3.2.0
-
isSealed
public boolean isSealed()
- Returns:
true
if this class object represents asealed
class (or interface)- Since:
- 3.2.0
-
requiresGenericSignature
public boolean requiresGenericSignature()
Returns whether this class must have a generic signature. That is, whether the Java compiler when compiling this class had to emit theSignature
bytecode attribute.- Specified by:
requiresGenericSignature
in interfaceGenericSignature
- Returns:
- whether this class must have a generic signature
-
genericSignature
public java.lang.String genericSignature(java.util.function.Function<java.lang.String,Type> typeVariableSubstitution)
Returns a generic signature of this class, possibly without any generic-related information. That is, produces a correct generic signature even if this class is not generic and does not use any type variables.Signatures of type variables are substituted for signatures of types provided by the substitution function
typeVariableSubstitution
. If the substitution function returnsnull
for some type variable identifier, no substitution happens and the type variable signature is used unmodified.Note that the return value does not come directly from bytecode. Jandex does not store the signature strings. Instead, the return value is reconstructed from the Jandex object model.
- Specified by:
genericSignature
in interfaceGenericSignature
- Parameters:
typeVariableSubstitution
- a substitution function from type variable identifiers to types- Returns:
- a generic signature of this class with type variables substituted, never
null
-
descriptor
public java.lang.String descriptor(java.util.function.Function<java.lang.String,Type> typeVariableSubstitution)
Returns a bytecode descriptor of the type introduced by this class.Note that the return value does not come directly from bytecode. Jandex does not store the descriptor strings. Instead, the return value is reconstructed from the Jandex object model.
- Specified by:
descriptor
in interfaceDescriptor
- Parameters:
typeVariableSubstitution
- a substitution function from type variable identifiers to types- Returns:
- the bytecode descriptor of this class's type
-
asClass
public ClassInfo 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
public FieldInfo 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
public MethodInfo 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
public MethodParameterInfo 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
public TypeTarget 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
public RecordComponentInfo 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)
-
setFieldArray
void setFieldArray(FieldInternal[] fields)
-
setFieldPositionArray
void setFieldPositionArray(byte[] fieldPositions)
-
setMethodArray
void setMethodArray(MethodInternal[] methods)
-
setMethodPositionArray
void setMethodPositionArray(byte[] methodPositions)
-
setMethods
void setMethods(java.util.List<MethodInfo> methods, NameTable names)
-
setRecordComponentArray
void setRecordComponentArray(RecordComponentInternal[] recordComponents)
-
setRecordComponentPositionArray
void setRecordComponentPositionArray(byte[] recordComponentPositions)
-
setRecordComponents
void setRecordComponents(java.util.List<RecordComponentInfo> recordComponents, NameTable names)
-
sortAndGetPositions
static <T> byte[] sortAndGetPositions(T[] internals, java.util.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.- 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
void setSuperClassType(Type superClassType)
-
setInterfaceTypes
void setInterfaceTypes(Type[] interfaceTypes)
-
setTypeParameters
void setTypeParameters(Type[] typeParameters)
-
setInnerClassInfo
void setInnerClassInfo(DotName enclosingClass, java.lang.String simpleName, boolean knownInnerClass)
-
setMemberClasses
void setMemberClasses(java.util.Set<DotName> memberClasses)
-
setEnclosingMethod
void setEnclosingMethod(ClassInfo.EnclosingMethodInfo enclosingMethod)
-
setModule
void setModule(ModuleInfo module)
-
setFlags
void setFlags(short flags)
-
setPermittedSubclasses
void setPermittedSubclasses(java.util.Set<DotName> permittedSubclasses)
-
-