Package org.jboss.jandex
Class TypeVariable
- java.lang.Object
-
- org.jboss.jandex.Type
-
- org.jboss.jandex.TypeVariable
-
- All Implemented Interfaces:
Descriptor
public final class TypeVariable extends Type
Represents a resolved type parameter or type argument. Thename()of this type variable corresponds to the raw type name. For type variables, the raw type name is the first declared bound. Theidentifier()is the name of the type variable as present in the source code.For example:
T extends Number
In this case, the identifier isT, while the name isjava.lang.Number.Type variables may have bounds. There are three possibilities:
- no bounds
- one bound, which is a type variable
- multiple bounds, where the first may be a class type, and the rest must be interface types
hasImplicitObjectBound()method may be used to discover whether the first class bound was declared or not.- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTypeVariable.BuilderConvenient builder forTypeVariable.
-
Field Summary
Fields Modifier and Type Field Description private Type[]boundsprivate inthashprivate static intHASH_MASKprivate java.lang.Stringidentifierprivate static intIMPLICIT_MASK-
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 TypeVariable(java.lang.String name)TypeVariable(java.lang.String name, Type[] bounds)TypeVariable(java.lang.String name, Type[] bounds, AnnotationInstance[] annotations)TypeVariable(java.lang.String name, Type[] bounds, AnnotationInstance[] annotations, boolean implicitObjectBound)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TypeVariableasTypeVariable()Casts this type to aTypeVariableand returns it if the kind isType.Kind.TYPE_VARIABLE.(package private) Type[]boundArray()java.util.List<Type>bounds()static TypeVariable.Builderbuilder(java.lang.String identifier)Create a builder of a type variable.(package private) TypeVariablecopyType(int boundIndex, Type bound)(package private) TypecopyType(AnnotationInstance[] newAnnotations)static TypeVariablecreate(java.lang.String identifier)Create an instance of a type variable with the givenidentifier.booleanequals(java.lang.Object o)Compares thisTypewith another type.inthashCode()Computes a hash code representing this type.booleanhasImplicitObjectBound()Returns whether this type variable has an implicit (undeclared) bound of typeObject.java.lang.Stringidentifier()The identifier of this type variable as it appears in Java source code.(package private) booleaninternEquals(java.lang.Object o)(package private) intinternHashCode()Type.Kindkind()Returns the kind of Type this is.DotNamename()Returns the name of this type (or its erasure in case of generic types) as aDotName, using theClass.getName()format.(package private) java.lang.StringtoString(boolean simple)(package private) TypewithoutAnnotations()Returns this type with all type annotations removed.-
Methods inherited from class org.jboss.jandex.Type
addAnnotation, annotation, annotationArray, annotations, annotationsWithRepeatable, appendAnnotations, asArrayType, asClassType, asParameterizedType, asPrimitiveType, asTypeVariableReference, asUnresolvedTypeVariable, asVoidType, asWildcardType, create, create, createWithAnnotations, descriptor, hasAnnotation, 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
-
-
-
-
Field Detail
-
HASH_MASK
private static final int HASH_MASK
- See Also:
- Constant Field Values
-
IMPLICIT_MASK
private static final int IMPLICIT_MASK
- See Also:
- Constant Field Values
-
identifier
private final java.lang.String identifier
-
bounds
private final Type[] bounds
-
hash
private int hash
-
-
Constructor Detail
-
TypeVariable
TypeVariable(java.lang.String name)
-
TypeVariable
TypeVariable(java.lang.String name, Type[] bounds)
-
TypeVariable
TypeVariable(java.lang.String name, Type[] bounds, AnnotationInstance[] annotations)
-
TypeVariable
TypeVariable(java.lang.String name, Type[] bounds, AnnotationInstance[] annotations, boolean implicitObjectBound)
-
-
Method Detail
-
create
public static TypeVariable create(java.lang.String identifier)
Create an instance of a type variable with the givenidentifier. The type variable has a single bound ofjava.lang.Object.- Parameters:
identifier- identifier of the type variable- Returns:
- the type variable
- Since:
- 3.1.0
- See Also:
identifier()
-
builder
public static TypeVariable.Builder builder(java.lang.String identifier)
Create a builder of a type variable.- Returns:
- the builder
- Since:
- 3.1.0
-
name
public DotName name()
Description copied from class:TypeReturns the name of this type (or its erasure in case of generic types) as aDotName, using theClass.getName()format. Specifically:- for primitive types and the void pseudo-type, the corresponding Java keyword
is returned (
void,boolean,byte,short,int,long,float,double,char); - for class types, the binary name of the class is returned;
- for array types, a string is returned that consists of one or more
[characters corresponding to the number of dimensions of the array type, followed by the element type as a single-character code for primitive types orLbinary.name.of.TheClass;for class types (for example,[Iforint[]or[[Ljava.lang.String;forString[][]); - for parameterized types, the binary name of the generic class is returned
(for example,
java.util.ListforList<String>); - for type variables, the name of the first bound of the type variable is returned,
or
java.lang.Objectfor type variables that have no bound; - for wildcard types, the name of the upper bound is returned,
or
java.lang.Objectif the wildcard type does not have an upper bound (for example,java.lang.Numberfor? extends Number).
- for primitive types and the void pseudo-type, the corresponding Java keyword
is returned (
-
identifier
public java.lang.String identifier()
The identifier of this type variable as it appears in Java source code.The following class has a type parameter with an identifier of
T:class Foo<T extends Number> { }- Returns:
- the identifier of this type variable
-
bounds
public java.util.List<Type> bounds()
-
boundArray
Type[] boundArray()
-
hasImplicitObjectBound
public boolean hasImplicitObjectBound()
Returns whether this type variable has an implicit (undeclared) bound of typeObject. If so, allbounds()are interface types.- Returns:
- whether this type variable has an implicit (undeclared) bound of type
Object
-
asTypeVariable
public TypeVariable asTypeVariable()
Description copied from class:TypeCasts this type to aTypeVariableand returns it if the kind isType.Kind.TYPE_VARIABLE. Throws an exception otherwise.- Overrides:
asTypeVariablein classType- Returns:
- a
TypeVariable
-
copyType
Type copyType(AnnotationInstance[] newAnnotations)
-
withoutAnnotations
Type withoutAnnotations()
Description copied from class:TypeReturns 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:
withoutAnnotationsin classType- Returns:
- this type without type annotations
-
copyType
TypeVariable copyType(int boundIndex, Type bound)
-
equals
public boolean equals(java.lang.Object o)
Description copied from class:TypeCompares 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()
Description copied from class:TypeComputes a hash code representing this type.
-
internEquals
boolean internEquals(java.lang.Object o)
- Overrides:
internEqualsin classType
-
internHashCode
int internHashCode()
- Overrides:
internHashCodein classType
-
-