java.lang.Object
io.quarkus.gizmo2.GenericType
- Direct Known Subclasses:
GenericType.OfPrimitive,GenericType.OfReference
A generic Java type, which may include type arguments as well as type annotations.
This class models types for the purpose of code generation, and is not generally suitable for usage in any kind of type-checking system.
Generic types are primitive types (including void)
and reference types. Reference types are array types
and throwable types. Throwable types are class types
(including "root" classes and inner classes)
and type variables. Note that in this model, class types represent
all of non-generic class types, parameterized types (generic class types with type arguments)
and raw types (generic class types without type arguments).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA generic type corresponding to an array type.static classA generic type of a class or interface (including specialized cases: enums, records, or annotations).static final classA generic type corresponding to an inner class.static final classA generic type corresponding to a primitive type, includingvoid.static classA generic type corresponding to a reference type.static final classA generic type corresponding to a "root" (non-inner) class.static classA generic type corresponding to a reference type that is suitable for use in a methodthrowsclause.static final classA generic type corresponding to a type variable. -
Method Summary
Modifier and TypeMethodDescriptionReturns the array type whose component type is this type.abstract ClassDescdesc()Returns the erased type descriptor for this generic type (notnull).booleanequals(GenericType gt) Returnstrueif this object is equal to the given object, orfalseif it is not.final booleanReturnstrueif this object is equal to the given object, orfalseif it is not.final booleanReturnstrueif this type has any type annotations, orfalseif it does not.final booleanhasAnnotations(RetentionPolicy retention) Returnstrueif this type has type annotations with given retention policy, orfalseif it does not.inthashCode()Returns the hash code of this generic type.booleanReturnstrueif this type has runtime-invisible type annotations, orfalseif it does not.booleanReturnstrueif this type has runtime-visible type annotations, orfalseif it does not.abstract booleanisRaw()Returnstrueif this type has no type arguments, orfalseif it has type arguments.static GenericTypeReturns the given type as an erased generic type (notnull).static GenericTypeof(Class<?> type, List<TypeArgument> typeArguments) Returns the given type as a generic type (notnull).static GenericTypeReturns the given type as an erased generic type (notnull).static GenericTypeof(ClassDesc desc, List<TypeArgument> typeArguments) Returns the given type as a generic type (notnull).static GenericType.OfArrayReturns a generic type for the given array class.static GenericType.OfArrayReturns a generic type for the given array type.static GenericType.OfClassReturns a generic type for the given class or interface type.static GenericType.OfClassofClass(Class<?> type, TypeArgument... typeArguments) Returns a generic type for the given class or interface type.static GenericType.OfClassofClass(Class<?> type, List<TypeArgument> typeArguments) Returns a generic type for the given class or interface type.static GenericType.OfClassReturns a generic type for the given class or interface type.static GenericType.OfClassofClass(ClassDesc desc, TypeArgument... typeArguments) Returns a generic type for the given class or interface type.static GenericType.OfClassofClass(ClassDesc desc, List<TypeArgument> typeArguments) Returns a generic type for the given class or interface type.static GenericType.OfInnerClassofInnerClass(GenericType.OfClass outerClass, String name) Returns a generic type representing an inner class of another class (notnull).static GenericType.OfPrimitiveofPrimitive(Class<?> type) Returns a generic type for the given primitive class.static GenericType.OfPrimitiveofPrimitive(ClassDesc type) Returns a generic type for the given primitive type.static GenericType.OfTypeVariableofTypeVariable(String name) Returns the generic type of a type variable (notnull).static GenericType.OfTypeVariableofTypeVariable(String name, Class<?> bound) Returns the generic type of a type variable (notnull).static GenericType.OfTypeVariableofTypeVariable(String name, ClassDesc bound) Returns the generic type of a type variable (notnull).booleanReturnstrueif a signature attribute would be needed for this generic type, orfalseotherwise.final StringtoString()Returns a string representation of this type.Append a string representation of this type to the given string builder.<A extends Annotation>
GenericTypewithAnnotation(Class<A> annotationType) Returns this generic type with the given additional annotation (notnull).<A extends Annotation>
GenericTypewithAnnotation(Class<A> annotationType, Consumer<AnnotationCreator<A>> builder) Returns this generic type with the given additional annotation (notnull).withAnnotations(Consumer<AnnotatableCreator> builder) Returns this generic type with annotations added by the given builder (notnull).
-
Method Details
-
of
Returns the given type as an erased generic type (notnull).- Parameters:
type- the type (must not benull)- Returns:
- the given type as an erased generic type (not
null)
-
of
Returns the given type as a generic type (notnull).- Parameters:
type- the type (must not benull)typeArguments- the type arguments, if any (must not benull)- Returns:
- the given type as a generic type (not
null) - Throws:
IllegalArgumentException- if the nonzero number of type arguments does not match the number of type parameters on the given class
-
ofClass
Returns a generic type for the given class or interface type.- Parameters:
type- the class object for the class or interface (must not benull)- Returns:
- a generic type for the given class or interface type
- Throws:
IllegalArgumentException- if the given type class object does not represent a class or interface
-
ofClass
Returns a generic type for the given class or interface type.- Parameters:
desc- the descriptor for the class or interface (must not benull)- Returns:
- a generic type for the given class or interface type
- Throws:
IllegalArgumentException- if the given type class object does not represent a class or interface
-
ofClass
Returns a generic type for the given class or interface type.- Parameters:
type- the class object for the class or interface (must not benull)typeArguments- the type arguments for the type (must not benull)- Returns:
- a generic type for the given class or interface type
- Throws:
IllegalArgumentException- if the given type class object does not represent a class or interface
-
ofClass
Returns a generic type for the given class or interface type.- Parameters:
type- the class object for the class or interface (must not benull)typeArguments- the type arguments for the type (must not benull)- Returns:
- a generic type for the given class or interface type
- Throws:
IllegalArgumentException- if the given type class object does not represent a class or interface
-
ofClass
Returns a generic type for the given class or interface type.- Parameters:
desc- the descriptor for the class or interface (must not benull)typeArguments- the type arguments for the type (must not benull)- Returns:
- a generic type for the given class or interface type
- Throws:
IllegalArgumentException- if the given type class object does not represent a class or interface
-
ofClass
Returns a generic type for the given class or interface type.- Parameters:
desc- the descriptor for the class or interface (must not benull)typeArguments- the type arguments for the type (must not benull)- Returns:
- a generic type for the given class or interface type
- Throws:
IllegalArgumentException- if the given type class object does not represent a class or interface
-
ofArray
Returns a generic type for the given array class.- Parameters:
type- the class object for the array type (must not benull)- Returns:
- a generic type for the given array class
- Throws:
IllegalArgumentException- if the given type class object does not represent an array type
-
ofArray
Returns a generic type for the given array type.- Parameters:
type- the array type (must not benull)- Returns:
- a generic type for the given array type
- Throws:
IllegalArgumentException- if the given type does not represent an array type
-
ofPrimitive
Returns a generic type for the given primitive class.- Parameters:
type- the class object for the primitive type (must not benull)- Returns:
- a generic type for the given primitive class
- Throws:
IllegalArgumentException- if the given type class object does not represent a primitive type
-
ofPrimitive
Returns a generic type for the given primitive type.- Parameters:
type- the primitive type (must not benull)- Returns:
- a generic type for the given primitive type
- Throws:
IllegalArgumentException- if the given type does not represent a primitive type
-
of
Returns the given type as an erased generic type (notnull).- Parameters:
desc- the type descriptor (must not benull)- Returns:
- the given type as an erased generic type (not
null)
-
of
Returns the given type as a generic type (notnull).- Parameters:
desc- the type descriptor (must not benull)typeArguments- the type arguments, if any (must not benull)- Returns:
- the given type as a generic type (not
null) - Throws:
IllegalArgumentException- if the nonzero number of type arguments does not match the number of type parameters on the given class
-
ofTypeVariable
Returns the generic type of a type variable (notnull).- Parameters:
name- the type variable name (must not benull)bound- the type variable's erased bound (must not benull)- Returns:
- the generic type of a type variable (not
null)
-
ofTypeVariable
Returns the generic type of a type variable (notnull).- Parameters:
name- the type variable name (must not benull)bound- the type variable's erased bound (must not benull)- Returns:
- the generic type of a type variable (not
null)
-
ofTypeVariable
Returns the generic type of a type variable (notnull). The bound of the type variable is assumed to bejava.lang.Object.- Parameters:
name- the type variable name (must not benull)- Returns:
- the generic type of a type variable (not
null)
-
ofInnerClass
Returns a generic type representing an inner class of another class (notnull). Note thatstaticmember classes are not inner classes and are represented byGenericType.OfRootClass.- Parameters:
outerClass- the enclosing class generic type (must not benull)name- the inner class name (must not benull)- Returns:
- a generic type representing an inner class of another class (not
null)
-
withAnnotations
Returns this generic type with annotations added by the given builder (notnull).- Parameters:
builder- the annotation builder (must not benull)- Returns:
- this generic type with annotations added by the given builder (not
null)
-
withAnnotation
Returns this generic type with the given additional annotation (notnull).- Parameters:
annotationType- the annotation type (must not benull)- Returns:
- this generic type with the given additional annotation (not
null)
-
withAnnotation
public <A extends Annotation> GenericType withAnnotation(Class<A> annotationType, Consumer<AnnotationCreator<A>> builder) Returns this generic type with the given additional annotation (notnull).- Parameters:
annotationType- the annotation type (must not benull)builder- the builder for the given annotation type (must not benull)- Returns:
- this generic type with the given additional annotation (not
null)
-
isRaw
public abstract boolean isRaw()Returnstrueif this type has no type arguments, orfalseif it has type arguments.- Returns:
trueif this type has no type arguments, orfalseif it has type arguments
-
signatureNeeded
public boolean signatureNeeded()Returnstrueif a signature attribute would be needed for this generic type, orfalseotherwise.- Returns:
trueif a signature attribute would be needed for this generic type, orfalseotherwise
-
hasAnnotations
Returnstrueif this type has type annotations with given retention policy, orfalseif it does not.- Parameters:
retention- the retention policy (must not benull)- Returns:
trueif this type has type annotations with given retention policy, orfalseif it does not
-
hasVisibleAnnotations
public boolean hasVisibleAnnotations()Returnstrueif this type has runtime-visible type annotations, orfalseif it does not.- Returns:
trueif this type has runtime-visible type annotations, orfalseif it does not
-
hasInvisibleAnnotations
public boolean hasInvisibleAnnotations()Returnstrueif this type has runtime-invisible type annotations, orfalseif it does not.- Returns:
trueif this type has runtime-invisible type annotations, orfalseif it does not
-
hasAnnotations
public final boolean hasAnnotations()Returnstrueif this type has any type annotations, orfalseif it does not.- Returns:
trueif this type has any type annotations, orfalseif it does not
-
arrayType
Returns the array type whose component type is this type.- Returns:
- the array type whose component type is this type
-
desc
Returns the erased type descriptor for this generic type (notnull).- Returns:
- the erased type descriptor for this generic type (not
null)
-
toString
Append a string representation of this type to the given string builder.- Parameters:
b- the string builder (must not benull)- Returns:
- the string builder that was passed in (not
null)
-
toString
Returns a string representation of this type. -
equals
Returnstrueif this object is equal to the given object, orfalseif it is not. -
equals
Returnstrueif this object is equal to the given object, orfalseif it is not.- Returns:
trueif this object is equal to the given object, orfalseif it is not
-
hashCode
public int hashCode()Returns the hash code of this generic type.
-