Package org.jboss.jandex
Class Type
- java.lang.Object
-
- org.jboss.jandex.Type
-
- Direct Known Subclasses:
ArrayType,ClassType,ParameterizedType,PrimitiveType,TypeVariable,UnresolvedTypeVariable,VoidType,WildcardType
public abstract class Type extends java.lang.ObjectRepresents a Java type declaration usage that is specified on methods, fields, classes, annotations, or other types. A type can be any class based type (interface, class, annotation), any primitive, any array, any generic type declaration, or void.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classType.KindRepresents a "kind" of Type.
-
Field Summary
Fields Modifier and Type Field Description private AnnotationInstance[]annotationsprivate static AnnotationInstance[]EMPTY_ANNOTATIONSstatic Type[]EMPTY_ARRAYprivate DotNamename
-
Constructor Summary
Constructors Constructor Description Type(DotName name, AnnotationInstance[] annotations)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) TypeaddAnnotation(AnnotationInstance annotation)AnnotationInstanceannotation(DotName name)(package private) AnnotationInstance[]annotationArray()java.util.List<AnnotationInstance>annotations()Returns the list of annotations declared on this type's usage.(package private) voidappendAnnotations(java.lang.StringBuilder builder)ArrayTypeasArrayType()Casts this type to anArrayTypeand returns it if the kind isType.Kind.ARRAYThrows an exception otherwise.ClassTypeasClassType()Casts this type to aClassTypeand returns it if the kind isType.Kind.CLASSThrows an exception otherwise.ParameterizedTypeasParameterizedType()Casts this type to aParameterizedTypeand returns it if the kind isType.Kind.PARAMETERIZED_TYPEThrows an exception otherwise.PrimitiveTypeasPrimitiveType()Casts this type to aPrimitiveTypeand returns it if the kind isType.Kind.PRIMITIVEThrows an exception otherwise.TypeVariableasTypeVariable()Casts this type to aParameterizedTypeand returns it if the kind isType.Kind.TYPE_VARIABLEThrows an exception otherwise.UnresolvedTypeVariableasUnresolvedTypeVariable()Casts this type to anUnresolvedTypeVariableand returns it if the kind isType.Kind.UNRESOLVED_TYPE_VARIABLEThrows an exception otherwise.VoidTypeasVoidType()Casts this type to aVoidTypeand returns it if the kind isType.Kind.VOIDThrows an exception otherwise.WildcardTypeasWildcardType()Casts this type to aWildcardTypeand returns it if the kind isType.Kind.WILDCARD_TYPEThrows an exception otherwise.(package private) abstract TypecopyType(AnnotationInstance[] newAnnotations)static Typecreate(DotName name, Type.Kind kind)Creates a type instance of the specified kind.booleanequals(java.lang.Object o)Compares this Type with another type, and returns true if they are equivalent.booleanhasAnnotation(DotName name)inthashCode()Computes a hash code representing this type.abstract Type.Kindkind()Returns the kind of Type this is.DotNamename()Returns the raw name of this type.java.lang.StringtoString()Returns a string representation for this type.(package private) java.lang.StringtoString(boolean simple)
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final Type[] EMPTY_ARRAY
-
EMPTY_ANNOTATIONS
private static final AnnotationInstance[] EMPTY_ANNOTATIONS
-
name
private final DotName name
-
annotations
private final AnnotationInstance[] annotations
-
-
Constructor Detail
-
Type
Type(DotName name, AnnotationInstance[] annotations)
-
-
Method Detail
-
create
public static Type create(DotName name, Type.Kind kind)
Creates a type instance of the specified kind. Types of kindCLASS, directly use the specified name. Types of kindARRAYparse 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.- Parameters:
name- the name to use or parsekind- the kind of type to create- Returns:
- the type
- Throws:
java.lang.IllegalArgumentException- if the kind is no supported
-
name
public DotName name()
Returns the raw name of this type. Primitives and void are returned as the Java reserved word (void, boolean, byte, short, char, int, long, float, double). 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 Number, has a raw type ofNumber- Returns:
- the name of this type
-
kind
public abstract Type.Kind kind()
Returns the kind of Type this is.- Returns:
- the kind
-
asClassType
public ClassType asClassType()
Casts this type to aClassTypeand returns it if the kind isType.Kind.CLASSThrows an exception otherwise.- Returns:
- a
ClassType - Throws:
java.lang.IllegalArgumentException- if not a class- Since:
- 2.0
-
asParameterizedType
public ParameterizedType asParameterizedType()
Casts this type to aParameterizedTypeand returns it if the kind isType.Kind.PARAMETERIZED_TYPEThrows an exception otherwise.- Returns:
- a
ClassType - Throws:
java.lang.IllegalArgumentException- if not a parameterized type- Since:
- 2.0
-
asTypeVariable
public TypeVariable asTypeVariable()
Casts this type to aParameterizedTypeand returns it if the kind isType.Kind.TYPE_VARIABLEThrows an exception otherwise.- Returns:
- a
ClassType - Throws:
java.lang.IllegalArgumentException- if not a type variable- Since:
- 2.0
-
asArrayType
public ArrayType asArrayType()
Casts this type to anArrayTypeand returns it if the kind isType.Kind.ARRAYThrows an exception otherwise.- Returns:
- a
ClassType - Throws:
java.lang.IllegalArgumentException- if not an array type- Since:
- 2.0
-
asWildcardType
public WildcardType asWildcardType()
Casts this type to aWildcardTypeand returns it if the kind isType.Kind.WILDCARD_TYPEThrows an exception otherwise.- Returns:
- a
ClassType - Throws:
java.lang.IllegalArgumentException- if not a wildcard type- Since:
- 2.0
-
asUnresolvedTypeVariable
public UnresolvedTypeVariable asUnresolvedTypeVariable()
Casts this type to anUnresolvedTypeVariableand returns it if the kind isType.Kind.UNRESOLVED_TYPE_VARIABLEThrows an exception otherwise.- Returns:
- a
ClassType - Throws:
java.lang.IllegalArgumentException- if not an unresolved type- Since:
- 2.0
-
asPrimitiveType
public PrimitiveType asPrimitiveType()
Casts this type to aPrimitiveTypeand returns it if the kind isType.Kind.PRIMITIVEThrows an exception otherwise.- Returns:
- a
ClassType - Throws:
java.lang.IllegalArgumentException- if not a primitive type- Since:
- 2.0
-
asVoidType
public VoidType asVoidType()
Casts this type to aVoidTypeand returns it if the kind isType.Kind.VOIDThrows an exception otherwise.- Returns:
- a
ClassType - Throws:
java.lang.IllegalArgumentException- if not a void type- Since:
- 2.0
-
toString
public java.lang.String toString()
Returns a string representation for this type. It is similar, yet not equivalent to a Java source code representation.- Overrides:
toStringin classjava.lang.Object- Returns:
- the string representation.
-
toString
java.lang.String toString(boolean simple)
-
appendAnnotations
void appendAnnotations(java.lang.StringBuilder builder)
-
equals
public boolean equals(java.lang.Object o)
Compares this Type with another type, and returns true if they are equivalent. A type is equivalent to another type if it is the same kind, and all of its fields are equal. This includes annotations, which must be equal as well.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the type to compare to- Returns:
- true if equal
- See Also:
Object.equals(Object)
-
annotations
public java.util.List<AnnotationInstance> annotations()
Returns the list of annotations declared on this type's usage. In order to allow for type reuse, the annotation instances returned by this method will have a null annotation target value. However, this information is not useful, because if it is accessed from this method, the target is this type.- Returns:
- a list of annotation instances declared on the usage this type represents
- Since:
- 2.0
-
annotationArray
AnnotationInstance[] annotationArray()
-
annotation
public final AnnotationInstance annotation(DotName name)
-
hasAnnotation
public final boolean hasAnnotation(DotName name)
-
addAnnotation
Type addAnnotation(AnnotationInstance annotation)
-
copyType
abstract Type copyType(AnnotationInstance[] newAnnotations)
-
hashCode
public int hashCode()
Computes a hash code representing this type.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code
-
-