public final class ClassInfo extends 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.
|
static class |
ClassInfo.NestingType
Describes the form of nesting used by a class
|
AnnotationTarget.Kind
Modifier and Type | Method and Description |
---|---|
Map<DotName,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 |
Collection<AnnotationInstance> |
classAnnotations()
Returns a list of all annotations directly declared on this class.
|
static ClassInfo |
create(DotName name,
DotName superName,
short flags,
DotName[] interfaces,
Map<DotName,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(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 |
hasNoArgsConstructor()
Returns a boolean indicating the presence of a no-arg constructor, if supported by the underlying index store.
|
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.
|
AnnotationTarget.Kind |
kind()
Returns the kind of object this target represents.
|
MethodInfo |
method(String name,
Type... parameters)
Retrieves a method based on its signature, which includes a method name and an argument list.
|
List<MethodInfo> |
methods()
Returns a list of all methods declared in this class.
|
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, an inner class,
an anonymous class, or a local class.
|
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.
|
String |
toString() |
List<TypeVariable> |
typeParameters()
Returns the generic type parameters of this class, if any.
|
@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 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 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 Map<DotName,List<AnnotationInstance>> annotations()
The target of the annotation instance can be used to determine the location of the annotation usage.
public final Collection<AnnotationInstance> classAnnotations()
public final List<MethodInfo> methods()
This list may be empty, but never null.
public final MethodInfo method(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(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<DotName> interfaceNames()
Note that this information is also available on the Type
instances returned by
interfaceTypes
public final List<Type> interfaceTypes()
public final Type superClassType()
public final List<TypeVariable> typeParameters()
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()
public String simpleName()
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
Copyright © 2018 JBoss by Red Hat. All rights reserved.