Top Description Inners Fields Constructors Methods
org.jboss.jandex

public final Class ArrayType

extends Type
Class Inheritance

Represents a Java array type. Note that this representation of array types is different from the Java language representation.

In the Java language, array types have a component type and an element type. An element type is never an array type; it is the ultimate type obtained after all array dimensions are removed. For example, an element type of String[][] is String. A component type is the element type in case of one-dimensional arrays, and the same array type with one dimension less in case of multidimensional arrays. For example, the component type of String[][] is String[], whose component type is String. The number of dimensions can only be found by obtaining the component type repeatedly, until the element type is reached.

On the other hand, the Jandex representation is compressed. It consists of a constituent type and a number of dimensions. In case the array type does not contain type annotations, the constituent type is the element type. For example, the array type String[][] has 2 dimensions and a constituent type of String. However, to faithfully represent type annotations, array types may be nested; that is, the constituent type may be another array type. For example, the array type of String[] @Ann [] has 1 dimension and a constituent type of String @Ann []. In turn, this array type has 1 dimension and a constituent type of String.

The constituent() and dimensions() methods provide access to the Jandex native representation. The elementType() and componentType() methods, as well as deepDimensions(), provide access to the Java language representation.

The component() method is present for backwards compatibility and should not be used. It is equivalent to the constituent() method.

Author
Jason T. Greene
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ArrayType.Builder

Convenient builder for ArrayType.

Field Summary

Modifier and TypeField and Description
private final Type
private final int
private int
Inherited from org.jboss.jandex.Type:
EMPTY_ARRAY

Constructor Summary

AccessConstructor and Description
pack-priv
ArrayType(Type constituent, int dimensions)

pack-priv
ArrayType(Type constituent, int dimensions, AnnotationInstance[] annotations)

Method Summary

Modifier and TypeMethod and Description
private void
private void
appendRootComponent(StringBuilder builder, boolean simple)

public ArrayType
asArrayType()

Overrides org.jboss.jandex.Type.asArrayType.

Casts this type to an org.jboss.jandex.ArrayType and returns it if the kind is Kind#ARRAY.
public static ArrayType.Builder

Returns:

the builder
builder
(Type
the constituent type
constituent
,
int
the number of dimensions of the array
dimensions
)

Create a builder of an array type.

public Type
component()

Deprecated use constituent()
Equivalent to constituent().
public Type

Returns:

the component type
componentType
()

Returns the component type of the array.

public Type

Returns:

the constituent type
constituent
()

Returns the constituent type of the array.

pack-priv Type
copyType(AnnotationInstance[] newAnnotations)

Implements abstract org.jboss.jandex.Type.copyType.

pack-priv Type
copyType(Type component, int dimensions)

public static ArrayType

Returns:

the new array type instance
create
(Type
the constituent type
constituent
,
int
the number of dimensions of this array
dimensions
)

Create a new array type instance with the specified number of dimensions and the specified constituent type.

public int

Returns:

the "deep" number of dimensions of this array type
deepDimensions
()

The total number of dimensions this array type has, when traversed deep to the element type.

public int

Returns:

the number of dimensions of this array type
dimensions
()

The number of dimensions this array type has.

public Type

Returns:

the element type
elementType
()

Returns the element type of the array.

public boolean
equals(Object
the type to compare to
o
)

Overrides org.jboss.jandex.Type.equals.

Compares this Type with another type.
public int
hashCode()

Overrides org.jboss.jandex.Type.hashCode.

Computes a hash code representing this type.
pack-priv boolean
pack-priv int
public Type.Kind
kind()

Implements abstract org.jboss.jandex.Type.kind.

Returns the kind of Type this is.
public DotName
name()

Overrides org.jboss.jandex.Type.name.

Returns the name of this type (or its erasure in case of generic types) as a DotName, using the Class#getName() format.
pack-priv String
toString(boolean simple)

Overrides org.jboss.jandex.Type.toString.

Inherited from org.jboss.jandex.Type:
addAnnotationannotationannotationArrayannotationsannotationsWithRepeatableappendAnnotationsasClassTypeasParameterizedTypeasPrimitiveTypeasTypeVariableasTypeVariableReferenceasUnresolvedTypeVariableasVoidTypeasWildcardTypecreatecreateWithAnnotationsdescriptorhasAnnotationtoString

Field Detail

constituentback to summary
private final Type constituent
dimensionsback to summary
private final int dimensions
hashback to summary
private int hash

Constructor Detail

ArrayTypeback to summary
pack-priv ArrayType(Type constituent, int dimensions)
ArrayTypeback to summary
pack-priv ArrayType(Type constituent, int dimensions, AnnotationInstance[] annotations)

Method Detail

appendArraySyntaxback to summary
private void appendArraySyntax(StringBuilder builder)
appendRootComponentback to summary
private void appendRootComponent(StringBuilder builder, boolean simple)
asArrayTypeback to summary
public ArrayType asArrayType()

Overrides org.jboss.jandex.Type.asArrayType.

Doc from org.jboss.jandex.Type.asArrayType.

Casts this type to an org.jboss.jandex.ArrayType and returns it if the kind is Kind#ARRAY. Throws an exception otherwise.

Returns:ArrayType

an ArrayType

Annotations
@Override
builderback to summary
public static ArrayType.Builder builder(Type constituent, int dimensions)

