Class Type
- Direct Known Subclasses:
ArrayType,ClassType,ParameterizedType,PrimitiveType,TypeVariable,TypeVariableReference,UnresolvedTypeVariable,VoidType,WildcardType
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.
- Author:
- Jason T. Greene
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionfinal AnnotationInstanceannotation(DotName name) Returns the annotation instance with given name declared on this type usage.Returns the annotation instances declared on this type usage.final List<AnnotationInstance>annotationsWithRepeatable(DotName name, IndexView index) Returns the annotation instances with given name declared on this type usage.Casts this type to anArrayTypeand returns it if the kind isType.Kind.ARRAY.Casts this type to aClassTypeand returns it if the kind isType.Kind.CLASS.Casts this type to aParameterizedTypeand returns it if the kind isType.Kind.PARAMETERIZED_TYPE.Casts this type to aPrimitiveTypeand returns it if the kind isType.Kind.PRIMITIVE.Casts this type to aTypeVariableand returns it if the kind isType.Kind.TYPE_VARIABLE.Casts this type to aTypeVariableReferenceand returns it if the kind isType.Kind.TYPE_VARIABLE_REFERENCE.Casts this type to anUnresolvedTypeVariableand returns it if the kind isType.Kind.UNRESOLVED_TYPE_VARIABLE.Casts this type to aVoidTypeand returns it if the kind isType.Kind.VOID.Casts this type to aWildcardTypeand returns it if the kind isType.Kind.WILDCARD_TYPE.static TypeCreates a type instance of the specified kind.static TypecreateWithAnnotations(DotName name, Type.Kind kind, AnnotationInstance[] annotations) Creates an instance of specified type with given typeannotations.booleanCompares thisTypewith another type.final booleanhasAnnotation(DotName name) Returns whether an annotation instance with given name is declared on this type usage.inthashCode()Computes a hash code representing this type.booleanintabstract Type.Kindkind()Returns the kind of Type this is.name()Returns the raw name of this type.toString()Returns a string representation for this type.
-
Field Details
-
EMPTY_ARRAY
-
-
Method Details
-
create
Creates a type instance of the specified kind. IfkindisCLASS, thenameis used as is. IfkindisARRAY, thenamemust be in the Java reflection format (Java descriptor format changing/to., e.g.[[[[Ljava.lang.String;"or[[[I). IfkindisPRIMITIVE, 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 isVOID, thenameis ignored. All other kinds cause an exception.- Parameters:
name- the name of type to use or parsekind- the kind of type to create- Returns:
- the type
- Throws:
IllegalArgumentException- if the kind is no supported
-
createWithAnnotations
public static Type createWithAnnotations(DotName name, Type.Kind kind, AnnotationInstance[] annotations) Creates an instance of specified type with given typeannotations. To create the type instance, this method delegates tocreate(DotName, Kind).- Parameters:
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 instance- Returns:
- the annotated type
- Throws:
IllegalArgumentException- if the kind is no supported
-
name
Returns the raw name of this type. Primitives and void are returned as the Java keyword (void, boolean, byte, short, int, long, float, double, char). Arrays are returned using the Java reflection array syntax (e.g.[[[Ljava.lang.String;) Classes are returned as a normalDotName.Generic values are returned as the underlying raw value. For example, a wildcard such as
? extends Numberhas a raw type ofNumber.- Returns:
- the name of this type
-
kind
Returns the kind of Type this is.- Returns:
- the kind
-
asClassType
Casts this type to aClassTypeand returns it if the kind isType.Kind.CLASS. Throws an exception otherwise.- Returns:
- a
ClassType - Throws:
IllegalArgumentException- if not a class- Since:
- 2.0
-
asParameterizedType
Casts this type to aParameterizedTypeand returns it if the kind isType.Kind.PARAMETERIZED_TYPE. Throws an exception otherwise.- Returns:
- a
ParameterizedType - Throws:
IllegalArgumentException- if not a parameterized type- Since:
- 2.0
-
asTypeVariable
Casts this type to aTypeVariableand returns it if the kind isType.Kind.TYPE_VARIABLE. Throws an exception otherwise.- Returns:
- a
TypeVariable - Throws:
IllegalArgumentException- if not a type variable- Since:
- 2.0
-
asTypeVariableReference
Casts this type to aTypeVariableReferenceand returns it if the kind isType.Kind.TYPE_VARIABLE_REFERENCE. Throws an exception otherwise.- Returns:
- a
TypeVariableReference - Throws:
IllegalArgumentException- if not a type variable- Since:
- 2.0
-
asArrayType
Casts this type to anArrayTypeand returns it if the kind isType.Kind.ARRAY. Throws an exception otherwise.- Returns:
- an
ArrayType - Throws:
IllegalArgumentException- if not an array type- Since:
- 2.0
-
asWildcardType
Casts this type to aWildcardTypeand returns it if the kind isType.Kind.WILDCARD_TYPE. Throws an exception otherwise.- Returns:
- a
WildcardType - Throws:
IllegalArgumentException- if not a wildcard type- Since:
- 2.0
-
asUnresolvedTypeVariable
Casts this type to anUnresolvedTypeVariableand returns it if the kind isType.Kind.UNRESOLVED_TYPE_VARIABLE. Throws an exception otherwise.- Returns:
- an
UnresolvedTypeVariable - Throws:
IllegalArgumentException- if not an unresolved type- Since:
- 2.0
-
asPrimitiveType
Casts this type to aPrimitiveTypeand returns it if the kind isType.Kind.PRIMITIVE. Throws an exception otherwise.- Returns:
- a
PrimitiveType - Throws:
IllegalArgumentException- if not a primitive type- Since:
- 2.0
-
asVoidType
Casts this type to aVoidTypeand returns it if the kind isType.Kind.VOID. Throws an exception otherwise.- Returns:
- a
VoidType - Throws:
IllegalArgumentException- if not a void type- Since:
- 2.0
-
hasAnnotation
Returns whether an annotation instance with given name is declared on this type usage.- Parameters:
name- name of the annotation type to look for, must not benull- Returns:
trueif the annotation is present,falseotherwise- See Also:
-
annotation
Returns the annotation instance with given name declared on this type usage.To allow for
Typeobject reuse, the annotation instances returned by this method have anullannotation target.- Parameters:
name- name of the annotation type to look for, must not benull- Returns:
- the annotation instance, or
nullif not found
-
annotationsWithRepeatable
Returns the annotation instances with given name declared on this type usage.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
Typeobject reuse, the annotation instances returned by this method have anullannotation target.- Parameters:
name- name of the annotation type, must not benullindex- index used to obtain the annotation type, must not benull- Returns:
- immutable list of annotation instances, never
null - Throws:
IllegalArgumentException- if the index isnull, if the index does not contain the annotation type or ifnamedoes not identify an annotation type- Since:
- 3.0
- See Also:
-
annotations
Returns the annotation instances declared on this type usage.To allow for
Typeobject reuse, the annotation instances returned by this method have anullannotation target.- Returns:
- immutable list of annotation instances, never
null - Since:
- 2.0
-
toString
Returns a string representation for this type. It is similar, yet not identical to a Java source code representation. -
equals
Compares thisTypewith 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. -
hashCode
public int hashCode()Computes a hash code representing this type. -
internEquals
-
internHashCode
public int internHashCode()
-