Top Description Inners Fields Constructors Methods
org.jboss.jandex

public abstract Class Type

extends Object
implements Descriptor
Class Inheritance
All Implemented Interfaces
org.jboss.jandex.Descriptor
Known Direct Subclasses
org.jboss.jandex.TypeVariable, org.jboss.jandex.TypeVariableReference, org.jboss.jandex.UnresolvedTypeVariable, org.jboss.jandex.VoidType, org.jboss.jandex.WildcardType, org.jboss.jandex.ArrayType, org.jboss.jandex.ClassType, org.jboss.jandex.ParameterizedType, org.jboss.jandex.PrimitiveType
Imports
java.util.ArrayList, .Arrays, .Collections, .List, .Objects, java.util.function.Function

Represents a Java type usage that is specified on methods, fields, classes, annotations, or other types. A type can be any class based type (interface, class, annotation), any primitive, any array, any generic type declaration, or void.

A type usage may have annotations associated with its declaration. A type is equal to another type if, and only if, it represents the same exact definition including the annotations specific to its usage.

To reduce memory overhead, type instances are often shared between their enclosing classes.

Author
Jason T. Greene

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract static class
Type.Builder<
self type
THIS extends Type.Builder<THIS>
>

Base class for type builders.

public static enum
Type.Kind

Represents a "kind" of Type.

Field Summary

Modifier and TypeField and Description
private final AnnotationInstance[]
private static final AnnotationInstance[]
public static final Type[]
private final DotName

Constructor Summary

AccessConstructor and Description
pack-priv
Type(DotName name, AnnotationInstance[] annotations)

Method Summary

Modifier and TypeMethod and Description
pack-priv Type
public final AnnotationInstance

Returns:

the annotation instance, or null if not found
annotation
(DotName
name of the annotation type to look for, must not be null
name
)

Returns the annotation instance with given name declared on this type usage.

pack-priv AnnotationInstance[]
public List<AnnotationInstance>

Returns:

immutable list of annotation instances, never null
annotations
()

Returns the annotation instances declared on this type usage.

public final List<AnnotationInstance>

Returns:

immutable list of annotation instances, never null
annotationsWithRepeatable
(DotName
name of the annotation type, must not be null
name
,
IndexView
index used to obtain the annotation type, must not be null
index
)

Returns the annotation instances with given name declared on this type usage.

pack-priv void
public ArrayType

Returns:

an ArrayType
asArrayType
()

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

public ClassType

Returns:

a ClassType
asClassType
()

Casts this type to a org.jboss.jandex.ClassType and returns it if the kind is Kind#CLASS.

public ParameterizedType

Returns:

a ParameterizedType
asParameterizedType
()

Casts this type to a org.jboss.jandex.ParameterizedType and returns it if the kind is Kind#PARAMETERIZED_TYPE.

public PrimitiveType

Returns:

a PrimitiveType
asPrimitiveType
()

Casts this type to a org.jboss.jandex.PrimitiveType and returns it if the kind is Kind#PRIMITIVE.

public TypeVariable

Returns:

a TypeVariable
asTypeVariable
()

Casts this type to a org.jboss.jandex.TypeVariable and returns it if the kind is Kind#TYPE_VARIABLE.

public TypeVariableReference

Returns:

a TypeVariableReference
asTypeVariableReference
()

Casts this type to a org.jboss.jandex.TypeVariableReference and returns it if the kind is Kind#TYPE_VARIABLE_REFERENCE.

public UnresolvedTypeVariable

Returns:

an UnresolvedTypeVariable
asUnresolvedTypeVariable
()

Casts this type to an org.jboss.jandex.UnresolvedTypeVariable and returns it if the kind is Kind#UNRESOLVED_TYPE_VARIABLE.

public VoidType

Returns:

a VoidType
asVoidType
()

Casts this type to a org.jboss.jandex.VoidType and returns it if the kind is Kind#VOID.

public WildcardType

Returns:

a WildcardType
asWildcardType
()

Casts this type to a org.jboss.jandex.WildcardType and returns it if the kind is Kind#WILDCARD_TYPE.

pack-priv abstract Type
copyType(AnnotationInstance[] newAnnotations)

public static Type

Returns:

the type
create
(DotName
the name of type to use or parse; must not be null
name
,
Type.Kind
the kind of type to create; must not be null
kind
)

Creates a type of the specified kind and name in the Class#getName() format.

public static Type

Returns:

