Class ParameterizedType

java.lang.Object
org.jboss.jandex.Type
org.jboss.jandex.ParameterizedType
All Implemented Interfaces:
Descriptor

public class ParameterizedType extends Type
Represents a parameterized type. The name() denotes the generic class, and arguments() is a list of type arguments applied to the generic class in order to instantiate this parameterized type.

For example, the parameterized type Map<String, Integer> would have a name of java.util.Map and two ClassType arguments: java.lang.String and java.lang.Integer.

Additionally, a parameterized type is used to represent an inner type whose enclosing type is either parameterized or has type annotations. In this case, the owner() method returns the type of the enclosing class. Such inner type may itself be parameterized.

For example, assume the following declarations:

 class A<T> {
     class B {
     }
 }

 class C {
     class D {
     }
 }
 
Then, the type A<String>.B is reprezented as a parameterized type, even though B is not parameterized, because the enclosing type is parameterized. The owner of this type is the parameterized type A<String>.

Similarly, the type @TypeAnn C.D is reprezented as a parameterized type, even though neither C nor D are parameterized, because the enclosing type has a type annotation. The owner of this type is the class type @TypeAnn C.

Since:
2.0
  • Field Details

    • arguments

      private final Type[] arguments
    • owner

      private final Type owner
    • hash

      private int hash
  • Constructor Details

  • Method Details

    • create

      public static ParameterizedType create(DotName name, Type... arguments)
      Create an instance of a parameterized type with given name, which denotes a generic class, and given type arguments.

      The resulting parameterized type has no owner.

      Parameters:
      name - the binary name of the generic class
      arguments - type arguments applied to the generic class to form the parameterized type
      Returns:
      the parameterized type
      Since:
      3.1.0
    • create

      public static ParameterizedType create(String name, Type... arguments)
      Create an instance of a parameterized type with given name, which denotes a generic class, and given type arguments.

      The resulting parameterized type has no owner.

      Parameters:
      name - the binary name of the generic class
      arguments - type arguments applied to the generic class to form the parameterized type
      Returns:
      the parameterized type
      Since:
      3.1.0
    • create

      public static ParameterizedType create(Class<?> clazz, Type... arguments)
      Create an instance of a parameterized type with given generic clazz and given type arguments.

      The resulting parameterized type has no owner.

      Parameters:
      clazz - the generic class
      arguments - type arguments applied to the generic class to form the parameterized type
      Returns:
      the parameterized type
      Since:
      3.1.0
    • create

      public static ParameterizedType create(DotName name, Type[] arguments, Type owner)
      Create an instance of a parameterized type with given name, which denotes a generic class, and given type arguments.

      An owner may be supplied when the new instance is supposed to represent an inner type whose enclosing type is either parameterized or annotated with a type annotation.

      Parameters:
      name - the binary name of the generic class
      arguments - an array of type arguments applied to a generic class to form the parameterized type
      owner - the enclosing type if annotated or parameterized, otherwise null
      Returns:
      the parameterized type
      Since:
      2.1
    • create

      public static ParameterizedType create(String name, Type[] arguments, Type owner)
      Create an instance of a parameterized type with given name, which denotes a generic class, and given type arguments.

      An owner may be supplied when the new instance is supposed to represent an inner type whose enclosing type is either parameterized or annotated with a type annotation.

      Parameters:
      name - the binary name of the generic class
      arguments - an array of type arguments applied to a generic class to form the parameterized type
      owner - the enclosing type if annotated or parameterized, otherwise null
      Returns:
      the parameterized type
      Since:
      3.1.0
    • create

      public static ParameterizedType create(Class<?> clazz, Type[] arguments, Type owner)
      Create an instance of a parameterized type with given generic clazz and given type arguments.

      An owner may be supplied when the new instance is supposed to represent an inner type whose enclosing type is either parameterized or annotated with a type annotation.

      Parameters:
      clazz - the generic class
      arguments - an array of type arguments applied to a generic class to form the parameterized type
      owner - the enclosing type if annotated or parameterized, otherwise null
      Returns:
      the parameterized type
      Since:
      3.1.0
    • builder

      public static ParameterizedType.Builder builder(DotName name)
      Create a builder of a parameterized type with the given name.
      Parameters:
      name - binary name of the generic class
      Returns:
      the builder
      Since:
      3.1.0
    • builder

      public static ParameterizedType.Builder builder(Class<?> clazz)
      Create a builder of a parameterized type for the given generic class.
      Parameters:
      clazz - the generic class
      Returns:
      the builder
      Since:
      3.1.0
    • arguments

      public List<Type> arguments()
      Returns the list of type arguments used to instantiate this parameterized type.
      Returns:
      the list of type arguments, or empty if none
    • argumentsArray

      Type[] argumentsArray()
    • owner

      public Type owner()
      Returns the owner (enclosing) type of this parameterized type, if the owner is parameterized or has type annotations. In the latter case, the owner may be a ClassType. Returns null otherwise.

      Note that parameterized inner classes whose enclosing types are not parameterized or type-annotated have no owner and hence this method returns null in such case.

      This example 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
    • kind

      public Type.Kind kind()
      Description copied from class: Type
      Returns the kind of Type this is.
      Specified by:
      kind in class Type
      Returns:
      the kind
    • asParameterizedType

      public ParameterizedType asParameterizedType()
      Description copied from class: Type
      Casts this type to a ParameterizedType and returns it if the kind is Type.Kind.PARAMETERIZED_TYPE. Throws an exception otherwise.
      Overrides:
      asParameterizedType in class Type
      Returns:
      a ParameterizedType
    • copyType

      ParameterizedType copyType(AnnotationInstance[] newAnnotations)
      Specified by:
      copyType in class Type
    • withoutAnnotations

      Type withoutAnnotations()
      Description copied from class: Type
      Returns 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:
      withoutAnnotations in class Type
      Returns:
      this type without type annotations
    • copyType

      ParameterizedType copyType(Type[] arguments)
    • copyType

      ParameterizedType copyType(int argumentIndex, Type argument)
    • copyType

      ParameterizedType copyType(Type owner)
    • toString

      String toString(boolean simple)
      Overrides:
      toString in class Type
    • equals

      public boolean equals(Object o)
      Description copied from class: Type
      Compares this Type 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.
      Overrides:
      equals in class Type
      Parameters:
      o - the type to compare to
      Returns:
      true if equal
      See Also:
    • hashCode

      public int hashCode()
      Description copied from class: Type
      Computes a hash code representing this type.
      Overrides:
      hashCode in class Type
      Returns:
      the hash code
    • internEquals

      boolean internEquals(Object o)
      Overrides:
      internEquals in class Type
    • internHashCode

      int internHashCode()
      Overrides:
      internHashCode in class Type