src/share/classes/javax/lang/model/util/Types.java

Sun, 05 May 2013 21:04:41 -0700

author
darcy
date
Sun, 05 May 2013 21:04:41 -0700
changeset 1725
e8987ce7fb4b
parent 1645
97f6839673d6
child 2223
6d1f9d1fd585
permissions
-rw-r--r--

8013909: Fix doclint issues in javax.lang.model
Reviewed-by: jjg

duke@1 1 /*
jjg@1521 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package javax.lang.model.util;
duke@1 27
jjg@1521 28 import java.lang.annotation.Annotation;
jjg@1521 29 import java.lang.annotation.AnnotationTypeMismatchException;
jjg@1521 30 import java.lang.annotation.IncompleteAnnotationException;
duke@1 31 import java.util.List;
duke@1 32 import javax.lang.model.element.*;
duke@1 33 import javax.lang.model.type.*;
duke@1 34
duke@1 35 /**
duke@1 36 * Utility methods for operating on types.
duke@1 37 *
duke@1 38 * <p><b>Compatibility Note:</b> Methods may be added to this interface
duke@1 39 * in future releases of the platform.
duke@1 40 *
duke@1 41 * @author Joseph D. Darcy
duke@1 42 * @author Scott Seligman
duke@1 43 * @author Peter von der Ah&eacute;
duke@1 44 * @see javax.annotation.processing.ProcessingEnvironment#getTypeUtils
duke@1 45 * @since 1.6
duke@1 46 */
duke@1 47 public interface Types {
duke@1 48
duke@1 49 /**
duke@1 50 * Returns the element corresponding to a type.
duke@1 51 * The type may be a {@code DeclaredType} or {@code TypeVariable}.
duke@1 52 * Returns {@code null} if the type is not one with a
duke@1 53 * corresponding element.
duke@1 54 *
darcy@1725 55 * @param t the type to map to an element
duke@1 56 * @return the element corresponding to the given type
duke@1 57 */
duke@1 58 Element asElement(TypeMirror t);
duke@1 59
duke@1 60 /**
duke@1 61 * Tests whether two {@code TypeMirror} objects represent the same type.
duke@1 62 *
jjg@1645 63 * <p>Since annotations are only meta-data associated with a type,
jjg@1645 64 * the set of annotations on either argument is <em>not</em> taken
jjg@1645 65 * into account when computing whether or not two {@code
jjg@1645 66 * TypeMirror} objects are the same type. In particular, two
jjg@1645 67 * {@code TypeMirror} objects can have different annotations and
jjg@1645 68 * still be considered the same.
jjg@1645 69 *
duke@1 70 * <p>Caveat: if either of the arguments to this method represents a
duke@1 71 * wildcard, this method will return false. As a consequence, a wildcard
duke@1 72 * is not the same type as itself. This might be surprising at first,
duke@1 73 * but makes sense once you consider that an example like this must be
duke@1 74 * rejected by the compiler:
duke@1 75 * <pre>
duke@1 76 * {@code List<?> list = new ArrayList<Object>();}
duke@1 77 * {@code list.add(list.get(0));}
duke@1 78 * </pre>
duke@1 79 *
duke@1 80 * @param t1 the first type
duke@1 81 * @param t2 the second type
duke@1 82 * @return {@code true} if and only if the two types are the same
duke@1 83 */
duke@1 84 boolean isSameType(TypeMirror t1, TypeMirror t2);
duke@1 85
duke@1 86 /**
duke@1 87 * Tests whether one type is a subtype of another.
duke@1 88 * Any type is considered to be a subtype of itself.
duke@1 89 *
duke@1 90 * @param t1 the first type
duke@1 91 * @param t2 the second type
duke@1 92 * @return {@code true} if and only if the first type is a subtype
duke@1 93 * of the second
duke@1 94 * @throws IllegalArgumentException if given an executable or package type
jjh@972 95 * @jls 4.10 Subtyping
duke@1 96 */
duke@1 97 boolean isSubtype(TypeMirror t1, TypeMirror t2);
duke@1 98
duke@1 99 /**
duke@1 100 * Tests whether one type is assignable to another.
duke@1 101 *
duke@1 102 * @param t1 the first type
duke@1 103 * @param t2 the second type
duke@1 104 * @return {@code true} if and only if the first type is assignable
duke@1 105 * to the second
duke@1 106 * @throws IllegalArgumentException if given an executable or package type
jjh@972 107 * @jls 5.2 Assignment Conversion
duke@1 108 */
duke@1 109 boolean isAssignable(TypeMirror t1, TypeMirror t2);
duke@1 110
duke@1 111 /**
duke@1 112 * Tests whether one type argument <i>contains</i> another.
duke@1 113 *
duke@1 114 * @param t1 the first type
duke@1 115 * @param t2 the second type
duke@1 116 * @return {@code true} if and only if the first type contains the second
duke@1 117 * @throws IllegalArgumentException if given an executable or package type
jjh@972 118 * @jls 4.5.1.1 Type Argument Containment and Equivalence
duke@1 119 */
duke@1 120 boolean contains(TypeMirror t1, TypeMirror t2);
duke@1 121
duke@1 122 /**
duke@1 123 * Tests whether the signature of one method is a <i>subsignature</i>
duke@1 124 * of another.
duke@1 125 *
duke@1 126 * @param m1 the first method
duke@1 127 * @param m2 the second method
duke@1 128 * @return {@code true} if and only if the first signature is a
duke@1 129 * subsignature of the second
jjh@972 130 * @jls 8.4.2 Method Signature
duke@1 131 */
duke@1 132 boolean isSubsignature(ExecutableType m1, ExecutableType m2);
duke@1 133
duke@1 134 /**
duke@1 135 * Returns the direct supertypes of a type. The interface types, if any,
duke@1 136 * will appear last in the list.
duke@1 137 *
duke@1 138 * @param t the type being examined
duke@1 139 * @return the direct supertypes, or an empty list if none
duke@1 140 * @throws IllegalArgumentException if given an executable or package type
duke@1 141 */
duke@1 142 List<? extends TypeMirror> directSupertypes(TypeMirror t);
duke@1 143
duke@1 144 /**
duke@1 145 * Returns the erasure of a type.
duke@1 146 *
duke@1 147 * @param t the type to be erased
duke@1 148 * @return the erasure of the given type
duke@1 149 * @throws IllegalArgumentException if given a package type
jjh@972 150 * @jls 4.6 Type Erasure
duke@1 151 */
duke@1 152 TypeMirror erasure(TypeMirror t);
duke@1 153
duke@1 154 /**
duke@1 155 * Returns the class of a boxed value of a given primitive type.
duke@1 156 * That is, <i>boxing conversion</i> is applied.
duke@1 157 *
duke@1 158 * @param p the primitive type to be converted
duke@1 159 * @return the class of a boxed value of type {@code p}
jjh@972 160 * @jls 5.1.7 Boxing Conversion
duke@1 161 */
duke@1 162 TypeElement boxedClass(PrimitiveType p);
duke@1 163
duke@1 164 /**
duke@1 165 * Returns the type (a primitive type) of unboxed values of a given type.
duke@1 166 * That is, <i>unboxing conversion</i> is applied.
duke@1 167 *
duke@1 168 * @param t the type to be unboxed
duke@1 169 * @return the type of an unboxed value of type {@code t}
duke@1 170 * @throws IllegalArgumentException if the given type has no
duke@1 171 * unboxing conversion
jjh@972 172 * @jls 5.1.8 Unboxing Conversion
duke@1 173 */
duke@1 174 PrimitiveType unboxedType(TypeMirror t);
duke@1 175
duke@1 176 /**
duke@1 177 * Applies capture conversion to a type.
duke@1 178 *
duke@1 179 * @param t the type to be converted
duke@1 180 * @return the result of applying capture conversion
duke@1 181 * @throws IllegalArgumentException if given an executable or package type
jjh@972 182 * @jls 5.1.10 Capture Conversion
duke@1 183 */
duke@1 184 TypeMirror capture(TypeMirror t);
duke@1 185
duke@1 186 /**
duke@1 187 * Returns a primitive type.
duke@1 188 *
duke@1 189 * @param kind the kind of primitive type to return
duke@1 190 * @return a primitive type
duke@1 191 * @throws IllegalArgumentException if {@code kind} is not a primitive kind
duke@1 192 */
duke@1 193 PrimitiveType getPrimitiveType(TypeKind kind);
duke@1 194
duke@1 195 /**
duke@1 196 * Returns the null type. This is the type of {@code null}.
duke@1 197 *
duke@1 198 * @return the null type
duke@1 199 */
duke@1 200 NullType getNullType();
duke@1 201
duke@1 202 /**
duke@1 203 * Returns a pseudo-type used where no actual type is appropriate.
duke@1 204 * The kind of type to return may be either
duke@1 205 * {@link TypeKind#VOID VOID} or {@link TypeKind#NONE NONE}.
duke@1 206 * For packages, use
duke@1 207 * {@link Elements#getPackageElement(CharSequence)}{@code .asType()}
duke@1 208 * instead.
duke@1 209 *
duke@1 210 * @param kind the kind of type to return
duke@1 211 * @return a pseudo-type of kind {@code VOID} or {@code NONE}
duke@1 212 * @throws IllegalArgumentException if {@code kind} is not valid
duke@1 213 */
duke@1 214 NoType getNoType(TypeKind kind);
duke@1 215
duke@1 216 /**
duke@1 217 * Returns an array type with the specified component type.
duke@1 218 *
duke@1 219 * @param componentType the component type
duke@1 220 * @return an array type with the specified component type.
duke@1 221 * @throws IllegalArgumentException if the component type is not valid for
duke@1 222 * an array
duke@1 223 */
duke@1 224 ArrayType getArrayType(TypeMirror componentType);
duke@1 225
duke@1 226 /**
duke@1 227 * Returns a new wildcard type argument. Either of the wildcard's
duke@1 228 * bounds may be specified, or neither, but not both.
duke@1 229 *
duke@1 230 * @param extendsBound the extends (upper) bound, or {@code null} if none
duke@1 231 * @param superBound the super (lower) bound, or {@code null} if none
duke@1 232 * @return a new wildcard
duke@1 233 * @throws IllegalArgumentException if bounds are not valid
duke@1 234 */
duke@1 235 WildcardType getWildcardType(TypeMirror extendsBound,
duke@1 236 TypeMirror superBound);
duke@1 237
duke@1 238 /**
duke@1 239 * Returns the type corresponding to a type element and
duke@1 240 * actual type arguments.
duke@1 241 * Given the type element for {@code Set} and the type mirror
duke@1 242 * for {@code String},
duke@1 243 * for example, this method may be used to get the
duke@1 244 * parameterized type {@code Set<String>}.
duke@1 245 *
duke@1 246 * <p> The number of type arguments must either equal the
duke@1 247 * number of the type element's formal type parameters, or must be
duke@1 248 * zero. If zero, and if the type element is generic,
duke@1 249 * then the type element's raw type is returned.
duke@1 250 *
duke@1 251 * <p> If a parameterized type is being returned, its type element
duke@1 252 * must not be contained within a generic outer class.
duke@1 253 * The parameterized type {@code Outer<String>.Inner<Number>},
duke@1 254 * for example, may be constructed by first using this
duke@1 255 * method to get the type {@code Outer<String>}, and then invoking
duke@1 256 * {@link #getDeclaredType(DeclaredType, TypeElement, TypeMirror...)}.
duke@1 257 *
duke@1 258 * @param typeElem the type element
duke@1 259 * @param typeArgs the actual type arguments
duke@1 260 * @return the type corresponding to the type element and
duke@1 261 * actual type arguments
duke@1 262 * @throws IllegalArgumentException if too many or too few
duke@1 263 * type arguments are given, or if an inappropriate type
duke@1 264 * argument or type element is provided
duke@1 265 */
duke@1 266 DeclaredType getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs);
duke@1 267
duke@1 268 /**
duke@1 269 * Returns the type corresponding to a type element
duke@1 270 * and actual type arguments, given a
duke@1 271 * {@linkplain DeclaredType#getEnclosingType() containing type}
duke@1 272 * of which it is a member.
duke@1 273 * The parameterized type {@code Outer<String>.Inner<Number>},
duke@1 274 * for example, may be constructed by first using
duke@1 275 * {@link #getDeclaredType(TypeElement, TypeMirror...)}
duke@1 276 * to get the type {@code Outer<String>}, and then invoking
duke@1 277 * this method.
duke@1 278 *
duke@1 279 * <p> If the containing type is a parameterized type,
duke@1 280 * the number of type arguments must equal the
duke@1 281 * number of {@code typeElem}'s formal type parameters.
duke@1 282 * If it is not parameterized or if it is {@code null}, this method is
duke@1 283 * equivalent to {@code getDeclaredType(typeElem, typeArgs)}.
duke@1 284 *
duke@1 285 * @param containing the containing type, or {@code null} if none
duke@1 286 * @param typeElem the type element
duke@1 287 * @param typeArgs the actual type arguments
duke@1 288 * @return the type corresponding to the type element and
duke@1 289 * actual type arguments, contained within the given type
duke@1 290 * @throws IllegalArgumentException if too many or too few
duke@1 291 * type arguments are given, or if an inappropriate type
duke@1 292 * argument, type element, or containing type is provided
duke@1 293 */
duke@1 294 DeclaredType getDeclaredType(DeclaredType containing,
duke@1 295 TypeElement typeElem, TypeMirror... typeArgs);
duke@1 296
duke@1 297 /**
duke@1 298 * Returns the type of an element when that element is viewed as
duke@1 299 * a member of, or otherwise directly contained by, a given type.
duke@1 300 * For example,
duke@1 301 * when viewed as a member of the parameterized type {@code Set<String>},
duke@1 302 * the {@code Set.add} method is an {@code ExecutableType}
duke@1 303 * whose parameter is of type {@code String}.
duke@1 304 *
duke@1 305 * @param containing the containing type
duke@1 306 * @param element the element
duke@1 307 * @return the type of the element as viewed from the containing type
duke@1 308 * @throws IllegalArgumentException if the element is not a valid one
duke@1 309 * for the given type
duke@1 310 */
duke@1 311 TypeMirror asMemberOf(DeclaredType containing, Element element);
duke@1 312 }

mercurial