the annotated type
createWithAnnotations
(DotName
the name of type to use or parse; must not be null
name
,
Type.Kind
the kind of type to create; must not be null
kind
,
AnnotationInstance[]
the type annotations that should be present on the type instance; may be null
annotations
)

Creates an instance of specified type with given type annotations.

public String

Returns:

the bytecode descriptor of this type (or its erasure in case of generic types)
descriptor
(Function<String, Type>
a substitution function from type variable identifiers to types
typeVariableSubstitution
)

Implements org.jboss.jandex.Descriptor.descriptor.

Returns the bytecode descriptor of this type (or its erasure in case of generic types).
public boolean

Returns:

true if equal
equals
(Object
the type to compare to
o
)

Overrides java.lang.Object.equals.

Compares this Type with another type.
public final boolean

Returns:

true if the annotation is present, false otherwise
hasAnnotation
(DotName
name of the annotation type to look for, must not be null
name
)

Returns whether an annotation instance with given name is declared on this type usage.

public int

Returns:

the hash code
hashCode
()

Overrides java.lang.Object.hashCode.

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

Returns:

the kind
kind
()

Returns the kind of Type this is.

public DotName

Returns:

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

Returns the name of this type (or its erasure in case of generic types) as a DotName, using the Class#getName() format.

public String

Returns:

the string representation.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation for this type.
pack-priv String
toString(boolean simple)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

annotationsback to summary
private final AnnotationInstance[] annotations
EMPTY_ANNOTATIONSback to summary
private static final AnnotationInstance[] EMPTY_ANNOTATIONS
EMPTY_ARRAYback to summary
public static final Type[] EMPTY_ARRAY
nameback to summary
private final DotName name

Constructor Detail

Typeback to summary
pack-priv Type(DotName name, AnnotationInstance[] annotations)

Method Detail

addAnnotationback to summary
pack-priv Type addAnnotation(AnnotationInstance annotation)
annotationback to summary
public final AnnotationInstance annotation(DotName name)

Returns the annotation instance with given name declared on this type usage.

To allow for Type object reuse, the annotation instances returned by this method have a null annotation target.

Parameters
name:DotName

name of the annotation type to look for, must not be null

Returns:AnnotationInstance

the annotation instance, or null if not found

annotationArrayback to summary
pack-priv AnnotationInstance[] annotationArray()
annotationsback to summary
public List<AnnotationInstance> annotations()

Returns the annotation instances declared on this type usage.

To allow for Type object reuse, the annotation instances returned by this method have a null annotation target.

Returns:List<AnnotationInstance>

immutable list of annotation instances, never null

Since
2.0
annotationsWithRepeatableback to summary
public final List<AnnotationInstance> annotationsWithRepeatable(DotName name, IndexView index)

Returns the annotation instances with given name declared on this type usage.

If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the AnnotationInstance#target() returns the target of the container annotation instance.

To allow for Type object reuse, the annotation instances returned by this method have a null annotation target.

Parameters
name:DotName

name of the annotation type, must not be null

index:IndexView

index used to obtain the annotation type, must not be null

Returns:List<AnnotationInstance>

immutable list of annotation instances, never null

Exceptions
IllegalArgumentException:
if the index is null, if the index does not contain the annotation type or if name does not identify an annotation type
Since
3.0
See Also
annotations()
appendAnnotationsback to summary
pack-priv void appendAnnotations(StringBuilder builder)
asArrayTypeback to summary
public ArrayType 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

Exceptions
IllegalArgumentException:
if not an array type
Since
2.0
asClassTypeback to summary
public ClassType asClassType()

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

Returns:ClassType

a ClassType

Exceptions
IllegalArgumentException:
if not a class
Since
2.0
asParameterizedTypeback to summary
public ParameterizedType asParameterizedType()

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

Returns:ParameterizedType

a ParameterizedType

Exceptions
IllegalArgumentException:
if not a parameterized type
Since
2.0
asPrimitiveTypeback to summary
public PrimitiveType asPrimitiveType()

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

Returns:PrimitiveType

a PrimitiveType

Exceptions
IllegalArgumentException:
if not a primitive type
Since
2.0
asTypeVariableback to summary
public TypeVariable asTypeVariable()

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

Returns:TypeVariable

a TypeVariable

Exceptions
IllegalArgumentException:
if not a type variable
Since
2.0
asTypeVariableReferenceback to summary
public TypeVariableReference asTypeVariableReference()

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

Returns:TypeVariableReference

a TypeVariableReference