Create a builder of an array type.

Parameters
constituent:Type

the constituent type

dimensions:int

the number of dimensions of the array

Returns:ArrayType.Builder

the builder

Since
3.1.0
See Also
constituent(), dimensions()
componentback to summary
public Type component()

Deprecated

use constituent()

Equivalent to constituent().

This method provides access to the Jandex compressed representation of array types. It is likely you want to use elementType() or componentType() instead.

Annotations
@Deprecated
componentTypeback to summary
public Type componentType()

Returns the component type of the array. For example, String[][] has a component type of String[], while String [] @Ann [] has a component type of String @Ann [].

Returns:Type

the component type

Since
3.1.0
constituentback to summary
public Type constituent()

Returns the constituent type of the array. Note that it may be another array type in case type annotations are present on the array components. For example, String[][] has 2 dimensions and a constituent type of String, while String[] @Ann [] has 1 dimension and a constituent type of String @Ann []. The String @Ann [] array type, in turn, has 1 dimension and a constituent type of String.

This method provides access to the Jandex compressed representation of array types. It is likely you want to use elementType() or componentType() instead.

Returns:Type

the constituent type

Since
3.1.0
copyTypeback to summary
pack-priv Type copyType(AnnotationInstance[] newAnnotations)

Implements abstract org.jboss.jandex.Type.copyType.

Annotations
@Override
copyTypeback to summary
pack-priv Type copyType(Type component, int dimensions)
createback to summary
public static ArrayType create(Type constituent, int dimensions)

Create a new array type instance with the specified number of dimensions and the specified constituent type.

Parameters
constituent:Type

the constituent type

dimensions:int

the number of dimensions of this array

Returns:ArrayType

the new array type instance

Since
2.1
See Also
constituent(), dimensions()
deepDimensionsback to summary
public int deepDimensions()

The total number of dimensions this array type has, when traversed deep to the element type. For example, both String[][] and String[] @Ann [] have a "deep" number of dimensions equal to 2.

This method is different to dimensions() in case this ArrayType has another ArrayType as its constituent type.

Returns:int

the "deep" number of dimensions of this array type

Since
3.1.0
dimensionsback to summary
public int dimensions()

The number of dimensions this array type has. Note that the constituent type may be an array type, so the number of dimensions does not necessarily correspond to the number of times an array dimension would have to be removed from this array type to reach its element type. For example, this method would return 2 for an array type of String[][], but it would return 1 for an array type of String[] @Ann [], because the constituent type of that array type is yet another array type, also with 1 dimension.

This method is different to deepDimensions() in case this ArrayType has another ArrayType as its constituent type.

This method provides access to the Jandex compressed representation of array types. It is likely you want to use deepDimensions() instead.

Returns:int

the number of dimensions of this array type

elementTypeback to summary
public Type elementType()

Returns the element type of the array. For example, both String[][] and String @Ann [] have an element type of String.

This method never returns an ArrayType.

Returns:Type

the element type

Since
3.1.0
equalsback to summary
public boolean equals(Object o)

Overrides org.jboss.jandex.Type.equals.

Doc from org.jboss.jandex.Type.equals.

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.

Parameters
o:Object

the type to compare to

Returns:boolean

true if equal

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides org.jboss.jandex.Type.hashCode.

Doc from org.jboss.jandex.Type.hashCode.

Computes a hash code representing this type.

Returns:int

the hash code

Annotations
@Override
internEqualsback to summary
pack-priv boolean internEquals(Object o)

Overrides org.jboss.jandex.Type.internEquals.

Annotations
@Override
internHashCodeback to summary
pack-priv int internHashCode()

Overrides org.jboss.jandex.Type.internHashCode.

Annotations
@Override
kindback to summary
public Type.Kind kind()

Implements abstract org.jboss.jandex.Type.kind.

Doc from org.jboss.jandex.Type.kind.

Returns the kind of Type this is.

Returns:Type.Kind

the kind

Annotations
@Override
nameback to summary
public DotName name()

Overrides org.jboss.jandex.Type.name.

Doc from org.jboss.jandex.Type.name.

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 Lbinary.name.of.TheClass; 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).
Returns:DotName

the name of this type (or its erasure in case of generic types)

Annotations
@Override
toStringback to summary
pack-priv String toString(boolean simple)

Overrides org.jboss.jandex.Type.toString.

Annotations
@Override
org.jboss.jandex back to summary

public final Class ArrayType.Builder

extends Type.Builder<ArrayType.Builder>
Class Inheritance

Convenient builder for ArrayType.
Since
3.1.0

Field Summary

Modifier and TypeField and Description
private final Type
private final int
Inherited from org.jboss.jandex.Type.Builder:
annotationsname

Constructor Summary

AccessConstructor and Description
pack-priv
Builder(Type constituent, int dimensions)

Method Summary

Modifier and TypeMethod and Description
public ArrayType

Returns:

the built array type
build
()

Returns the built array type.

Inherited from org.jboss.jandex.Type.Builder:
addAnnotationannotationsArrayself

Field Detail

constituentback to summary
private final Type constituent
dimensionsback to summary
private final int dimensions

Constructor Detail

Builderback to summary
pack-priv Builder(Type constituent, int dimensions)

Method Detail

buildback to summary
public ArrayType build()

Returns the built array type.

Returns:ArrayType

the built array type