public abstract class Type
extends java.lang.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 |
---|---|
private AnnotationInstance[] |
annotations |
private static AnnotationInstance[] |
EMPTY_ANNOTATIONS |
static Type[] |
EMPTY_ARRAY |
private DotName |
name |
Constructor and Description |
---|
Type(DotName name,
AnnotationInstance[] annotations) |
Modifier and Type | Method and Description |
---|---|
(package private) Type |
addAnnotation(AnnotationInstance annotation) |
AnnotationInstance |
annotation(DotName name) |
(package private) AnnotationInstance[] |
annotationArray() |
java.util.List<AnnotationInstance> |
annotations()
Returns the list of annotations declared on this type's usage.
|
(package private) void |
appendAnnotations(java.lang.StringBuilder builder) |
ArrayType |
asArrayType()
Casts this type to an
ArrayType and returns it if the kind is
Type.Kind.ARRAY
Throws an exception otherwise. |
ClassType |
asClassType()
Casts this type to a
ClassType and returns it if the kind is Type.Kind.CLASS
Throws an exception otherwise. |
ParameterizedType |
asParameterizedType()
Casts this type to a
ParameterizedType and returns it if the kind is
Type.Kind.PARAMETERIZED_TYPE
Throws an exception otherwise. |
PrimitiveType |
asPrimitiveType()
Casts this type to a
PrimitiveType and returns it if the kind is
Type.Kind.PRIMITIVE
Throws an exception otherwise. |
TypeVariable |
asTypeVariable()
Casts this type to a
ParameterizedType and returns it if the kind is
Type.Kind.TYPE_VARIABLE
Throws an exception otherwise. |
UnresolvedTypeVariable |
asUnresolvedTypeVariable()
Casts this type to an
UnresolvedTypeVariable and returns it if the kind is
Type.Kind.UNRESOLVED_TYPE_VARIABLE
Throws an exception otherwise. |
VoidType |
asVoidType()
Casts this type to a
VoidType and returns it if the kind is
Type.Kind.VOID
Throws an exception otherwise. |
WildcardType |
asWildcardType()
Casts this type to a
WildcardType and returns it if the kind is
Type.Kind.WILDCARD_TYPE
Throws an exception otherwise. |
(package private) abstract Type |
copyType(AnnotationInstance[] newAnnotations) |
static Type |
create(DotName name,
Type.Kind kind)
Creates a type instance of the specified kind.
|
boolean |
equals(java.lang.Object o)
Compares this Type with another type, and returns true if they are equivalent.
|
boolean |
hasAnnotation(DotName name) |
int |
hashCode()
Computes a hash code representing this type.
|
abstract Type.Kind |
kind()
Returns the kind of Type this is.
|
DotName |
name()
Returns the raw name of this type.
|
java.lang.String |
toString()
Returns a string representation for this type.
|
(package private) java.lang.String |
toString(boolean simple) |
public static final Type[] EMPTY_ARRAY
private static final AnnotationInstance[] EMPTY_ANNOTATIONS
private final DotName name
private final AnnotationInstance[] annotations
Type(DotName name, AnnotationInstance[] annotations)
public static Type create(DotName name, Type.Kind kind)
CLASS
,
directly use the specified name. Types of kind ARRAY
parse the name
in the Java reflection format (Java descriptor format changing / to '.',
e.g. "[[[[Ljava.lang.String;"). Types of kind PRIMITIVE parsed using the
primitive descriptor format (e.g. "I" for int).
Types of kind VOID ignore the specified name, and return a void type. All
other types will throw an exception.name
- the name to use or parsekind
- the kind of type to createjava.lang.IllegalArgumentException
- if the kind is no supportedpublic DotName name()
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.ClassType
java.lang.IllegalArgumentException
- if not a classpublic ParameterizedType asParameterizedType()
ParameterizedType
and returns it if the kind is
Type.Kind.PARAMETERIZED_TYPE
Throws an exception otherwise.ClassType
java.lang.IllegalArgumentException
- if not a parameterized typepublic TypeVariable asTypeVariable()
ParameterizedType
and returns it if the kind is
Type.Kind.TYPE_VARIABLE
Throws an exception otherwise.ClassType
java.lang.IllegalArgumentException
- if not a type variablepublic ArrayType asArrayType()
ArrayType
and returns it if the kind is
Type.Kind.ARRAY
Throws an exception otherwise.ClassType
java.lang.IllegalArgumentException
- if not an array typepublic WildcardType asWildcardType()
WildcardType
and returns it if the kind is
Type.Kind.WILDCARD_TYPE
Throws an exception otherwise.ClassType
java.lang.IllegalArgumentException
- if not a wildcard typepublic UnresolvedTypeVariable asUnresolvedTypeVariable()
UnresolvedTypeVariable
and returns it if the kind is
Type.Kind.UNRESOLVED_TYPE_VARIABLE
Throws an exception otherwise.ClassType
java.lang.IllegalArgumentException
- if not an unresolved typepublic PrimitiveType asPrimitiveType()
PrimitiveType
and returns it if the kind is
Type.Kind.PRIMITIVE
Throws an exception otherwise.ClassType
java.lang.IllegalArgumentException
- if not a primitive typepublic VoidType asVoidType()
VoidType
and returns it if the kind is
Type.Kind.VOID
Throws an exception otherwise.ClassType
java.lang.IllegalArgumentException
- if not a void typepublic java.lang.String toString()
toString
in class java.lang.Object
java.lang.String toString(boolean simple)
void appendAnnotations(java.lang.StringBuilder builder)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- the type to compare toObject.equals(Object)
public java.util.List<AnnotationInstance> annotations()
AnnotationInstance[] annotationArray()
public final AnnotationInstance annotation(DotName name)
public final boolean hasAnnotation(DotName name)
Type addAnnotation(AnnotationInstance annotation)
abstract Type copyType(AnnotationInstance[] newAnnotations)
public int hashCode()
hashCode
in class java.lang.Object