FileDocCategorySizeDatePackage
Types.javaAPI DocJava SE 6 API10533Tue Jun 10 00:26:12 BST 2008javax.lang.model.util

Types

public interface Types
Utility methods for operating on types.

Compatibility Note: Methods may be added to this interface in future releases of the platform.

author
Joseph D. Darcy
author
Scott Seligman
author
Peter von der Ahé
version
1.7 06/07/11
see
javax.annotation.processing.ProcessingEnvironment#getTypeUtils
since
1.6

Fields Summary
Constructors Summary
Methods Summary
public javax.lang.model.element.ElementasElement(javax.lang.model.type.TypeMirror t)
Returns the element corresponding to a type. The type may be a {@code DeclaredType} or {@code TypeVariable}. Returns {@code null} if the type is not one with a corresponding element.

return
the element corresponding to the given type

public javax.lang.model.type.TypeMirrorasMemberOf(javax.lang.model.type.DeclaredType containing, javax.lang.model.element.Element element)
Returns the type of an element when that element is viewed as a member of, or otherwise directly contained by, a given type. For example, when viewed as a member of the parameterized type {@code Set}, the {@code Set.add} method is an {@code ExecutableType} whose parameter is of type {@code String}.

param
containing the containing type
param
element the element
return
the type of the element as viewed from the containing type
throws
IllegalArgumentException if the element is not a valid one for the given type

public javax.lang.model.element.TypeElementboxedClass(javax.lang.model.type.PrimitiveType p)
Returns the class of a boxed value of a given primitive type. That is, boxing conversion is applied.

param
p the primitive type to be converted
return
the class of a boxed value of type {@code p}
jls3
5.1.7 Boxing Conversion

public javax.lang.model.type.TypeMirrorcapture(javax.lang.model.type.TypeMirror t)
Applies capture conversion to a type.

param
t the type to be converted
return
the result of applying capture conversion
throws
IllegalArgumentException if given an executable or package type
jls3
5.1.10 Capture Conversion

public booleancontains(javax.lang.model.type.TypeMirror t1, javax.lang.model.type.TypeMirror t2)
Tests whether one type argument contains another.

param
t1 the first type
param
t2 the second type
return
{@code true} if and only if the first type contains the second
throws
IllegalArgumentException if given an executable or package type
jls3
4.5.1.1 Type Argument Containment and Equivalence

public java.util.ListdirectSupertypes(javax.lang.model.type.TypeMirror t)
Returns the direct supertypes of a type. The interface types, if any, will appear last in the list.

param
t the type being examined
return
the direct supertypes, or an empty list if none
throws
IllegalArgumentException if given an executable or package type

public javax.lang.model.type.TypeMirrorerasure(javax.lang.model.type.TypeMirror t)
Returns the erasure of a type.

param
t the type to be erased
return
the erasure of the given type
throws
IllegalArgumentException if given a package type
jls3
4.6 Type Erasure

public javax.lang.model.type.ArrayTypegetArrayType(javax.lang.model.type.TypeMirror componentType)
Returns an array type with the specified component type.

param
componentType the component type
return
an array type with the specified component type.
throws
IllegalArgumentException if the component type is not valid for an array

