public abstract class Type extends Object
A type usage may have annotations associated with its declaration. A type is equal to another type if, and only if, it represents the same exact definition including the annotations specific to its usage.
To reduce memory overhead, type instances are often shared between their enclosing classes.
| Modifier and Type | Class and Description |
|---|---|
static class |
Type.Kind
Represents a "kind" of Type.
|
| Modifier and Type | Field and Description |
|---|---|
static Type[] |
EMPTY_ARRAY |
| Modifier and Type | Method and Description |
|---|---|
AnnotationInstance |
annotation(DotName name)
Returns the annotation instance with given name declared on this type usage.
|
List<AnnotationInstance> |
annotations()
Returns the annotation instances declared on this type usage.
|
List<AnnotationInstance> |
annotationsWithRepeatable(DotName name,
IndexView index)
Returns the annotation instances with given name declared on this type usage.
|
static boolean |
arrayEquals(org.jboss.jandex.Interned[] a,
org.jboss.jandex.Interned[] b) |
static int |
arrayHashCode(org.jboss.jandex.Interned[] array) |
ArrayType |
asArrayType()
Casts this type to an
ArrayType and returns it if the kind is
Type.Kind.ARRAY. |
ClassType |
asClassType()
Casts this type to a
ClassType and returns it if the kind is Type.Kind.CLASS. |
ParameterizedType |
asParameterizedType()
Casts this type to a
ParameterizedType and returns it if the kind is
Type.Kind.PARAMETERIZED_TYPE. |
PrimitiveType |
asPrimitiveType()
Casts this type to a
PrimitiveType and returns it if the kind is
Type.Kind.PRIMITIVE. |
TypeVariable |
asTypeVariable()
Casts this type to a
TypeVariable and returns it if the kind is
Type.Kind.TYPE_VARIABLE. |
TypeVariableReference |
asTypeVariableReference()
Casts this type to a
TypeVariableReference and returns it if the kind is
Type.Kind.TYPE_VARIABLE_REFERENCE. |
UnresolvedTypeVariable |
asUnresolvedTypeVariable()
Casts this type to an
UnresolvedTypeVariable and returns it if the kind is
Type.Kind.UNRESOLVED_TYPE_VARIABLE. |
VoidType |
asVoidType()
Casts this type to a
VoidType and returns it if the kind is
Type.Kind.VOID. |
WildcardType |
asWildcardType()
Casts this type to a
WildcardType and returns it if the kind is
Type.Kind.WILDCARD_TYPE. |
static Type |
create(DotName name,
Type.Kind kind)
Creates a type instance of the specified kind.
|
static Type |
createWithAnnotations(DotName name,
Type.Kind kind,
AnnotationInstance[] annotations)
Creates an instance of specified type with given type
annotations. |
boolean |
equals(Object o)
Compares this
Type with another type. |
boolean |
hasAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this type usage.
|
int |
hashCode()
Computes a hash code representing this type.
|
boolean |
internEquals(Object o) |
int |
internHashCode() |
abstract Type.Kind |
kind()
Returns the kind of Type this is.
|
DotName |
name()
Returns the raw name of this type.
|
String |
toString()
Returns a string representation for this type.
|
public static final Type[] EMPTY_ARRAY
public static Type create(DotName name, Type.Kind kind)
kind is CLASS,
the name is used as is. If kind is ARRAY, the name
must be in the Java reflection format (Java descriptor format changing /
to ., e.g. [[[[Ljava.lang.String;" or [[[I). If kind
is PRIMITIVE, the name must be in the Java reflection format (which is equal
to the Java keyword denoting the primitive type, e.g. int). If kind is
VOID, the name is ignored. All other kinds cause an exception.name - the name of type to use or parsekind - the kind of type to createIllegalArgumentException - if the kind is no supportedpublic static Type createWithAnnotations(DotName name, Type.Kind kind, AnnotationInstance[] annotations)
annotations.
To create the type instance, this method delegates to create(DotName, Kind).name - the name of type to use or parsekind - the kind of type to createannotations - the type annotations that should be present on the type instanceIllegalArgumentException - if the kind is no supportedpublic DotName name()
[[[Ljava.lang.String;) Classes are returned as a normal DotName.
Generic values are returned as the underlying raw value. For example,
a wildcard such as ? extends Number has a raw type of
Number.
public abstract Type.Kind kind()
public ClassType asClassType()
ClassType and returns it if the kind is Type.Kind.CLASS.
Throws an exception otherwise.ClassTypeIllegalArgumentException - if not a classpublic ParameterizedType asParameterizedType()
ParameterizedType and returns it if the kind is
Type.Kind.PARAMETERIZED_TYPE. Throws an exception otherwise.ParameterizedTypeIllegalArgumentException - if not a parameterized typepublic TypeVariable asTypeVariable()
TypeVariable and returns it if the kind is
Type.Kind.TYPE_VARIABLE. Throws an exception otherwise.TypeVariableIllegalArgumentException - if not a type variablepublic TypeVariableReference asTypeVariableReference()
TypeVariableReference and returns it if the kind is
Type.Kind.TYPE_VARIABLE_REFERENCE. Throws an exception otherwise.TypeVariableReferenceIllegalArgumentException - if not a type variablepublic ArrayType asArrayType()
ArrayType and returns it if the kind is
Type.Kind.ARRAY. Throws an exception otherwise.ArrayTypeIllegalArgumentException - if not an array typepublic WildcardType asWildcardType()
WildcardType and returns it if the kind is
Type.Kind.WILDCARD_TYPE. Throws an exception otherwise.WildcardTypeIllegalArgumentException - if not a wildcard typepublic UnresolvedTypeVariable asUnresolvedTypeVariable()
UnresolvedTypeVariable and returns it if the kind is
Type.Kind.UNRESOLVED_TYPE_VARIABLE. Throws an exception otherwise.UnresolvedTypeVariableIllegalArgumentException - if not an unresolved typepublic PrimitiveType asPrimitiveType()
PrimitiveType and returns it if the kind is
Type.Kind.PRIMITIVE. Throws an exception otherwise.PrimitiveTypeIllegalArgumentException - if not a primitive typepublic VoidType asVoidType()
VoidType and returns it if the kind is
Type.Kind.VOID. Throws an exception otherwise.VoidTypeIllegalArgumentException - if not a void typepublic final boolean hasAnnotation(DotName name)
name - 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)
To allow for Type object reuse, the annotation instances returned by this method
have a null annotation target.
name - name of the annotation type to look for, must not be nullnull if not foundpublic final List<AnnotationInstance> annotationsWithRepeatable(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.
To allow for Type object reuse, the annotation instances returned by this method
have a null annotation target.
name - 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()public List<AnnotationInstance> annotations()
To allow for Type object reuse, the annotation instances returned by this method
have a null annotation target.
nullpublic String toString()
public boolean equals(Object o)
Type with another type. A type is equal to another type
if it is of the same kind, and all of their fields are equal. This includes
annotations, which must be equal as well.equals in class Objecto - the type to compare toObject.equals(Object)public int hashCode()
public boolean internEquals(Object o)
public int internHashCode()
public static boolean arrayEquals(org.jboss.jandex.Interned[] a,
org.jboss.jandex.Interned[] b)
public static int arrayHashCode(org.jboss.jandex.Interned[] array)
Copyright © 2018–2022. All rights reserved.