Exceptions
IllegalArgumentException:
if not a type variable
Since
2.0
asUnresolvedTypeVariableback to summary
public UnresolvedTypeVariable asUnresolvedTypeVariable()

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

Returns:UnresolvedTypeVariable

an UnresolvedTypeVariable

Exceptions
IllegalArgumentException:
if not an unresolved type
Since
2.0
asVoidTypeback to summary
public VoidType asVoidType()

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

Returns:VoidType

a VoidType

Exceptions
IllegalArgumentException:
if not a void type
Since
2.0
asWildcardTypeback to summary
public WildcardType asWildcardType()

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

Returns:WildcardType

a WildcardType

Exceptions
IllegalArgumentException:
if not a wildcard type
Since
2.0
copyTypeback to summary
pack-priv abstract Type copyType(AnnotationInstance[] newAnnotations)
createback to summary
public static Type create(DotName name, Type.Kind kind)

Creates a type of the specified kind and name in the Class#getName() format. Specifically:

  • if kind is VOID, the name is ignored;
  • if kind is PRIMITIVE, the name must be the corresponding Java keyword (boolean, byte, short, int, long, float, double, char);
  • if kind is CLASS, the name must be a binary name of the class;
  • if kind is ARRAY, the name must 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[][]);
  • all other kinds cause an exception.
Parameters
name:DotName

the name of type to use or parse; must not be null

kind:Type.Kind

the kind of type to create; must not be null

Returns:Type

the type

Exceptions
IllegalArgumentException:
if the kind is not supported
createWithAnnotationsback to summary
public static Type createWithAnnotations(DotName name, Type.Kind kind, AnnotationInstance[] annotations)

Creates an instance of specified type with given type annotations. To create the type instance, this method delegates to create(DotName, Kind).

Parameters
name:DotName

the name of type to use or parse; must not be null

kind:Type.Kind

the kind of type to create; must not be null

annotations:AnnotationInstance[]

the type annotations that should be present on the type instance; may be null

Returns:Type

the annotated type

Exceptions
IllegalArgumentException:
if the kind is not supported
descriptorback to summary
public String descriptor(Function<String, Type> typeVariableSubstitution)

Implements org.jboss.jandex.Descriptor.descriptor.

