summaryrefslogtreecommitdiff
path: root/javax/lang/model/util/Types.java
diff options
context:
space:
mode:
Diffstat (limited to 'javax/lang/model/util/Types.java')
-rw-r--r--javax/lang/model/util/Types.java166
1 files changed, 166 insertions, 0 deletions
diff --git a/javax/lang/model/util/Types.java b/javax/lang/model/util/Types.java
index 18eb58098..b05008c77 100644
--- a/javax/lang/model/util/Types.java
+++ b/javax/lang/model/util/Types.java
@@ -37,6 +37,14 @@ exception statement from your version. */
package javax.lang.model.util;
+import java.util.List;
+
+import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
+
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeMirror;
+
/**
* Utility methods for operating on types.
*
@@ -45,4 +53,162 @@ package javax.lang.model.util;
*/
public interface Types
{
+
+ /**
+ * Returns the element corresponding to this type
+ * or {@code null} if no such element exists.
+ * The type may be a {@link javax.lang.model.type.DeclaredType}
+ * or a {@link javax.lang.model.type.TypeVariable}.
+ *
+ * @param type the type to return the corresponding element to.
+ * @return the element corresponding to this type.
+ */
+ Element asElement(TypeMirror type);
+
+ /**
+ * Returns a view of an element when seen as a member of,
+ * or otherwise contained by, the specified type. For
+ * example, the method {@code Set.add(E)} becomes
+ * {@code Set.add(String)} when viewed as a member of
+ * the parameterised type {@code Set<String>}.
+ *
+ * @param container the type containing the element.
+ * @param element the element being contained.
+ * @return the type of the element viewed from the container.
+ * @throws IllegalArgumentException if the element is not applicable
+ * for the specified container.
+ */
+ TypeMirror asMemberOf(DeclaredType container, Element element);
+
+ /**
+ * Applies capture conversion to the type, as specified
+ * in section 5.1.10 of the Java Language Specification.
+ *
+ * @param type the type to capture convert.
+ * @return the result of applying capture conversion.
+ * @throws IllegalArgumentException if given an executable or package type.
+ */
+ TypeMirror capture(TypeMirror type);
+
+ /**
+ * Returns {@code true} if {@code type1} contains {@code type2}.
+ *
+ * @param type1 the first type.
+ * @param type2 the second type.
+ * @return true if type1 contains type2.
+ * @throws IllegalArgumentException if given an executable or package type.
+ */
+ boolean contains(TypeMirror type1, TypeMirror type2);
+
+ /**
+ * Returns the direct supertypes of the specified type. The superclass
+ * appears first, if any, followed by the interfaces, if any.
+ *
+ * @param type the type to examine.
+ * @return the direct supertypes or an empty list if there are none.
+ * @throws IllegalArgumentException if given an executable or package type.
+ */
+ List<? extends TypeMirror> directSupertypes(TypeMirror type);
+
+ /**
+ * Returns the erasure of the type, as specified by section
+ * 4.6 of the Java Language Specification.
+ *
+ * @param type the type to erase.
+ * @return the type erasure.
+ * @throws IllegalArgumentException if given a package type.
+ */
+ TypeMirror erasure(TypeMirror type);
+
+ /**
+ * <p>Returns the type corresponding to a type element and actual
+ * type arguments, given the specified containing type of which
+ * it is a member. This method is needed to retrieve types
+ * contained by parameterised types, for example
+ * {@code Outer<String>.Inner<Integer>}. To obtain this type,
+ * this method should be supplied with the {@link DeclaredType}
+ * for {@code Outer<String>} (probably obtained by a call
+ * to {@link #getDeclaredType(TypeElement, TypeMirror...)}),
+ * the element representing {@code Inner} and the
+ * {@link TypeMirror} for {@code String}</p>.
+ * <p>If the container is parameterised, the number of type
+ * arguments must equal the number of formal type parameters
+ * used in the specified element. Calls where the container
+ * is not parameterised, or is {@code null}, are equivalent
+ * to calls to {@link #getDeclaredType(TypeElement, TypeMirror...)}.
+ *
+ * @param container the type containing the returned type,
+ * or {@code null} if there is none.
+ * @param element the type element to return the realised type for.
+ * @param args the actual type arguments to match to the element's
+ * formal parameters.
+ * @return the type corresponding to the specified element using
+ * the specified type arguments.
+ * @throws IllegalArgumentException if the number of type arguments
+ * doesn't match the number of type
+ * parameters, or an inappropriate
+ * container, type element or argument
+ * is given.
+ */
+ DeclaredType getDeclaredType(DeclaredType container, TypeElement element,
+ TypeMirror... args);
+
+ /**
+ * Returns the type corresponding to a type element and actual
+ * type arguments. So, for the type element for {@code Set<T>},
+ * and the type mirror for {@code String}, this method would
+ * return the declared type for {@code Set<String>}. The number
+ * of type arguments must either match the number of formal
+ * type parameters in the element, or be zero in order to obtain
+ * the raw type ({@code Set} in the above). The type element
+ * must not be contained within a generic outer class; for that,
+ * use {@link #getDeclaredType(DeclaredType,TypeElement,TypeMirror...)}.
+ *
+ * @param element the type element to return the realised type for.
+ * @param args the actual type arguments to match to the element's
+ * formal parameters.
+ * @return the type corresponding to the specified element using
+ * the specified type arguments.
+ * @throws IllegalArgumentException if the number of type arguments
+ * doesn't match the number of type
+ * parameters, or an inappropriate
+ * type element or argument is given.
+ */
+ DeclaredType getDeclaredType(TypeElement element, TypeMirror... args);
+
+ /**
+ * Returns {@code true} if {@code type1} may be assigned to {@code type2},
+ * according to section 5.2 of the Java Language Specification.
+ *
+ * @param type1 the first type.
+ * @param type2 the second type.
+ * @return true if type1 can be assigned to type2.
+ * @throws IllegalArgumentException if given an executable or package type.
+ */
+ boolean isAssignable(TypeMirror type1, TypeMirror type2);
+
+ /**
+ * Returns {@code true} if the two types are the same. Note that
+ * wildcard types are never the same as any other type, including
+ * themselves. This rule prevents wildcard types being used as
+ * method arguments.
+ *
+ * @param type1 the first type.
+ * @param type2 the second type.
+ * @return true iff the two types are the same.
+ */
+ boolean isSameType(TypeMirror type1, TypeMirror type2);
+
+ /**
+ * Returns {@code true} if {@code type1} is a subtype of {@code type2},
+ * according to section 4.10 of the Java Language Specification. A
+ * type is always considered a subtype of itself.
+ *
+ * @param type1 the first type.
+ * @param type2 the second type.
+ * @return true if type1 is a subtype of type2.
+ * @throws IllegalArgumentException if given an executable or package type.
+ */
+ boolean isSubtype(TypeMirror type1, TypeMirror type2);
+
}