public javax.lang.model.type.DeclaredTypegetDeclaredType(javax.lang.model.element.TypeElement typeElem, javax.lang.model.type.TypeMirror typeArgs)
Returns the type corresponding to a type element and actual type arguments. Given the type element for {@code Set} and the type mirror for {@code String}, for example, this method may be used to get the parameterized type {@code Set}.

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 {@code Outer.Inner}, for example, may be constructed by first using this method to get the type {@code Outer}, and then invoking {@link #getDeclaredType(DeclaredType, TypeElement, TypeMirror...)}.

param
typeElem the type element
param
typeArgs the actual type arguments
return
the type corresponding to the type element and actual type arguments
throws
IllegalArgumentException if too many or too few type arguments are given, or if an inappropriate type argument or type element is provided

public javax.lang.model.type.DeclaredTypegetDeclaredType(javax.lang.model.type.DeclaredType containing, javax.lang.model.element.TypeElement typeElem, javax.lang.model.type.TypeMirror typeArgs)
Returns the type corresponding to a type element and actual type arguments, given a {@linkplain DeclaredType#getEnclosingType() containing type} of which it is a member. The parameterized type {@code Outer.Inner}, for example, may be constructed by first using {@link #getDeclaredType(TypeElement, TypeMirror...)} to get the type {@code Outer}, and then invoking this method.

If the containing type is a parameterized type, the number of type arguments must equal the number of {@code typeElem}'s formal type parameters. If it is not parameterized or if it is {@code null}, this method is equivalent to {@code getDeclaredType(typeElem, typeArgs)}.

param
containing the containing type, or {@code null} if none
param
typeElem the type element
param
typeArgs the actual type arguments
return
the type corresponding to the type element and actual type arguments, contained within the given type
throws
IllegalArgumentException if too many or too few type arguments are given, or if an inappropriate type argument, type element, or containing type is provided

public javax.lang.model.type.NoTypegetNoType(javax.lang.model.type.TypeKind kind)
Returns a pseudo-type used where no actual type is appropriate. The kind of type to return may be either {@link TypeKind#VOID VOID} or {@link TypeKind#NONE NONE}. For packages, use {@link Elements#getPackageElement(CharSequence)}{@code .asType()} instead.

param
kind the kind of type to return
return
a pseudo-type of kind {@code VOID} or {@code NONE}
throws
IllegalArgumentException if {@code kind} is not valid

public javax.lang.model.type.NullTypegetNullType()
Returns the null type. This is the type of {@code null}.

return
the null type

public javax.lang.model.type.PrimitiveTypegetPrimitiveType(javax.lang.model.type.TypeKind kind)
Returns a primitive type.

param
kind the kind of primitive type to return
return
a primitive type
throws
IllegalArgumentException if {@code kind} is not a primitive kind

public javax.lang.model.type.WildcardTypegetWildcardType(javax.lang.model.type.TypeMirror extendsBound, javax.lang.model.type.TypeMirror superBound)
Returns a new wildcard type argument. Either of the wildcard's bounds may be specified, or neither, but not both.

param
extendsBound the extends (upper) bound, or {@code null} if none
param
superBound the super (lower) bound, or {@code null} if none
return
a new wildcard
throws
IllegalArgumentException if bounds are not valid

public booleanisAssignable(javax.lang.model.type.TypeMirror t1, javax.lang.model.type.TypeMirror t2)
Tests whether one type is assignable to another.

param
t1 the first type
param
t2 the second type
return
{@code true} if and only if the first type is assignable to the second
throws
IllegalArgumentException if given an executable or package type
jls3
5.2 Assignment Conversion

public booleanisSameType(javax.lang.model.type.TypeMirror t1, javax.lang.model.type.TypeMirror t2)
Tests whether two {@code 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:

{@code List list = new ArrayList();}
{@code list.add(list.get(0));}

param
t1 the first type
param
t2 the second type
return
{@code true} if and only if the two types are the same

public booleanisSubsignature(javax.lang.model.type.ExecutableType m1, javax.lang.model.type.ExecutableType m2)
Tests whether the signature of one method is a subsignature of another.

param
m1 the first method
param
m2 the second method
return
{@code true} if and only if the first signature is a subsignature of the second
jls3
8.4.2 Method Signature

public booleanisSubtype(javax.lang.model.type.TypeMirror t1, javax.lang.model.type.TypeMirror t2)
Tests whether one type is a subtype of another. Any type is considered to be a subtype of itself.

param
t1 the first type
param
t2 the second type
return
{@code true} if and only if the first type is a subtype of the second
throws
IllegalArgumentException if given an executable or package type
jls3
4.10 Subtyping

public javax.lang.model.type.PrimitiveTypeunboxedType(javax.lang.model.type.TypeMirror t)
Returns the type (a primitive type) of unboxed values of a given type. That is, unboxing conversion is applied.

param
t the type to be unboxed
return
the type of an unboxed value of type {@code t}
throws
IllegalArgumentException if the given type has no unboxing conversion
jls3
5.1.8 Unboxing Conversion