Class GenericType

java.lang.Object
io.quarkus.gizmo2.GenericType
Direct Known Subclasses:
GenericType.OfPrimitive, GenericType.OfReference

public abstract class GenericType extends Object
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).

  • Method Details

    • of

      public static GenericType of(Class<?> type)
      Returns the given type as an erased generic type (not null).
      Parameters:
      type - the type (must not be null)
      Returns:
      the given type as an erased generic type (not null)
    • of

      public static GenericType of(Class<?> type, List<TypeArgument> typeArguments)
      Returns the given type as a generic type (not null).
      Parameters:
      type - the type (must not be null)
      typeArguments - the type arguments, if any (must not be null)
      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

      public static GenericType.OfClass ofClass(Class<?> type)
      Returns a generic type for the given class or interface type.
      Parameters:
      type - the class object for the class or interface (must not be null)
      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

      public static GenericType.OfClass ofClass(ClassDesc desc)
      Returns a generic type for the given class or interface type.
      Parameters:
      desc - the descriptor for the class or interface (must not be null)
      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

      public static GenericType.OfClass ofClass(Class<?> type, List<TypeArgument> typeArguments)
      Returns a generic type for the given class or interface type.
      Parameters:
      type - the class object for the class or interface (must not be null)
      typeArguments - the type arguments for the type (must not be null)
      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

      public static GenericType.OfClass ofClass(Class<?> type, TypeArgument... typeArguments)
      Returns a generic type for the given class or interface type.
      Parameters:
      type - the class object for the class or interface (must not be null)
      typeArguments - the type arguments for the type (must not be null)
      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

      public static GenericType.OfClass ofClass(ClassDesc desc, List<TypeArgument> typeArguments)
      Returns a generic type for the given class or interface type.
      Parameters:
      desc - the descriptor for the class or interface (must not be null)
      typeArguments - the type arguments for the type (must not be null)
      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

      public static GenericType.OfClass ofClass(ClassDesc desc, TypeArgument... typeArguments)
      Returns a generic type for the given class or interface type.
      Parameters:
      desc - the descriptor for the class or interface (must not be null)
      typeArguments - the type arguments for the type (must not be null)
      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

      public static GenericType.OfArray ofArray(Class<?> type)
      Returns a generic type for the given array class.
      Parameters:
      type - the class object for the array type (must not be null)
      Returns:
      a generic type for the given array class
      Throws:
      IllegalArgumentException - if the given type class object does not represent an array type
    • ofArray

      public static GenericType.OfArray ofArray(ClassDesc type)
      Returns a generic type for the given array type.
      Parameters:
      type - the array type (must not be null)
      Returns:
      a generic type for the given array type
      Throws:
      IllegalArgumentException - if the given type does not represent an array type
    • ofPrimitive

      public static GenericType.OfPrimitive ofPrimitive(Class<?> type)
      Returns a generic type for the given primitive class.
      Parameters:
      type - the class object for the primitive type (must not be null)
      Returns:
      a generic type for the given primitive class
      Throws:
      IllegalArgumentException - if the given type class object does not represent a primitive type
    • ofPrimitive

      public static GenericType.OfPrimitive ofPrimitive(ClassDesc type)
      Returns a generic type for the given primitive type.
      Parameters:
      type - the primitive type (must not be null)
      Returns:
      a generic type for the given primitive type
      Throws:
      IllegalArgumentException - if the given type does not represent a primitive type
    • of

      public static GenericType of(ClassDesc desc)
      Returns the given type as an erased generic type (not null).
      Parameters:
      desc - the type descriptor (must not be null)
      Returns:
      the given type as an erased generic type (not null)
    • of

      public static GenericType of(ClassDesc desc, List<TypeArgument> typeArguments)
      Returns the given type as a generic type (not null).
      Parameters:
      desc - the type descriptor (must not be null)
      typeArguments - the type arguments, if any (must not be null)
      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

      public static GenericType.OfTypeVariable ofTypeVariable(String name, Class<?> bound)
      Returns the generic type of a type variable (not null).
      Parameters:
      name - the type variable name (must not be null)
      bound - the type variable's erased bound (must not be null)
      Returns:
      the generic type of a type variable (not null)
    • ofTypeVariable

      public static GenericType.OfTypeVariable ofTypeVariable(String name, ClassDesc bound)
      Returns the generic type of a type variable (not null).
      Parameters:
      name - the type variable name (must not be null)
      bound - the type variable's erased bound (must not be null)
      Returns:
      the generic type of a type variable (not null)
    • ofTypeVariable

      public static GenericType.OfTypeVariable ofTypeVariable(String name)
      Returns the generic type of a type variable (not null). The bound of the type variable is assumed to be java.lang.Object.
      Parameters:
      name - the type variable name (must not be null)
      Returns:
      the generic type of a type variable (not null)
    • ofInnerClass

      public static GenericType.OfInnerClass ofInnerClass(GenericType.OfClass outerClass, String name)
      Returns a generic type representing an inner class of another class (not null). Note that static member classes are not inner classes and are represented by GenericType.OfRootClass.
      Parameters:
      outerClass - the enclosing class generic type (must not be null)
      name - the inner class name (must not be null)
      Returns:
      a generic type representing an inner class of another class (not null)
    • withAnnotations

      public GenericType withAnnotations(Consumer<AnnotatableCreator> builder)
      Returns this generic type with annotations added by the given builder (not null).
      Parameters:
      builder - the annotation builder (must not be null)
      Returns:
      this generic type with annotations added by the given builder (not null)
    • withAnnotation

      public <A extends Annotation> GenericType withAnnotation(Class<A> annotationType)
      Returns this generic type with the given additional annotation (not null).
      Parameters:
      annotationType - the annotation type (must not be null)
      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 (not null).
      Parameters:
      annotationType - the annotation type (must not be null)
      builder - the builder for the given annotation type (must not be null)
      Returns:
      this generic type with the given additional annotation (not null)
    • isRaw

      public abstract boolean isRaw()
      Returns true if this type has no type arguments, or false if it has type arguments.
      Returns:
      true if this type has no type arguments, or false if it has type arguments
    • signatureNeeded

      public boolean signatureNeeded()
      Returns true if a signature attribute would be needed for this generic type, or false otherwise.
      Returns:
      true if a signature attribute would be needed for this generic type, or false otherwise
    • hasAnnotations

      public final boolean hasAnnotations(RetentionPolicy retention)
      Returns true if this type has type annotations with given retention policy, or false if it does not.
      Parameters:
      retention - the retention policy (must not be null)
      Returns:
      true if this type has type annotations with given retention policy, or false if it does not
    • hasVisibleAnnotations

      public boolean hasVisibleAnnotations()
      Returns true if this type has runtime-visible type annotations, or false if it does not.
      Returns:
      true if this type has runtime-visible type annotations, or false if it does not
    • hasInvisibleAnnotations

      public boolean hasInvisibleAnnotations()
      Returns true if this type has runtime-invisible type annotations, or false if it does not.
      Returns:
      true if this type has runtime-invisible type annotations, or false if it does not
    • hasAnnotations

      public final boolean hasAnnotations()
      Returns true if this type has any type annotations, or false if it does not.
      Returns:
      true if this type has any type annotations, or false if it does not
    • arrayType

      public GenericType.OfArray arrayType()
      Returns the array type whose component type is this type.
      Returns:
      the array type whose component type is this type
    • desc

      public abstract ClassDesc desc()
      Returns the erased type descriptor for this generic type (not null).
      Returns:
      the erased type descriptor for this generic type (not null)
    • toString

      public StringBuilder toString(StringBuilder b)
      Append a string representation of this type to the given string builder.
      Parameters:
      b - the string builder (must not be null)
      Returns:
      the string builder that was passed in (not null)
    • toString

      public final String toString()
      Returns a string representation of this type.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this type
    • equals

      public final boolean equals(Object obj)
      Returns true if this object is equal to the given object, or false if it is not.
      Overrides:
      equals in class Object
      Returns:
      true if this object is equal to the given object, or false if it is not
    • equals

      public boolean equals(GenericType gt)
      Returns true if this object is equal to the given object, or false if it is not.
      Returns:
      true if this object is equal to the given object, or false if it is not
    • hashCode

      public int hashCode()
      Returns the hash code of this generic type.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of this generic type