Class ArrayType

java.lang.Object
org.jboss.jandex.Type
org.jboss.jandex.ArrayType

public final class ArrayType extends Type
Represents a Java array type declaration.
Author:
Jason T. Greene
Since:
2.0
  • Method Details

    • create

      public static ArrayType create(Type component, int dimensions)
      Create a new mock array type instance with the specified component and dimensions.
      Parameters:
      component - the array component
      dimensions - the number of dimensions of this array
      Returns:
      the new mock array type instance
      Since:
      2.1
    • component

      public Type component()
      Returns the component type of the array. For example, String[] has a component type of String.

      It is possible for an ArrayType to have another ArrayType as its component type. This happens when an array has some of its dimensions annotated (e.g. String[] @Ann []). In such case, having multiple nested ArrayTypes is necessary to faithfully represent the annotations.

      Returns:
      the component type
    • name

      public DotName name()
      Description copied from class: Type
      Returns the name of this type (or its erasure in case of generic types) as a DotName, using the Class.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 or L<binary class name>; for class types (for example, [I for int[] or [[Ljava.lang.String; for String[][]);
      • for parameterized types, the binary name of the generic class is returned (for example, java.util.List for List<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).
      Overrides:
      name in class Type
      Returns:
      the name of this type (or its erasure in case of generic types)
    • dimensions

      public int dimensions()
      The number of dimensions this array type has. For example, this method would return 2 for an array type of String[][].

      Note that an ArrayType may have another ArrayType as its component type (see component()). For example, String[] @Ann [] is an array type with 1 dimension and a component type of another array type, also with 1 dimension.

      Returns:
      the number of dimensions of this array type
    • 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
    • asArrayType

      public ArrayType asArrayType()
      Description copied from class: Type
      Casts this type to an ArrayType and returns it if the kind is Type.Kind.ARRAY. Throws an exception otherwise.
      Overrides:
      asArrayType in class Type
      Returns:
      an ArrayType
    • 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

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

      public int internHashCode()
      Overrides:
      internHashCode in class Type