public interface Types
Compatibility Note: Methods may be added to this interface in future releases of the platform.
ProcessingEnvironment.getTypeUtils()
| Modifier and Type | Method and Description |
|---|---|
Element |
asElement(TypeMirror
Returns the element corresponding to a type.
|
TypeMirror |
asMemberOf(DeclaredType
Returns the type of an element when that element is viewed as a member of, or otherwise directly contained by, a given type.
|
TypeElement |
boxedClass(PrimitiveType
Returns the class of a boxed value of a given primitive type.
|
TypeMirror |
capture(TypeMirror
Applies capture conversion to a type.
|
boolean |
contains(TypeMirror
Tests whether one type argument
contains another.
|
List |
directSupertypes(TypeMirror
Returns the direct supertypes of a type.
|
TypeMirror |
erasure(TypeMirror
Returns the erasure of a type.
|
ArrayType |
getArrayType(TypeMirror
Returns an array type with the specified component type.
|
DeclaredType |
getDeclaredType(DeclaredType
Returns the type corresponding to a type element and actual type arguments, given a
containing type of which it is a member.
|
DeclaredType |
getDeclaredType(TypeElement
Returns the type corresponding to a type element and actual type arguments.
|
NoType |
getNoType(TypeKind
Returns a pseudo-type used where no actual type is appropriate.
|
NullType |
getNullType()
Returns the null type.
|
PrimitiveType |
getPrimitiveType(TypeKind
Returns a primitive type.
|
WildcardType |
getWildcardType(TypeMirror
Returns a new wildcard type argument.
|
boolean |
isAssignable(TypeMirror
Tests whether one type is assignable to another.
|
boolean |
isSameType(TypeMirror
Tests whether two
TypeMirror objects represent the same type.
|
boolean |
isSubsignature(ExecutableType
Tests whether the signature of one method is a
subsignature of another.
|
boolean |
isSubtype(TypeMirror
Tests whether one type is a subtype of another.
|
PrimitiveType |
unboxedType(TypeMirror
Returns the type (a primitive type) of unboxed values of a given type.
|
ElementasElement(TypeMirror t)
DeclaredType or
TypeVariable. Returns
null if the type is not one with a corresponding element.
t - the type to map to an element
boolean isSameType(TypeMirrort1, TypeMirror t2)
TypeMirror objects represent the same type.
Caveat: if either of the arguments to this method represents a wildcard, this method will return false. As a consequence, a wildcard is not the same type as itself. This might be surprising at first, but makes sense once you consider that an example like this must be rejected by the compiler:
List<?> list = new ArrayList<Object>();list.add(list.get(0));
Since annotations are only meta-data associated with a type, the set of annotations on either argument is not taken into account when computing whether or not two TypeMirror objects are the same type. In particular, two TypeMirror objects can have different annotations and still be considered the same.
t1 - the first type
t2 - the second type
true if and only if the two types are the same
boolean isSubtype(TypeMirrort1, TypeMirror t2)
t1 - the first type
t2 - the second type
true if and only if the first type is a subtype of the second
IllegalArgumentException - if given an executable or package type
boolean isAssignable(TypeMirrort1, TypeMirror t2)
t1 - the first type
t2 - the second type
true if and only if the first type is assignable to the second
IllegalArgumentException - if given an executable or package type
boolean contains(TypeMirrort1, TypeMirror t2)
t1 - the first type
t2 - the second type
true if and only if the first type contains the second
IllegalArgumentException - if given an executable or package type
boolean isSubsignature(ExecutableTypem1, ExecutableType m2)
m1 - the first method
m2 - the second method
true if and only if the first signature is a subsignature of the second
List<? extends TypeMirror > directSupertypes(TypeMirror t)
t - the type being examined
IllegalArgumentException - if given an executable or package type
TypeMirrorerasure(TypeMirror t)
t - the type to be erased
IllegalArgumentException - if given a package type
TypeElementboxedClass(PrimitiveType p)
p - the primitive type to be converted
p
PrimitiveTypeunboxedType(TypeMirror t)
t - the type to be unboxed
t
IllegalArgumentException - if the given type has no unboxing conversion
TypeMirrorcapture(TypeMirror t)
t - the type to be converted
IllegalArgumentException - if given an executable or package type
PrimitiveTypegetPrimitiveType(TypeKind kind)
kind - the kind of primitive type to return
IllegalArgumentException - if
kind is not a primitive kind
NullTypegetNullType()
null.
NoTypegetNoType(TypeKind kind)
VOID or
NONE. For packages, use
Elements.getPackageElement(CharSequence)
.asType() instead.
kind - the kind of type to return
VOID or
NONE
IllegalArgumentException - if
kind is not valid
ArrayTypegetArrayType(TypeMirror componentType)
componentType - the component type
IllegalArgumentException - if the component type is not valid for an array
WildcardTypegetWildcardType(TypeMirror extendsBound, TypeMirror superBound)
extendsBound - the extends (upper) bound, or
null if none
superBound - the super (lower) bound, or
null if none
IllegalArgumentException - if bounds are not valid
DeclaredTypegetDeclaredType(TypeElement typeElem, TypeMirror ... typeArgs)
Set and the type mirror for
String, for example, this method may be used to get the parameterized type
Set<String>.
The number of type arguments must either equal the number of the type element's formal type parameters, or must be zero. If zero, and if the type element is generic, then the type element's raw type is returned.
If a parameterized type is being returned, its type element must not be contained within a generic outer class. The parameterized type Outer<String>.Inner<Number>, for example, may be constructed by first using this method to get the type Outer<String>, and then invoking getDeclaredType(DeclaredType, TypeElement, TypeMirror...).
typeElem - the type element
typeArgs - the actual type arguments
IllegalArgumentException - if too many or too few type arguments are given, or if an inappropriate type argument or type element is provided
DeclaredTypegetDeclaredType(DeclaredType containing, TypeElement typeElem, TypeMirror ... typeArgs)
Outer<String>.Inner<Number>, for example, may be constructed by first using
getDeclaredType(TypeElement, TypeMirror...) to get the type
Outer<String>, and then invoking this method.
If the containing type is a parameterized type, the number of type arguments must equal the number of typeElem's formal type parameters. If it is not parameterized or if it is null, this method is equivalent to getDeclaredType(typeElem, typeArgs).
containing - the containing type, or
null if none
typeElem - the type element
typeArgs - the actual type arguments
IllegalArgumentException - if too many or too few type arguments are given, or if an inappropriate type argument, type element, or containing type is provided
TypeMirrorasMemberOf(DeclaredType containing, Element element)
Set<String>, the
Set.add method is an
ExecutableType whose parameter is of type
String.
containing - the containing type
element - the element
IllegalArgumentException - if the element is not a valid one for the given type