public final class ClassInfo extends java.lang.Object implements 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.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.
|
private static class |
ClassInfo.NestingInfo |
static class |
ClassInfo.NestingType
Describes the form of nesting used by a class
|
AnnotationTarget.Kind
Modifier and Type | Field and Description |
---|---|
private java.util.Map<DotName,java.util.List<AnnotationInstance>> |
annotations |
private FieldInternal[] |
fields |
private short |
flags |
private boolean |
hasNoArgsConstructor |
private Type[] |
interfaceTypes |
private MethodInternal[] |
methods |
private DotName |
name |
private ClassInfo.NestingInfo |
nestingInfo |
private Type |
superClassType |
private Type[] |
typeParameters |
Constructor and Description |
---|
ClassInfo(DotName name,
Type superClassType,
short flags,
Type[] interfaceTypes,
java.util.Map<DotName,java.util.List<AnnotationInstance>> annotations) |
ClassInfo(DotName name,
Type superClassType,
short flags,
Type[] interfaceTypes,
java.util.Map<DotName,java.util.List<AnnotationInstance>> annotations,
boolean hasNoArgsConstructor) |
Modifier and Type | Method and Description |
---|---|
java.util.Map<DotName,java.util.List<AnnotationInstance>> |
annotations()
Returns a map indexed by annotation name, with a value list of annotation instances.
|
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 |
TypeTarget |
asType()
Casts and returns this target as a
TypeTarget if it is of kind TYPE |
AnnotationInstance |
classAnnotation(DotName name)
Returns the annotation with the specified name directly declared on this class.
|
java.util.Collection<AnnotationInstance> |
classAnnotations()
Returns a list of all annotations directly declared on this class.
|
(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.
|
DotName |
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.
|
ClassInfo.EnclosingMethodInfo |
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.
|
FieldInfo |
field(java.lang.String name)
Retrieves a field by the given name.
|
(package private) FieldInternal[] |
fieldArray() |
java.util.List<FieldInfo> |
fields()
Returns a list of all available fields.
|
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.
|
boolean |
hasNoArgsConstructor()
Returns a boolean indicating the presence of a no-arg constructor, if supported by the underlying index store.
|
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 the implements clause of this class.
|
AnnotationTarget.Kind |
kind()
Returns the kind of object this target represents.
|
MethodInfo |
method(java.lang.String name,
Type... parameters)
Retrieves a method based on its signature, which includes a method name and an argument list.
|
(package private) MethodInternal[] |
methodArray() |
java.util.List<MethodInfo> |
methods()
Returns a list of all methods declared in this class.
|
DotName |
name()
Returns the name of the class
|
(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, an inner class,
an anonymous class, or a local class.
|
(package private) void |
setEnclosingMethod(ClassInfo.EnclosingMethodInfo enclosingMethod) |
(package private) void |
setFieldArray(FieldInternal[] fields) |
(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 |
setMethodArray(MethodInternal[] methods) |
(package private) void |
setMethods(java.util.List<MethodInfo> methods,
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 an inner 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.
|
java.lang.String |
toString() |
(package private) Type[] |
typeParameterArray() |
java.util.List<TypeVariable> |
typeParameters()
Returns the generic type parameters of this class, if any.
|
private final DotName name
private final java.util.Map<DotName,java.util.List<AnnotationInstance>> annotations
private short flags
private Type[] interfaceTypes
private Type superClassType
private Type[] typeParameters
private MethodInternal[] methods
private FieldInternal[] fields
private boolean hasNoArgsConstructor
private ClassInfo.NestingInfo nestingInfo
ClassInfo(DotName name, Type superClassType, short flags, Type[] interfaceTypes, java.util.Map<DotName,java.util.List<AnnotationInstance>> annotations)
ClassInfo(DotName name, Type superClassType, short flags, Type[] interfaceTypes, java.util.Map<DotName,java.util.List<AnnotationInstance>> annotations, boolean hasNoArgsConstructor)
@Deprecated public static ClassInfo create(DotName name, DotName superName, short flags, DotName[] interfaces, java.util.Map<DotName,java.util.List<AnnotationInstance>> annotations, boolean hasNoArgsConstructor)
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 constructorpublic final AnnotationTarget.Kind kind()
AnnotationTarget
kind
in interface AnnotationTarget
public java.lang.String toString()
toString
in class java.lang.Object
public final DotName name()
public final short flags()
Modifier
can be used to decode the value.public 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 java.util.Map<DotName,java.util.List<AnnotationInstance>> annotations()
The target of the annotation instance can be used to determine the location of the annotation usage.
public final java.util.Collection<AnnotationInstance> classAnnotations()
public final AnnotationInstance classAnnotation(DotName name)
name
- the annotation name to look forpublic final java.util.List<MethodInfo> methods()
This list may be empty, but never null.
final MethodInternal[] methodArray()
public final MethodInfo method(java.lang.String name, Type... parameters)
java.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.
name
- the name of the method to findparameters
- the type parameters of the methodpublic final MethodInfo firstMethod(java.lang.String name)
name
- the name of the methodpublic final FieldInfo field(java.lang.String name)
name
- the name of the fieldpublic final java.util.List<FieldInfo> fields()
final FieldInternal[] fieldArray()
public final java.util.List<DotName> interfaceNames()
Note that this information is also available on the Type
instances returned by
interfaceTypes
public final java.util.List<Type> interfaceTypes()
final Type[] interfaceTypeArray()
final Type[] copyInterfaceTypes()
public final Type superClassType()
public final java.util.List<TypeVariable> typeParameters()
final Type[] typeParameterArray()
public final boolean hasNoArgsConstructor()
true
in case of the Java class has a no-copyParameters constructor, false
if it does not, or it is not knownpublic ClassInfo.NestingType nestingType()
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 calling
Modifier.isStatic(int)
on the return of flags()
public java.lang.String simpleName()
java.lang.String nestingSimpleName()
public DotName enclosingClass()
public ClassInfo.EnclosingMethodInfo enclosingMethod()
public ClassInfo asClass()
AnnotationTarget
ClassInfo
if it is of kind CLASS
asClass
in interface AnnotationTarget
public FieldInfo asField()
AnnotationTarget
FieldInfo
if it is of kind FIELD
asField
in interface AnnotationTarget
public MethodInfo asMethod()
AnnotationTarget
MethodInfo
if it is of kind METHOD
asMethod
in interface AnnotationTarget
public MethodParameterInfo asMethodParameter()
AnnotationTarget
MethodParameterInfo
if it is of kind METHOD_PARAMETER
asMethodParameter
in interface AnnotationTarget
public TypeTarget asType()
AnnotationTarget
TypeTarget
if it is of kind TYPE
asType
in interface AnnotationTarget
void setHasNoArgsConstructor(boolean hasNoArgsConstructor)
void setFieldArray(FieldInternal[] fields)
void setMethodArray(MethodInternal[] methods)
void setMethods(java.util.List<MethodInfo> methods, NameTable names)
void setSuperClassType(Type superClassType)
void setInterfaceTypes(Type[] interfaceTypes)
void setTypeParameters(Type[] typeParameters)
void setInnerClassInfo(DotName enclosingClass, java.lang.String simpleName, boolean knownInnerClass)
void setEnclosingMethod(ClassInfo.EnclosingMethodInfo enclosingMethod)
void setFlags(short flags)