1. /*
  2. * @(#)Types.java 1.3 04/06/07
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.mirror.util;
  8. import java.util.Collection;
  9. import com.sun.mirror.declaration.*;
  10. import com.sun.mirror.type.*;
  11. /**
  12. * Utility methods for operating on types.
  13. *
  14. * @author Joseph D. Darcy
  15. * @author Scott Seligman
  16. * @version 1.3 04/06/07
  17. * @since 1.5
  18. */
  19. public interface Types {
  20. /**
  21. * Tests whether one type is a subtype of the another.
  22. * Any type is considered to be a subtype of itself.
  23. *
  24. * @param t1 the first type
  25. * @param t2 the second type
  26. * @return <tt>true</tt> if and only if the first type is a subtype
  27. * of the second
  28. */
  29. boolean isSubtype(TypeMirror t1, TypeMirror t2);
  30. /**
  31. * Tests whether one type is assignable to another.
  32. *
  33. * @param t1 the first type
  34. * @param t2 the second type
  35. * @return <tt>true</tt> if and only if the first type is assignable
  36. * to the second
  37. */
  38. boolean isAssignable(TypeMirror t1, TypeMirror t2);
  39. /**
  40. * Returns the erasure of a type.
  41. *
  42. * @param t the type to be erased
  43. * @return the erasure of the given type
  44. */
  45. TypeMirror getErasure(TypeMirror t);
  46. /**
  47. * Returns a primitive type.
  48. *
  49. * @param kind the kind of primitive type to return
  50. * @return a primitive type
  51. */
  52. PrimitiveType getPrimitiveType(PrimitiveType.Kind kind);
  53. /**
  54. * Returns the pseudo-type representing the type of <tt>void</tt>.
  55. *
  56. * @return the pseudo-type representing the type of <tt>void</tt>
  57. */
  58. VoidType getVoidType();
  59. /**
  60. * Returns an array type with the specified component type.
  61. *
  62. * @param componentType the component type
  63. * @return an array type with the specified component type.
  64. * @throws IllegalArgumentException if the component type is not valid for
  65. * an array
  66. */
  67. ArrayType getArrayType(TypeMirror componentType);
  68. /**
  69. * Returns the type variable declared by a type parameter.
  70. *
  71. * @param tparam the type parameter
  72. * @return the type variable declared by the type parameter
  73. */
  74. TypeVariable getTypeVariable(TypeParameterDeclaration tparam);
  75. /**
  76. * Returns a new wildcard.
  77. * Either the wildcards's upper bounds or lower bounds may be
  78. * specified, or neither, but not both.
  79. *
  80. * @param upperBounds the upper bounds of this wildcard,
  81. * or an empty collection if none
  82. * @param lowerBounds the lower bounds of this wildcard,
  83. * or an empty collection if none
  84. * @return a new wildcard
  85. * @throws IllegalArgumentException if bounds are not valid
  86. */
  87. WildcardType getWildcardType(Collection<ReferenceType> upperBounds,
  88. Collection<ReferenceType> lowerBounds);
  89. /**
  90. * Returns the type corresponding to a type declaration and
  91. * actual type arguments.
  92. * Given the declaration for <tt>String</tt>, for example, this
  93. * method may be used to get the <tt>String</tt> type. It may
  94. * then be invoked a second time, with the declaration for <tt>Set</tt>,
  95. * to make the parameterized type {@code Set<String>}.
  96. *
  97. * <p> The number of type arguments must either equal the
  98. * number of the declaration's formal type parameters, or must be
  99. * zero. If zero, and if the declaration is generic,
  100. * then the declaration's raw type is returned.
  101. *
  102. * <p> If a parameterized type is being returned, its declaration
  103. * must not be contained within a generic outer class.
  104. * The parameterized type {@code Outer<String>.Inner<Number>},
  105. * for example, may be constructed by first using this
  106. * method to get the type {@code Outer<String>}, and then invoking
  107. * {@link #getDeclaredType(DeclaredType, TypeDeclaration, TypeMirror...)}.
  108. *
  109. * @param decl the type declaration
  110. * @param typeArgs the actual type arguments
  111. * @return the type corresponding to the type declaration and
  112. * actual type arguments
  113. * @throws IllegalArgumentException if too many or too few
  114. * type arguments are given, or if an inappropriate type
  115. * argument or declaration is provided
  116. */
  117. DeclaredType getDeclaredType(TypeDeclaration decl,
  118. TypeMirror... typeArgs);
  119. /**
  120. * Returns the type corresponding to a type declaration
  121. * and actual arguments, given a
  122. * {@linkplain DeclaredType#getContainingType() containing type}
  123. * of which it is a member.
  124. * The parameterized type {@code Outer<String>.Inner<Number>},
  125. * for example, may be constructed by first using
  126. * {@link #getDeclaredType(TypeDeclaration, TypeMirror...)}
  127. * to get the type {@code Outer<String>}, and then invoking
  128. * this method.
  129. *
  130. * <p> If the containing type is a parameterized type,
  131. * the number of type arguments must equal the
  132. * number of the declaration's formal type parameters.
  133. * If it is not parameterized or if it is <tt>null</tt>, this method is
  134. * equivalent to <tt>getDeclaredType(decl, typeArgs)</tt>.
  135. *
  136. * @param containing the containing type, or <tt>null</tt> if none
  137. * @param decl the type declaration
  138. * @param typeArgs the actual type arguments
  139. * @return the type corresponding to the type declaration and
  140. * actual type arguments,
  141. * contained within the given type
  142. * @throws IllegalArgumentException if too many or too few
  143. * type arguments are given, or if an inappropriate type
  144. * argument, declaration, or containing type is provided
  145. */
  146. DeclaredType getDeclaredType(DeclaredType containing,
  147. TypeDeclaration decl,
  148. TypeMirror... typeArgs);
  149. }