Class TypeVariableReference
- java.lang.Object
-
- org.jboss.jandex.Type
-
- org.jboss.jandex.TypeVariableReference
-
- All Implemented Interfaces:
Descriptor
public final class TypeVariableReference extends Type
Represents a reference to a type variable in the bound of a recursive type parameter. For example, if a class or method declares a type parameterT extends Comparable<T>
, then the second occurence ofT
is represented as a type variable reference and not as a type variable, because it occurs in its own definition. A type variable which is fully defined before its occurence in a recursive type parameter is still represented as a type variable. For example, the recursive type parameter in the following class includes one type variable reference:abstract class Builder<T, THIS extends Builder<T, THIS>> { abstract T build(); final THIS self() { return (THIS) this; } }
The identifier of the reference isTHIS
. The occurence of type variableT
in the recursive type parameter is not represented as a reference, because it does not occur in its own definition. It is fully defined before.The same holds for mutually recursive type parameters. If a type variable is fully defined before the type parameter in whose bound it occurs, it is represented as a type variable. It is represented as a type variable reference if it is defined after the type parameter in whose bound it occurs.
The type variable reference may be followed to obtain the original type variable.
Note that a type variable and a reference to that type variable may have different type annotations. Type annotations on the reference may be looked up from the reference, but when the reference is followed, the result is the original type variable with its own type annotations.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jboss.jandex.Type
Type.Builder<THIS extends Type.Builder<THIS>>, Type.Kind
-
-
Field Summary
Fields Modifier and Type Field Description private DotName
internalClassName
private java.lang.String
name
private TypeVariable
target
-
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 TypeVariableReference(java.lang.String name, DotName internalClassName)
TypeVariableReference(java.lang.String name, TypeVariable target, AnnotationInstance[] annotations, DotName internalClassName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TypeVariableReference
asTypeVariableReference()
Casts this type to aTypeVariableReference
and returns it if the kind isType.Kind.TYPE_VARIABLE_REFERENCE
.(package private) Type
copyType(AnnotationInstance[] newAnnotations)
boolean
equals(java.lang.Object o)
Compares thisType
with another type.TypeVariable
follow()
Returns the type variable referred to by this reference.int
hashCode()
Computes a hash code representing this type.java.lang.String
identifier()
Returns the identifier of this type variable reference as it appears in Java source code.(package private) DotName
internalClassName()
(package private) boolean
internEquals(java.lang.Object o)
(package private) int
internHashCode()
Type.Kind
kind()
Returns the kind of Type this is.DotName
name()
Returns the name of this type (or its erasure in case of generic types) as aDotName
, using theClass.getName()
format.(package private) void
setTarget(TypeVariable target)
(package private) java.lang.String
toString(boolean simple)
-
Methods inherited from class org.jboss.jandex.Type
addAnnotation, annotation, annotationArray, annotations, annotationsWithRepeatable, appendAnnotations, asArrayType, asClassType, asParameterizedType, asPrimitiveType, asTypeVariable, asUnresolvedTypeVariable, asVoidType, asWildcardType, create, create, createWithAnnotations, descriptor, hasAnnotation, parse, toString, withoutAnnotations
-
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
-
name
private final java.lang.String name
-
target
private TypeVariable target
-
internalClassName
private final DotName internalClassName
-
-
Constructor Detail
-
TypeVariableReference
TypeVariableReference(java.lang.String name, DotName internalClassName)
-
TypeVariableReference
TypeVariableReference(java.lang.String name, TypeVariable target, AnnotationInstance[] annotations, DotName internalClassName)
-
-
Method Detail
-
name
public DotName name()
Description copied from class:Type
Returns 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,[I
forint[]
or[[Ljava.lang.String;
forString[][]
); - for parameterized types, the binary name of the generic class is returned
(for example,
java.util.List
forList<String>
); - for type variables, the name of the first bound of the type variable is returned,
or
java.lang.Object
for type variables that have no bound; - for wildcard types, the name of the upper bound is returned,
or
java.lang.Object
if the wildcard type does not have an upper bound (for example,java.lang.Number
for? extends Number
).
- for primitive types and the void pseudo-type, the corresponding Java keyword
is returned (
-
identifier
public java.lang.String identifier()
Returns the identifier of this type variable reference as it appears in Java source code.For example, the following class has a recursive type parameter
E
with one reference:abstract class MyEnum<E extends MyEnum<E>> { }
The identifier of the reference isE
.- Returns:
- the identifier of this type variable reference
-
follow
public TypeVariable follow()
Returns the type variable referred to by this reference.
-
internalClassName
DotName internalClassName()
-
asTypeVariableReference
public TypeVariableReference asTypeVariableReference()
Description copied from class:Type
Casts this type to aTypeVariableReference
and returns it if the kind isType.Kind.TYPE_VARIABLE_REFERENCE
. Throws an exception otherwise.- Overrides:
asTypeVariableReference
in classType
- Returns:
- a
TypeVariableReference
-
copyType
Type copyType(AnnotationInstance[] newAnnotations)
-
setTarget
void setTarget(TypeVariable target)
-
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
-
-