Returns the bytecode descriptor of this type (or its erasure in case of generic types). Specifically:

  • for primitive types and the void pseudo-type, the single-character descriptor is returned;
  • for class types, the Lbinary/name/of/TheClass; string 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 descriptor of the element type (for example, [I for int[] or [[Ljava/lang/String; for String[][]);
  • for parameterized types, the descriptor of the generic class is returned (for example, Ljava/util/List; for List<String>);
  • for type variables, the descriptor of the first bound of the type variable is returned, or the descriptor of the java.lang.Object class for type variables that have no bound;
  • for wildcard types, the descriptor of the upper bound is returned, or the descriptor of the java.lang.Object class if the wildcard type does not have an upper bound (for example, Ljava/lang/Number; for ? extends Number).
Descriptors of type variables are substituted for descriptors of types provided by the substitution function typeVariableSubstitution. If the substitution function returns null for some type variable identifier, or if it returns the type variable itself, no substitution happens and the type variable descriptor is used unmodified.

Note that the return value does not come directly from bytecode. Jandex does not store the descriptor strings. Instead, the return value is reconstructed from the Jandex object model.

Parameters
typeVariableSubstitution:Function<String, Type>

Doc from org.jboss.jandex.Descriptor.descriptor.

a substitution function from type variable identifiers to types

Returns:String

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

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.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
See Also
Object#equals(Object)
hasAnnotationback to summary
public final boolean hasAnnotation(DotName name)

Returns whether an annotation instance with given name is declared on this type usage.

Parameters
name:DotName

name of the annotation type to look for, must not be null

Returns:boolean

true if the annotation is present, false otherwise

See Also
annotation(DotName)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Computes a hash code representing this type.

Returns:int

the hash code

Annotations
@Override
internEqualsback to summary
pack-priv boolean internEquals(Object o)
internHashCodeback to summary
pack-priv int internHashCode()
kindback to summary
public abstract Type.Kind kind()

Returns the kind of Type this is.

Returns:Type.Kind

the kind

nameback to summary
public DotName 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)

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation for this type. It is similar, yet not identical to a Java source code representation.

Returns:String

the string representation.

toStringback to summary
pack-priv String toString(boolean simple)
org.jboss.jandex back to summary

pack-priv abstract Class Type.Builder<THIS extends Type.Builder<THIS>>

extends Object
Class Inheritance
Known Direct Subclasses
org.jboss.jandex.TypeVariable.Builder, org.jboss.jandex.WildcardType.Builder, org.jboss.jandex.ArrayType.Builder, org.jboss.jandex.ClassType.Builder, org.jboss.jandex.ParameterizedType.Builder
Type Parameters
<THIS>
self type

Base class for type builders.
Since
3.1.0

Field Summary

Modifier and TypeField and Description
protected final List<AnnotationInstance>
protected final DotName

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public THIS

Returns:

this builder
addAnnotation
(AnnotationInstance
the annotation instance; can be created using AnnotationInstance.builder()
annotation
)

Adds an annotation to the type being created by this builder.

protected AnnotationInstance[]

Returns:

the annotations array or null if no annotation was specified
annotationsArray
()

protected THIS
self()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotationsback to summary
protected final List<AnnotationInstance> annotations
nameback to summary
protected final DotName name

Constructor Detail

Builderback to summary
protected Builder(DotName name)

Method Detail

addAnnotationback to summary
public THIS addAnnotation(AnnotationInstance annotation)

Adds an annotation to the type being created by this builder. Note that it becomes a type annotation.

Parameters
annotation:AnnotationInstance

the annotation instance; can be created using AnnotationInstance.builder()

Returns:THIS

this builder

See Also
Type#annotations()
annotationsArrayback to summary
protected AnnotationInstance[] annotationsArray()
Returns:AnnotationInstance[]

the annotations array or null if no annotation was specified

selfback to summary
protected THIS self()
Annotations
@SuppressWarnings:unchecked
org.jboss.jandex back to summary

public final Enum Type.Kind

extends Enum<Type.Kind>
Class Inheritance

Represents a "kind" of Type.
Author
Jason T. Greene

Field Summary

Modifier and TypeField and Description
public static final Type.Kind
ARRAY

A Java array

public static final Type.Kind
CLASS

A Java class, interface, or annotation

public static final Type.Kind
PARAMETERIZED_TYPE

A generic parameterized type

public static final Type.Kind
PRIMITIVE

A Java primitive (boolean, byte, short, char, int, long, float, double)

public static final Type.Kind
TYPE_VARIABLE

A resolved generic type parameter or type argument

public static final Type.Kind
TYPE_VARIABLE_REFERENCE

A reference to a resolved type variable occuring in the bound of a recursive type parameter

public static final Type.Kind
UNRESOLVED_TYPE_VARIABLE

An unresolved type parameter or argument.

public static final Type.Kind
VOID

Used to designate a Java method that returns nothing

public static final Type.Kind
WILDCARD_TYPE

A generic wildcard type

Constructor Summary

AccessConstructor and Description
private
Kind()

Method Summary

Modifier and TypeMethod and Description
public static Type.Kind
fromOrdinal(int ordinal)

public static Type.Kind
public static Type.Kind[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ARRAYback to summary
public static final Type.Kind ARRAY

A Java array

CLASSback to summary
public static final Type.Kind CLASS

A Java class, interface, or annotation

PARAMETERIZED_TYPEback to summary
public static final Type.Kind PARAMETERIZED_TYPE

A generic parameterized type

PRIMITIVEback to summary
public static final Type.Kind PRIMITIVE

A Java primitive (boolean, byte, short, char, int, long, float, double)

TYPE_VARIABLEback to summary
public static final Type.Kind TYPE_VARIABLE

A resolved generic type parameter or type argument

TYPE_VARIABLE_REFERENCEback to summary
public static final Type.Kind TYPE_VARIABLE_REFERENCE

A reference to a resolved type variable occuring in the bound of a recursive type parameter

UNRESOLVED_TYPE_VARIABLEback to summary
public static final Type.Kind UNRESOLVED_TYPE_VARIABLE

An unresolved type parameter or argument. This is merely a placeholder which occurs during an error condition or incomplete processing. In most cases, it need not be dealt with.

VOIDback to summary
public static final Type.Kind VOID

Used to designate a Java method that returns nothing

WILDCARD_TYPEback to summary
public static final Type.Kind WILDCARD_TYPE

A generic wildcard type

Constructor Detail

Kindback to summary
private Kind()

Method Detail

fromOrdinalback to summary
public static Type.Kind fromOrdinal(int ordinal)
valueOfback to summary
public static Type.Kind valueOf(String name)
valuesback to summary
public static Type.Kind[] values()