0N/A/*
850N/A * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
553N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
553N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/Apackage javax.lang.model.util;
0N/A
0N/Aimport java.util.List;
0N/Aimport javax.lang.model.element.*;
0N/Aimport javax.lang.model.type.*;
0N/A
0N/A/**
0N/A * Utility methods for operating on types.
0N/A *
0N/A * <p><b>Compatibility Note:</b> Methods may be added to this interface
0N/A * in future releases of the platform.
0N/A *
0N/A * @author Joseph D. Darcy
0N/A * @author Scott Seligman
0N/A * @author Peter von der Ah&eacute;
0N/A * @see javax.annotation.processing.ProcessingEnvironment#getTypeUtils
0N/A * @since 1.6
0N/A */
0N/Apublic interface Types {
0N/A
0N/A /**
0N/A * Returns the element corresponding to a type.
0N/A * The type may be a {@code DeclaredType} or {@code TypeVariable}.
0N/A * Returns {@code null} if the type is not one with a
0N/A * corresponding element.
0N/A *
0N/A * @return the element corresponding to the given type
0N/A */
0N/A Element asElement(TypeMirror t);
0N/A
0N/A /**
0N/A * Tests whether two {@code TypeMirror} objects represent the same type.
0N/A *
0N/A * <p>Caveat: if either of the arguments to this method represents a
0N/A * wildcard, this method will return false. As a consequence, a wildcard
0N/A * is not the same type as itself. This might be surprising at first,
0N/A * but makes sense once you consider that an example like this must be
0N/A * rejected by the compiler:
0N/A * <pre>
0N/A * {@code List<?> list = new ArrayList<Object>();}
0N/A * {@code list.add(list.get(0));}
0N/A * </pre>
0N/A *
0N/A * @param t1 the first type
0N/A * @param t2 the second type
0N/A * @return {@code true} if and only if the two types are the same
0N/A */
0N/A boolean isSameType(TypeMirror t1, TypeMirror t2);
0N/A
0N/A /**
0N/A * Tests whether one type is a subtype of another.
0N/A * Any type is considered to be a subtype of itself.
0N/A *
0N/A * @param t1 the first type
0N/A * @param t2 the second type
0N/A * @return {@code true} if and only if the first type is a subtype
0N/A * of the second
0N/A * @throws IllegalArgumentException if given an executable or package type
971N/A * @jls 4.10 Subtyping
0N/A */
0N/A boolean isSubtype(TypeMirror t1, TypeMirror t2);
0N/A
0N/A /**
0N/A * Tests whether one type is assignable to another.
0N/A *
0N/A * @param t1 the first type
0N/A * @param t2 the second type
0N/A * @return {@code true} if and only if the first type is assignable
0N/A * to the second
0N/A * @throws IllegalArgumentException if given an executable or package type
971N/A * @jls 5.2 Assignment Conversion
0N/A */
0N/A boolean isAssignable(TypeMirror t1, TypeMirror t2);
0N/A
0N/A /**
0N/A * Tests whether one type argument <i>contains</i> another.
0N/A *
0N/A * @param t1 the first type
0N/A * @param t2 the second type
0N/A * @return {@code true} if and only if the first type contains the second
0N/A * @throws IllegalArgumentException if given an executable or package type
971N/A * @jls 4.5.1.1 Type Argument Containment and Equivalence
0N/A */
0N/A boolean contains(TypeMirror t1, TypeMirror t2);
0N/A
0N/A /**
0N/A * Tests whether the signature of one method is a <i>subsignature</i>
0N/A * of another.
0N/A *
0N/A * @param m1 the first method
0N/A * @param m2 the second method
0N/A * @return {@code true} if and only if the first signature is a
0N/A * subsignature of the second
971N/A * @jls 8.4.2 Method Signature
0N/A */
0N/A boolean isSubsignature(ExecutableType m1, ExecutableType m2);
0N/A
0N/A /**
0N/A * Returns the direct supertypes of a type. The interface types, if any,
0N/A * will appear last in the list.
0N/A *
0N/A * @param t the type being examined
0N/A * @return the direct supertypes, or an empty list if none
0N/A * @throws IllegalArgumentException if given an executable or package type
0N/A */
0N/A List<? extends TypeMirror> directSupertypes(TypeMirror t);
0N/A
0N/A /**
0N/A * Returns the erasure of a type.
0N/A *
0N/A * @param t the type to be erased
0N/A * @return the erasure of the given type
0N/A * @throws IllegalArgumentException if given a package type
971N/A * @jls 4.6 Type Erasure
0N/A */
0N/A TypeMirror erasure(TypeMirror t);
0N/A
0N/A /**
0N/A * Returns the class of a boxed value of a given primitive type.
0N/A * That is, <i>boxing conversion</i> is applied.
0N/A *
0N/A * @param p the primitive type to be converted
0N/A * @return the class of a boxed value of type {@code p}
971N/A * @jls 5.1.7 Boxing Conversion
0N/A */
0N/A TypeElement boxedClass(PrimitiveType p);
0N/A
0N/A /**
0N/A * Returns the type (a primitive type) of unboxed values of a given type.
0N/A * That is, <i>unboxing conversion</i> is applied.
0N/A *
0N/A * @param t the type to be unboxed
0N/A * @return the type of an unboxed value of type {@code t}
0N/A * @throws IllegalArgumentException if the given type has no
0N/A * unboxing conversion
971N/A * @jls 5.1.8 Unboxing Conversion
0N/A */
0N/A PrimitiveType unboxedType(TypeMirror t);
0N/A
0N/A /**
0N/A * Applies capture conversion to a type.
0N/A *
0N/A * @param t the type to be converted
0N/A * @return the result of applying capture conversion
0N/A * @throws IllegalArgumentException if given an executable or package type
971N/A * @jls 5.1.10 Capture Conversion
0N/A */
0N/A TypeMirror capture(TypeMirror t);
0N/A
0N/A /**
0N/A * Returns a primitive type.
0N/A *
0N/A * @param kind the kind of primitive type to return
0N/A * @return a primitive type
0N/A * @throws IllegalArgumentException if {@code kind} is not a primitive kind
0N/A */
0N/A PrimitiveType getPrimitiveType(TypeKind kind);
0N/A
0N/A /**
0N/A * Returns the null type. This is the type of {@code null}.
0N/A *
0N/A * @return the null type
0N/A */
0N/A NullType getNullType();
0N/A
0N/A /**
0N/A * Returns a pseudo-type used where no actual type is appropriate.
0N/A * The kind of type to return may be either
0N/A * {@link TypeKind#VOID VOID} or {@link TypeKind#NONE NONE}.
0N/A * For packages, use
0N/A * {@link Elements#getPackageElement(CharSequence)}{@code .asType()}
0N/A * instead.
0N/A *
0N/A * @param kind the kind of type to return
0N/A * @return a pseudo-type of kind {@code VOID} or {@code NONE}
0N/A * @throws IllegalArgumentException if {@code kind} is not valid
0N/A */
0N/A NoType getNoType(TypeKind kind);
0N/A
0N/A /**
0N/A * Returns an array type with the specified component type.
0N/A *
0N/A * @param componentType the component type
0N/A * @return an array type with the specified component type.
0N/A * @throws IllegalArgumentException if the component type is not valid for
0N/A * an array
0N/A */
0N/A ArrayType getArrayType(TypeMirror componentType);
0N/A
0N/A /**
0N/A * Returns a new wildcard type argument. Either of the wildcard's
0N/A * bounds may be specified, or neither, but not both.
0N/A *
0N/A * @param extendsBound the extends (upper) bound, or {@code null} if none
0N/A * @param superBound the super (lower) bound, or {@code null} if none
0N/A * @return a new wildcard
0N/A * @throws IllegalArgumentException if bounds are not valid
0N/A */
0N/A WildcardType getWildcardType(TypeMirror extendsBound,
0N/A TypeMirror superBound);
0N/A
0N/A /**
0N/A * Returns the type corresponding to a type element and
0N/A * actual type arguments.
0N/A * Given the type element for {@code Set} and the type mirror
0N/A * for {@code String},
0N/A * for example, this method may be used to get the
0N/A * parameterized type {@code Set<String>}.
0N/A *
0N/A * <p> The number of type arguments must either equal the
0N/A * number of the type element's formal type parameters, or must be
0N/A * zero. If zero, and if the type element is generic,
0N/A * then the type element's raw type is returned.
0N/A *
0N/A * <p> If a parameterized type is being returned, its type element
0N/A * must not be contained within a generic outer class.
0N/A * The parameterized type {@code Outer<String>.Inner<Number>},
0N/A * for example, may be constructed by first using this
0N/A * method to get the type {@code Outer<String>}, and then invoking
0N/A * {@link #getDeclaredType(DeclaredType, TypeElement, TypeMirror...)}.
0N/A *
0N/A * @param typeElem the type element
0N/A * @param typeArgs the actual type arguments
0N/A * @return the type corresponding to the type element and
0N/A * actual type arguments
0N/A * @throws IllegalArgumentException if too many or too few
0N/A * type arguments are given, or if an inappropriate type
0N/A * argument or type element is provided
0N/A */
0N/A DeclaredType getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs);
0N/A
0N/A /**
0N/A * Returns the type corresponding to a type element
0N/A * and actual type arguments, given a
0N/A * {@linkplain DeclaredType#getEnclosingType() containing type}
0N/A * of which it is a member.
0N/A * The parameterized type {@code Outer<String>.Inner<Number>},
0N/A * for example, may be constructed by first using
0N/A * {@link #getDeclaredType(TypeElement, TypeMirror...)}
0N/A * to get the type {@code Outer<String>}, and then invoking
0N/A * this method.
0N/A *
0N/A * <p> If the containing type is a parameterized type,
0N/A * the number of type arguments must equal the
0N/A * number of {@code typeElem}'s formal type parameters.
0N/A * If it is not parameterized or if it is {@code null}, this method is
0N/A * equivalent to {@code getDeclaredType(typeElem, typeArgs)}.
0N/A *
0N/A * @param containing the containing type, or {@code null} if none
0N/A * @param typeElem the type element
0N/A * @param typeArgs the actual type arguments
0N/A * @return the type corresponding to the type element and
0N/A * actual type arguments, contained within the given type
0N/A * @throws IllegalArgumentException if too many or too few
0N/A * type arguments are given, or if an inappropriate type
0N/A * argument, type element, or containing type is provided
0N/A */
0N/A DeclaredType getDeclaredType(DeclaredType containing,
0N/A TypeElement typeElem, TypeMirror... typeArgs);
0N/A
0N/A /**
0N/A * Returns the type of an element when that element is viewed as
0N/A * a member of, or otherwise directly contained by, a given type.
0N/A * For example,
0N/A * when viewed as a member of the parameterized type {@code Set<String>},
0N/A * the {@code Set.add} method is an {@code ExecutableType}
0N/A * whose parameter is of type {@code String}.
0N/A *
0N/A * @param containing the containing type
0N/A * @param element the element
0N/A * @return the type of the element as viewed from the containing type
0N/A * @throws IllegalArgumentException if the element is not a valid one
0N/A * for the given type
0N/A */
0N/A TypeMirror asMemberOf(DeclaredType containing, Element element);
0N/A}