public final class ClassInfo extends Object implements AnnotationTarget
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.| Modifier and Type | Class and Description |
|---|---|
static class |
ClassInfo.EnclosingMethodInfo
Provides information on the enclosing method or constructor for a local or anonymous class,
if available.
|
static class |
ClassInfo.NestingType
Describes the form of nesting used by a class
|
AnnotationTarget.Kind| Modifier and Type | Method and 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.
|
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.
|
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.
|
Map<DotName,List<AnnotationInstance>> |
annotations$$bridge() |
Map<DotName,List<AnnotationInstance>> |
annotationsMap()
Returns a map indexed by annotation name, with a value list of annotation instances.
|
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 a
ClassInfo if it is of kind CLASS |
FieldInfo |
asField()
Casts and returns this target as a
FieldInfo if it is of kind FIELD |
MethodInfo |
asMethod()
Casts and returns this target as a
MethodInfo if it is of kind METHOD |
MethodParameterInfo |
asMethodParameter()
Casts and returns this target as a
MethodParameterInfo if it is of kind METHOD_PARAMETER |
RecordComponentInfo |
asRecordComponent()
Casts and returns this target as a
RecordComponentInfo if it is of kind RECORD_COMPONENT |
TypeTarget |
asType()
Casts and returns this target as a
TypeTarget if it is of kind TYPE |
AnnotationInstance |
classAnnotation(DotName name)
Deprecated.
|
Collection<AnnotationInstance> |
classAnnotations()
Deprecated.
|
List<AnnotationInstance> |
classAnnotationsWithRepeatable(DotName name,
IndexView index)
Deprecated.
|
List<MethodInfo> |
constructors()
Returns a list of all constructors declared in this class (which have the special name
<init>). |
static ClassInfo |
create(DotName name,
DotName superName,
short flags,
DotName[] interfaces,
Map<DotName,List<AnnotationInstance>> annotations,
boolean hasNoArgsConstructor)
Deprecated.
|
AnnotationInstance |
declaredAnnotation(DotName name)
Returns the annotation instance with given name declared on this class.
|
List<AnnotationInstance> |
declaredAnnotations()
Returns the annotation instances declared on this class.
|
List<AnnotationInstance> |
declaredAnnotationsWithRepeatable(DotName name,
IndexView index)
Returns the annotation instances with given name declared on this class.
|
DotName |
enclosingClass()
Returns the enclosing class if this is a member class, or
null 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.
|
List<FieldInfo> |
enumConstants()
Returns a list of enum constants declared by this enum class, represented as
FieldInfo. |
FieldInfo |
field(String name)
Retrieves a field by the given name.
|
List<FieldInfo> |
fields()
Returns a list of all available fields.
|
MethodInfo |
firstMethod(String name)
Retrieves the "first" occurrence of a method by the given name.
|
short |
flags()
Returns the access flags for this class.
|
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.
|
List<DotName> |
interfaceNames()
Returns a list of names for all interfaces this class implements.
|
DotName[] |
interfaces()
Deprecated.
|
List<Type> |
interfaceTypes()
Returns the list of types in the
implements clause of this class. |
boolean |
isAnnotation() |
boolean |
isEnum() |
boolean |
isInterface() |
boolean |
isModule() |
boolean |
isRecord() |
boolean |
isSynthetic() |
AnnotationTarget.Kind |
kind()
Returns the kind of object this target represents.
|
Set<DotName> |
memberClasses()
Returns a set of names of member classes declared in this class.
|
MethodInfo |
method(String name,
Type... parameters)
Retrieves a method based on its signature, which includes a method name and an parameter type list.
|
List<MethodInfo> |
methods()
Returns a list of all methods declared in this class.
|
ModuleInfo |
module()
Returns the module information from this class if it is a module descriptor, i.e.
|
DotName |
name()
Returns the name of the class
|
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. |
RecordComponentInfo |
recordComponent(String name)
Retrieves a record component by the given name.
|
List<RecordComponentInfo> |
recordComponents()
Returns a list of all record components declared by this class.
|
String |
simpleName()
Returns the source declared name of this class if it is a top-level class, member class or a local class.
|
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.
|
String |
toString() |
List<TypeVariable> |
typeParameters()
Returns the generic type parameters of this class, if any.
|
List<FieldInfo> |
unsortedFields()
Returns a list of all fields declared in this class, in the declaration order.
|
List<MethodInfo> |
unsortedMethods()
Returns a list of all methods declared in this class, in the declaration order.
|
List<RecordComponentInfo> |
unsortedRecordComponents()
Returns a list of all record components declared in this class, in the declaration order.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitannotation, annotation, annotations, annotations, annotationsWithRepeatable, annotationsWithRepeatable, declaredAnnotation, declaredAnnotation, declaredAnnotationsWithRepeatable, declaredAnnotationsWithRepeatable, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation@Deprecated public static ClassInfo create(DotName name, DotName superName, short flags, DotName[] interfaces, Map<DotName,List<AnnotationInstance>> annotations, boolean hasNoArgsConstructor)
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 constructorpublic final AnnotationTarget.Kind kind()
AnnotationTargetkind in interface AnnotationTargetpublic final DotName name()
public final short flags()
Modifier
can be used to decode the value.public final boolean isSynthetic()
true if this class is a synthetic classpublic final boolean isInterface()
true if this class object represents an interface typepublic final boolean isEnum()
true if this class object represents an enum typepublic final boolean isAnnotation()
true if this class object represents an annotation typepublic final boolean isRecord()
true if this class object represents a record typepublic final boolean isModule()
true if this class object represents a Java module descriptorpublic final DotName superName()
superClassType method. For all classes,
with the one exception of java.lang.Object, which is the one class in the
Java language without a super-type, this method will always return a non-null value.java.lang.Object@Deprecated public final DotName[] interfaces()
interfaceNames() should be used instead.public final boolean hasAnnotation(DotName name)
hasAnnotation in interface AnnotationTargetname - name of the annotation type to look for, must not be nulltrue if the annotation is present, false otherwiseannotation(DotName)public final AnnotationInstance annotation(DotName name)
target() 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.
annotation in interface AnnotationTargetname - name of the annotation type to look for, must not be nullnull if not foundannotations(DotName)public final List<AnnotationInstance> annotations(DotName name)
target() 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) {...}
}
annotations in interface AnnotationTargetname - name of the annotation type, must not be nullnullannotationsWithRepeatable(DotName, IndexView),
annotations()public final List<AnnotationInstance> annotationsWithRepeatable(DotName name, IndexView index)
target() 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.
annotationsWithRepeatable in interface AnnotationTargetname - name of the annotation type, must not be nullindex - index used to obtain the annotation type, must not be nullnullIllegalArgumentException - if the index is null, if the index does not contain the annotation type
or if name does not identify an annotation typeannotations(DotName),
annotations()public final List<AnnotationInstance> annotations()
target() 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) {...}
}
annotations in interface AnnotationTargetnullpublic final boolean hasDeclaredAnnotation(DotName name)
Unlike hasAnnotation(DotName), this method ignores annotations declared on the class members
and types within the signature of the class and its members.
hasDeclaredAnnotation in interface AnnotationTargetname - name of the annotation type to look for, must not be nulltrue if the annotation is present, false otherwisehasAnnotation(DotName)public final AnnotationInstance declaredAnnotation(DotName name)
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.
declaredAnnotation in interface AnnotationTargetname - name of the annotation type to look for, must not be nullnull if not foundannotation(DotName)public final List<AnnotationInstance> declaredAnnotationsWithRepeatable(DotName name, IndexView index)
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.
declaredAnnotationsWithRepeatable in interface AnnotationTargetname - name of the annotation type, must not be nullindex - index used to obtain the annotation type, must not be nullnullIllegalArgumentException - if the index is null, if the index does not contain the annotation type
or if name does not identify an annotation typeannotationsWithRepeatable(DotName, IndexView)public final List<AnnotationInstance> declaredAnnotations()
Unlike annotations(), this method doesn't return annotations the class members
and types within the signature of the class and its members.
declaredAnnotations in interface AnnotationTargetnullannotations()public final Map<DotName,List<AnnotationInstance>> annotationsMap()
The target of the annotation instance can be used to determine the location of the annotation usage.
nullpublic final Map<DotName,List<AnnotationInstance>> annotations$$bridge()
@Deprecated public final Collection<AnnotationInstance> classAnnotations()
declaredAnnotations()@Deprecated public final AnnotationInstance classAnnotation(DotName name)
declaredAnnotation(DotName)name - the annotation name to look for@Deprecated public final List<AnnotationInstance> classAnnotationsWithRepeatable(DotName name, IndexView index)
declaredAnnotationsWithRepeatable(DotName, IndexView)name - the name of the annotationindex - the index used to obtain the annotation classpublic final List<MethodInfo> methods()
<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 never null.
public final List<MethodInfo> unsortedMethods()
methods() 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.
public final List<MethodInfo> constructors()
<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.
public final MethodInfo method(String name, Type... parameters)
T is considered equal to java.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.
name - the name of the method to findparameters - the type parameters of the methodpublic final MethodInfo firstMethod(String name)
name - the name of the methodpublic final FieldInfo field(String name)
name - the name of the fieldpublic final List<FieldInfo> fields()
public final List<FieldInfo> unsortedFields()
fields() 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.
public final RecordComponentInfo recordComponent(String name)
name - the name of the record componentpublic final List<RecordComponentInfo> recordComponents()
public final List<RecordComponentInfo> unsortedRecordComponents()
recordComponents() 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.
public final List<FieldInfo> enumConstants()
FieldInfo.
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.
nullpublic final List<DotName> interfaceNames()
Note that this information is also available on the Type instances returned by
interfaceTypes
public final List<Type> interfaceTypes()
implements clause of this class. These types may be generic types.
This list may be empty, but is never null.implements clause of this classpublic final Type superClassType()
public final List<TypeVariable> typeParameters()
public final boolean hasNoArgsConstructor()
true for inner classes (that is, non-static
member classes, local classes and anonymous classes). In such case, a constructor may exist
among methods() that has no MethodInfo.parameters(), but
MethodInfo.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.
true if this class has a zero-parameter constructor, false if it does notpublic ClassInfo.NestingType nestingType()
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 calling
Modifier.isStatic(int) on the return value of flags().
public String simpleName()
null.null if this is an anonymous classpublic DotName enclosingClass()
null if this is a top-level,
local or anonymous class.public ClassInfo.EnclosingMethodInfo enclosingMethod()
null 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.nullpublic Set<DotName> memberClasses()
Member classes of member classes are not included in the returned set.
Never returns null, but may return an empty set.
nullpublic ModuleInfo module()
module-info.nullpublic ClassInfo asClass()
AnnotationTargetClassInfo if it is of kind CLASSasClass in interface AnnotationTargetpublic FieldInfo asField()
AnnotationTargetFieldInfo if it is of kind FIELDasField in interface AnnotationTargetpublic MethodInfo asMethod()
AnnotationTargetMethodInfo if it is of kind METHODasMethod in interface AnnotationTargetpublic MethodParameterInfo asMethodParameter()
AnnotationTargetMethodParameterInfo if it is of kind METHOD_PARAMETERasMethodParameter in interface AnnotationTargetpublic TypeTarget asType()
AnnotationTargetTypeTarget if it is of kind TYPEasType in interface AnnotationTargetpublic RecordComponentInfo asRecordComponent()
AnnotationTargetRecordComponentInfo if it is of kind RECORD_COMPONENTasRecordComponent in interface AnnotationTargetCopyright © 2018–2022. All rights reserved.