Class ArrayType
- java.lang.Object
-
- org.jboss.jandex.Type
-
- org.jboss.jandex.ArrayType
-
- All Implemented Interfaces:
Descriptor
public final class ArrayType extends Type
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[][]
isString
. 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 ofString[][]
isString[]
, whose component type isString
. 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 ofString
. 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 ofString[] @Ann []
has 1 dimension and a constituent type ofString @Ann []
. In turn, this array type has 1 dimension and a constituent type ofString
.The
constituent()
anddimensions()
methods provide access to the Jandex native representation. TheelementType()
andcomponentType()
methods, as well asdeepDimensions()
, provide access to the Java language representation.The
component()
method is present for backwards compatibility and should not be used. It is equivalent to theconstituent()
method.- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ArrayType.Builder
Convenient builder forArrayType
.
-
Field Summary
Fields Modifier and Type Field Description private Type
constituent
private int
dimensions
private int
hash
-
Fields inherited from class org.jboss.jandex.Type
EMPTY_ARRAY
-
Fields inherited from interface org.jboss.jandex.Descriptor
NO_SUBSTITUTION
-
-
Constructor Summary
Constructors Constructor Description ArrayType(Type constituent, int dimensions)
ArrayType(Type constituent, int dimensions, AnnotationInstance[] annotations)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private void
appendArraySyntax(java.lang.StringBuilder builder)
private void
appendRootComponent(java.lang.StringBuilder builder, boolean simple)
ArrayType
asArrayType()
Casts this type to anArrayType
and returns it if the kind isType.Kind.ARRAY
.static ArrayType.Builder
builder(Type constituent, int dimensions)
Create a builder of an array type.Type
component()
Deprecated.useconstituent()
Type
componentType()
Returns the component type of the array.Type
constituent()
Returns the constituent type of the array.(package private) Type
copyType(AnnotationInstance[] newAnnotations)
(package private) Type
copyType(Type component, int dimensions)
static ArrayType
create(Type constituent, int dimensions)
Create a new array type instance with the specified number of dimensions and the specified constituent type.int
deepDimensions()
The total number of dimensions this array type has, when traversed deep to the element type.int
dimensions()
The number of dimensions this array type has.Type
elementType()
Returns the element type of the array.boolean
equals(java.lang.Object o)
Compares thisType
with another type.int
hashCode()
Computes a hash code representing this type.(package private) boolean
internEquals(java.lang.Object o)
(package private) int
internHashCode()
Type.Kind
kind()
Returns the kind of Type this is.DotName
name()
Returns the name of this type (or its erasure in case of generic types) as aDotName
, using theClass.getName()
format.(package private) java.lang.String
toString(boolean simple)
(package private) Type
withoutAnnotations()
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 Detail
-
constituent
private final Type constituent
-
dimensions
private final int dimensions
-
hash
private int hash
-
-
Constructor Detail
-
ArrayType
ArrayType(Type constituent, int dimensions)
-
ArrayType
ArrayType(Type constituent, int dimensions, AnnotationInstance[] annotations)
-
-
Method Detail
-
create
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
- the constituent typedimensions
- the number of dimensions of this array- Returns:
- the new array type instance
- Since:
- 2.1
- See Also:
constituent()
,dimensions()
-
builder
public static ArrayType.Builder builder(Type constituent, int dimensions)
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:
constituent()
,dimensions()
-
component
@Deprecated public Type 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
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 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
public Type 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
public Type 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
public DotName 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 (
-
asArrayType
public ArrayType 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
Type copyType(AnnotationInstance[] newAnnotations)
-
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
-
appendRootComponent
private void appendRootComponent(java.lang.StringBuilder builder, boolean simple)
-
appendArraySyntax
private void appendArraySyntax(java.lang.StringBuilder builder)
-
equals
public boolean equals(java.lang.Object o)
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
boolean internEquals(java.lang.Object o)
- Overrides:
internEquals
in classType
-
internHashCode
int internHashCode()
- Overrides:
internHashCode
in classType
-
-