Class ParameterizedType
- java.lang.Object
-
- org.jboss.jandex.Type
-
- org.jboss.jandex.ParameterizedType
-
- All Implemented Interfaces:
Descriptor
public class ParameterizedType extends Type
Represents a parameterized type. Thename()
denotes the generic class, andarguments()
is a list of type arguments applied to the generic class in order to instantiate this parameterized type.For example, the parameterized type
Map<String, Integer>
would have a name ofjava.util.Map
and twoClassType
arguments:java.lang.String
andjava.lang.Integer
.Additionally, a parameterized type is used to represent an inner type whose enclosing type is either parameterized or has type annotations. In this case, the
owner()
method returns the type of the enclosing class. Such inner type may itself be parameterized.For example, assume the following declarations:
class A<T> { class B { } } class C { class D { } }
Then, the typeA<String>.B
is reprezented as a parameterized type, even thoughB
is not parameterized, because the enclosing type is parameterized. The owner of this type is the parameterized typeA<String>
.Similarly, the type
@TypeAnn C.D
is reprezented as a parameterized type, even though neitherC
norD
are parameterized, because the enclosing type has a type annotation. The owner of this type is the class type@TypeAnn C
.- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ParameterizedType.Builder
Convenient builder forParameterizedType
.
-
Field Summary
Fields Modifier and Type Field Description private Type[]
arguments
private int
hash
private Type
owner
-
Fields inherited from class org.jboss.jandex.Type
EMPTY_ARRAY
-
Fields inherited from interface org.jboss.jandex.Descriptor
NO_SUBSTITUTION
-
-
Constructor Summary
Constructors Constructor Description ParameterizedType(DotName name, Type[] arguments, Type owner)
ParameterizedType(DotName name, Type[] arguments, Type owner, AnnotationInstance[] annotations)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<Type>
arguments()
Returns the list of type arguments used to instantiate this parameterized type.(package private) Type[]
argumentsArray()
ParameterizedType
asParameterizedType()
Casts this type to aParameterizedType
and returns it if the kind isType.Kind.PARAMETERIZED_TYPE
.static ParameterizedType.Builder
builder(java.lang.Class<?> clazz)
Create a builder of a parameterized type for the given generic class.static ParameterizedType.Builder
builder(DotName name)
Create a builder of a parameterized type with the givenname
.(package private) ParameterizedType
copyType(int argumentIndex, Type argument)
(package private) ParameterizedType
copyType(AnnotationInstance[] newAnnotations)
(package private) ParameterizedType
copyType(Type owner)
(package private) ParameterizedType
copyType(Type[] arguments)
static ParameterizedType
create(java.lang.Class<?> clazz, Type... arguments)
Create an instance of a parameterized type with given genericclazz
and given typearguments
.static ParameterizedType
create(java.lang.Class<?> clazz, Type[] arguments, Type owner)
Create an instance of a parameterized type with given genericclazz
and given typearguments
.static ParameterizedType
create(java.lang.String name, Type... arguments)
Create an instance of a parameterized type with givenname
, which denotes a generic class, and given typearguments
.static ParameterizedType
create(java.lang.String name, Type[] arguments, Type owner)
Create an instance of a parameterized type with givenname
, which denotes a generic class, and given typearguments
.static ParameterizedType
create(DotName name, Type... arguments)
Create an instance of a parameterized type with givenname
, which denotes a generic class, and given typearguments
.static ParameterizedType
create(DotName name, Type[] arguments, Type owner)
Create an instance of a parameterized type with givenname
, which denotes a generic class, and given typearguments
.boolean
equals(java.lang.Object o)
Compares thisType
with another type.int
hashCode()
Computes a hash code representing this type.(package private) boolean
internEquals(java.lang.Object o)
(package private) int
internHashCode()
Type.Kind
kind()
Returns the kind of Type this is.Type
owner()
Returns the owner (enclosing) type of this parameterized type, if the owner is parameterized or has type annotations.(package private) java.lang.String
toString(boolean simple)
(package private) Type
withoutAnnotations()
Returns this type with all type annotations removed.-
Methods inherited from class org.jboss.jandex.Type
addAnnotation, annotation, annotationArray, annotations, annotationsWithRepeatable, appendAnnotations, asArrayType, asClassType, asPrimitiveType, asTypeVariable, asTypeVariableReference, asUnresolvedTypeVariable, asVoidType, asWildcardType, create, create, createWithAnnotations, descriptor, hasAnnotation, name, parse, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jboss.jandex.Descriptor
descriptor
-
-
-
-
Method Detail
-
create
public static ParameterizedType create(DotName name, Type... arguments)
Create an instance of a parameterized type with givenname
, which denotes a generic class, and given typearguments
.The resulting parameterized type has no owner.
- Parameters:
name
- the binary name of the generic classarguments
- type arguments applied to the generic class to form the parameterized type- Returns:
- the parameterized type
- Since:
- 3.1.0
-
create
public static ParameterizedType create(java.lang.String name, Type... arguments)
Create an instance of a parameterized type with givenname
, which denotes a generic class, and given typearguments
.The resulting parameterized type has no owner.
- Parameters:
name
- the binary name of the generic classarguments
- type arguments applied to the generic class to form the parameterized type- Returns:
- the parameterized type
- Since:
- 3.1.0
-
create
public static ParameterizedType create(java.lang.Class<?> clazz, Type... arguments)
Create an instance of a parameterized type with given genericclazz
and given typearguments
.The resulting parameterized type has no owner.
- Parameters:
clazz
- the generic classarguments
- type arguments applied to the generic class to form the parameterized type- Returns:
- the parameterized type
- Since:
- 3.1.0
-
create
public static ParameterizedType create(DotName name, Type[] arguments, Type owner)
Create an instance of a parameterized type with givenname
, which denotes a generic class, and given typearguments
.An
owner
may be supplied when the new instance is supposed to represent an inner type whose enclosing type is either parameterized or annotated with a type annotation.- Parameters:
name
- the binary name of the generic classarguments
- an array of type arguments applied to a generic class to form the parameterized typeowner
- the enclosing type if annotated or parameterized, otherwisenull
- Returns:
- the parameterized type
- Since:
- 2.1
-
create
public static ParameterizedType create(java.lang.String name, Type[] arguments, Type owner)
Create an instance of a parameterized type with givenname
, which denotes a generic class, and given typearguments
.An
owner
may be supplied when the new instance is supposed to represent an inner type whose enclosing type is either parameterized or annotated with a type annotation.- Parameters:
name
- the binary name of the generic classarguments
- an array of type arguments applied to a generic class to form the parameterized typeowner
- the enclosing type if annotated or parameterized, otherwisenull
- Returns:
- the parameterized type
- Since:
- 3.1.0
-
create
public static ParameterizedType create(java.lang.Class<?> clazz, Type[] arguments, Type owner)
Create an instance of a parameterized type with given genericclazz
and given typearguments
.An
owner
may be supplied when the new instance is supposed to represent an inner type whose enclosing type is either parameterized or annotated with a type annotation.- Parameters:
clazz
- the generic classarguments
- an array of type arguments applied to a generic class to form the parameterized typeowner
- the enclosing type if annotated or parameterized, otherwisenull
- Returns:
- the parameterized type
- Since:
- 3.1.0
-
builder
public static ParameterizedType.Builder builder(DotName name)
Create a builder of a parameterized type with the givenname
.- Parameters:
name
- binary name of the generic class- Returns:
- the builder
- Since:
- 3.1.0
-
builder
public static ParameterizedType.Builder builder(java.lang.Class<?> clazz)
Create a builder of a parameterized type for the given generic class.- Parameters:
clazz
- the generic class- Returns:
- the builder
- Since:
- 3.1.0
-
arguments
public java.util.List<Type> arguments()
Returns the list of type arguments used to instantiate this parameterized type.- Returns:
- the list of type arguments, or empty if none
-
argumentsArray
Type[] argumentsArray()
-
owner
public Type owner()
Returns the owner (enclosing) type of this parameterized type, if the owner is parameterized or has type annotations. In the latter case, the owner may be aClassType
. Returnsnull
otherwise.Note that parameterized inner classes whose enclosing types are not parameterized or type-annotated have no owner and hence this method returns
null
in such case.This example shows the case where a parameterized type is used to represent a non-parameterized class
X
:Y<String>.X
This example will return a parameterized type forY
whenX
'sowner()
method is called.- Returns:
- the owner type if the owner is parameterized or annotated, otherwise null
-
asParameterizedType
public ParameterizedType asParameterizedType()
Description copied from class:Type
Casts this type to aParameterizedType
and returns it if the kind isType.Kind.PARAMETERIZED_TYPE
. Throws an exception otherwise.- Overrides:
asParameterizedType
in classType
- Returns:
- a
ParameterizedType
-
copyType
ParameterizedType copyType(AnnotationInstance[] newAnnotations)
-
withoutAnnotations
Type withoutAnnotations()
Description copied from class:Type
Returns this type with all type annotations removed. The annotations are removed deeply, that is also on the constituent type in case of arrays, on type arguments in case of parameterized types, on the bound in case of wildcard types, etc.- Overrides:
withoutAnnotations
in classType
- Returns:
- this type without type annotations
-
copyType
ParameterizedType copyType(Type[] arguments)
-
copyType
ParameterizedType copyType(int argumentIndex, Type argument)
-
copyType
ParameterizedType copyType(Type owner)
-
equals
public boolean equals(java.lang.Object o)
Description copied from class:Type
Compares thisType
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.
-
hashCode
public int hashCode()
Description copied from class:Type
Computes a hash code representing this type.
-
internEquals
boolean internEquals(java.lang.Object o)
- Overrides:
internEquals
in classType
-
internHashCode
int internHashCode()
- Overrides:
internHashCode
in classType
-
-