Interface Types


public interface Types
Utility methods for operating on types.
Since:
1.5
Version:
1.3 04/06/07
Author:
Joseph D. Darcy, Scott Seligman
  • Method Details

    • 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