Mirror API

com.sun.mirror.util
Interface Types


public interface Types

Utility methods for operating on types.

Since:
1.5

Method Summary
 ArrayType getArrayType(TypeMirror componentType)
          Returns an array type with the specified component type.
 DeclaredType getDeclaredType(DeclaredType containing, TypeDeclaration decl, TypeMirror... typeArgs)
          Returns the type corresponding to a type declaration and actual arguments, given a containing type of which it is a member.
 DeclaredType getDeclaredType(TypeDeclaration decl, TypeMirror... typeArgs)
          Returns the type corresponding to a type declaration and actual type arguments.
 TypeMirror getErasure(TypeMirror t)
          Returns the erasure of a type.
 PrimitiveType getPrimitiveType(PrimitiveType.Kind kind)
          Returns a primitive type.
 TypeVariable getTypeVariable(TypeParameterDeclaration tparam)
          Returns the type variable declared by a type parameter.
 VoidType getVoidType()
          Returns the pseudo-type representing the type of void.
 WildcardType getWildcardType(Collection<ReferenceType> upperBounds, Collection<ReferenceType> lowerBounds)
          Returns a new wildcard.
 boolean isAssignable(TypeMirror t1, TypeMirror t2)
          Tests whether one type is assignable to another.
 boolean isSubtype(TypeMirror t1, TypeMirror t2)
          Tests whether one type is a subtype of the another.
 

Method Detail

isSubtype

boolean isSubtype(TypeMirror t1,
                  TypeMirror t2)
Tests whether one type is a subtype of the another. Any type is considered to be a subtype of itself.

Parameters:
t1 - the first type
t2 - the second type
Returns:
true if and only if the first type is a subtype of the second

isAssignable

boolean isAssignable(TypeMirror t1,
                     TypeMirror t2)
Tests whether one type is assignable to another.

Parameters:
t1 - the first type
t2 - the second type
Returns:
true if and only if the first type is assignable to the second

getErasure

TypeMirror getErasure(TypeMirror t)
Returns the erasure of a type.

Parameters:
t - the type to be erased
Returns:
the erasure of the given type

getPrimitiveType

PrimitiveType getPrimitiveType(PrimitiveType.Kind kind)
Returns a primitive type.

Parameters:
kind - the kind of primitive type to return
Returns:
a primitive type

getVoidType

VoidType getVoidType()
Returns the pseudo-type representing the type of void.

Returns:
the pseudo-type representing the type of void

getArrayType

ArrayType getArrayType(TypeMirror componentType)
Returns an array type with the specified component type.

Parameters:
componentType - the component type
Returns:
an array type with the specified component type.
Throws:
IllegalArgumentException - if the component type is not valid for an array

getTypeVariable

TypeVariable getTypeVariable(TypeParameterDeclaration tparam)
Returns the type variable declared by a type parameter.

Parameters:
tparam - the type parameter
Returns:
the type variable declared by the type parameter

getWildcardType

WildcardType getWildcardType(Collection<ReferenceType> upperBounds,
                             Collection<ReferenceType> lowerBounds)
Returns a new wildcard. Either the wildcards's upper bounds or lower bounds may be specified, or neither, but not both.

Parameters:
upperBounds - the upper bounds of this wildcard, or an empty collection if none
lowerBounds - the lower bounds of this wildcard, or an empty collection if none
Returns:
a new wildcard
Throws:
IllegalArgumentException - if bounds are not valid

getDeclaredType

DeclaredType getDeclaredType(TypeDeclaration decl,
                             TypeMirror... typeArgs)
Returns the type corresponding to a type declaration and actual type arguments. Given the declaration for String, for example, this method may be used to get the String type. It may then be invoked a second time, with the declaration for Set, to make the parameterized type Set<String>.

The number of type arguments must either equal the number of the declaration's formal type parameters, or must be zero. If zero, and if the declaration is generic, then the declaration's raw type is returned.

If a parameterized type is being returned, its declaration 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, TypeDeclaration, TypeMirror...).

Parameters:
decl - the type declaration
typeArgs - the actual type arguments
Returns:
the type corresponding to the type declaration and actual type arguments
Throws:
IllegalArgumentException - if too many or too few type arguments are given, or if an inappropriate type argument or declaration is provided

getDeclaredType

DeclaredType getDeclaredType(DeclaredType containing,
                             TypeDeclaration decl,
                             TypeMirror... typeArgs)
Returns the type corresponding to a type declaration and actual arguments, given a containing type of which it is a member. The parameterized type Outer<String>.Inner<Number>, for example, may be constructed by first using getDeclaredType(TypeDeclaration, 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 the declaration's formal type parameters. If it is not parameterized or if it is null, this method is equivalent to getDeclaredType(decl, typeArgs).

Parameters:
containing - the containing type, or null if none
decl - the type declaration
typeArgs - the actual type arguments
Returns:
the type corresponding to the type declaration 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, declaration, or containing type is provided

Mirror API

Submit a bug or feature
Copyright © 2004, 2011, Oracle and/or its affiliates. All rights reserved.