Class ParameterizedType
- java.lang.Object
-
- org.jboss.jandex.Type
-
- org.jboss.jandex.ParameterizedType
-
public class ParameterizedType extends Type
Represents a generic parameterized type. Thename()
corresponds to the raw type, and the arguments list corresponds to a list of type arguments passed to the parameterized type.Additionally, a parameterized type is used to represent an inner class whose enclosing class is either parameterized or has type annotations. In this case, the
owner()
method will specify the type for the enclosing class. It is also possible for such a type to be parameterized itself.For example, the follow declaration would have a name of "java.util.Map", and two
ClassType
arguments, the first being "java.lang.String", the second "java.lang.Integer":java.util.Map<String, Integer>
Another example shows the case where a parameterized type is used to represent a non-parameterized class (X), whose owner (Y) is itself parameterized:
Y<String>.X
- Since:
- 2.0
- Author:
- Jason T. Greene
-
-
Field Summary
-
Fields inherited from class org.jboss.jandex.Type
EMPTY_ARRAY
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<Type>
arguments()
Returns the list of arguments passed to this Parameterized type.ParameterizedType
asParameterizedType()
Casts this type to aParameterizedType
and returns it if the kind isType.Kind.PARAMETERIZED_TYPE
Throws an exception otherwise.static ParameterizedType
create(DotName name, Type[] arguments, Type owner)
Create a new mock instance.boolean
equals(Object o)
Compares this Type with another type, and returns true if they are equivalent.int
hashCode()
Computes a hash code representing this type.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 contains type annotations.String
toString()
Returns a string representation for this type.-
Methods inherited from class org.jboss.jandex.Type
annotation, annotations, asArrayType, asClassType, asPrimitiveType, asTypeVariable, asUnresolvedTypeVariable, asVoidType, asWildcardType, create, hasAnnotation, name
-
-
-
-
Method Detail
-
create
public static ParameterizedType create(DotName name, Type[] arguments, Type owner)
Create a new mock instance.- Parameters:
name
- the name of this typearguments
- an array of types representing arguments to this typeowner
- the enclosing type if annotated or parameterized, otherwise null- Returns:
- the mock instance
- Since:
- 2.1
-
arguments
public List<Type> arguments()
Returns the list of arguments passed to this Parameterized type.- Returns:
- the list of type arguments, or empty if none
-
owner
public Type owner()
Returns the owner (enclosing) type of this parameterized type if the owner is parameterized, or contains type annotations. The latter may be aClassType
. Otherwise null is returned.Note that this means that inner classes whose enclosing types are not parameterized or annotated may return null when this method is called.
The example below 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 for "Y" when X's
owner()
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
ClassType
-
toString
public String toString()
Description copied from class:Type
Returns a string representation for this type. It is similar, yet not equivalent to a Java source code representation.
-
equals
public boolean equals(Object o)
Description copied from class:Type
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:
equals
in classType
- Parameters:
o
- the type to compare to- Returns:
- true if equal
- See Also:
Object.equals(Object)
-
-