Class ArrayType
- All Implemented Interfaces:
Descriptor
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.
- Since:
- 2.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from class org.jboss.jandex.Type
EMPTY_ARRAY
Fields inherited from interface org.jboss.jandex.Descriptor
NO_SUBSTITUTION
-
Constructor Summary
ConstructorsConstructorDescriptionArrayType
(Type constituent, int dimensions, AnnotationInstance[] annotations) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
appendArraySyntax
(StringBuilder builder) private void
appendRootComponent
(StringBuilder builder, boolean simple) Casts this type to anArrayType
and returns it if the kind isType.Kind.ARRAY
.static ArrayType.Builder
Create a builder of an array type.Deprecated.Returns the component type of the array.Returns the constituent type of the array.(package private) Type
copyType
(AnnotationInstance[] newAnnotations) (package private) Type
static ArrayType
Create a new array type instance with the specified number of dimensions and the specified constituent type.int
The total number of dimensions this array type has, when traversed deep to the element type.int
The number of dimensions this array type has.Returns the element type of the array.boolean
Compares thisType
with another type.int
hashCode()
Computes a hash code representing this type.(package private) boolean
(package private) int
kind()
Returns the kind of Type this is.name()
Returns the name of this type (or its erasure in case of generic types) as aDotName
, using theClass.getName()
format.(package private) String
toString
(boolean simple) (package private) Type
Returns this type with all type annotations removed.Methods inherited from class org.jboss.jandex.Type
addAnnotation, annotation, annotationArray, annotations, annotationsWithRepeatable, appendAnnotations, asClassType, asParameterizedType, asPrimitiveType, asTypeVariable, asTypeVariableReference, asUnresolvedTypeVariable, asVoidType, asWildcardType, create, create, createWithAnnotations, descriptor, hasAnnotation, parse, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.jboss.jandex.Descriptor
descriptor
-
Field Details
-
constituent
-
dimensions
private final int dimensions -
hash
private int hash
-
-
Constructor Details
-
ArrayType
ArrayType(Type constituent, int dimensions) -
ArrayType
ArrayType(Type constituent, int dimensions, AnnotationInstance[] annotations)
-
-
Method Details
-
create
Create a new array type instance with the specified number of dimensions and the specified constituent type.- Parameters:
constituent
- the constituent typedimensions
- the number of dimensions of this array- Returns:
- the new array type instance
- Since:
- 2.1
- See Also:
-
builder
Create a builder of an array type.- Parameters:
constituent
- the constituent typedimensions
- the number of dimensions of the array- Returns:
- the builder
- Since:
- 3.1.0
- See Also:
-
component
Deprecated.useconstituent()
Equivalent toconstituent()
.This method provides access to the Jandex compressed representation of array types. It is likely you want to use
elementType()
orcomponentType()
instead. -
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 ofString
, whileString[] @Ann []
has 1 dimension and a constituent type ofString @Ann []
. TheString @Ann []
array type, in turn, has 1 dimension and a constituent type ofString
.This method provides access to the Jandex compressed representation of array types. It is likely you want to use
elementType()
orcomponentType()
instead.- Returns:
- the constituent type
- Since:
- 3.1.0
-
elementType
Returns the element type of the array. For example, bothString[][]
andString @Ann []
have an element type ofString
.This method never returns an
ArrayType
.- Returns:
- the element type
- Since:
- 3.1.0
-
componentType
Returns the component type of the array. For example,String[][]
has a component type ofString[]
, whileString [] @Ann []
has a component type ofString @Ann []
.- Returns:
- the component type
- Since:
- 3.1.0
-
dimensions
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 ofString[][]
, but it would return 1 for an array type ofString[] @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 thisArrayType
has anotherArrayType
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:
- the number of dimensions of this array type
-
deepDimensions
public int deepDimensions()The total number of dimensions this array type has, when traversed deep to the element type. For example, bothString[][]
andString[] @Ann []
have a "deep" number of dimensions equal to 2.This method is different to
dimensions()
in case thisArrayType
has anotherArrayType
as its constituent type.- Returns:
- the "deep" number of dimensions of this array type
- Since:
- 3.1.0
-
name
Description copied from class:Type
Returns the name of this type (or its erasure in case of generic types) as aDotName
, using theClass.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 orLbinary.name.of.TheClass;
for class types (for example,[I
forint[]
or[[Ljava.lang.String;
forString[][]
); - for parameterized types, the binary name of the generic class is returned
(for example,
java.util.List
forList<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
).
- for primitive types and the void pseudo-type, the corresponding Java keyword
is returned (
-
kind
Description copied from class:Type
Returns the kind of Type this is. -
asArrayType
Description copied from class:Type
Casts this type to anArrayType
and returns it if the kind isType.Kind.ARRAY
. Throws an exception otherwise.- Overrides:
asArrayType
in classType
- Returns:
- an
ArrayType
-
copyType
-
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 classType
- Returns:
- this type without type annotations
-
copyType
-
toString
-
appendRootComponent
-
appendArraySyntax
-
equals
Description copied from class:Type
Compares thisType
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. -
hashCode
public int hashCode()Description copied from class:Type
Computes a hash code representing this type. -
internEquals
- Overrides:
internEquals
in classType
-
internHashCode
int internHashCode()- Overrides:
internHashCode
in classType
-
constituent()