|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.tools.javac.model.JavacTypes
public class JavacTypes
Utility methods for operating on types.
This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.
| Field Summary | |
|---|---|
private static java.util.Set<TypeKind> |
EXEC_OR_PKG
|
private static Context.Key<JavacTypes> |
KEY
|
private Symtab |
syms
|
private Types |
types
|
| Constructor Summary | |
|---|---|
JavacTypes(Context context)
Public for use only by JavacProcessingEnvironment |
|
| Method Summary | ||
|---|---|---|
Element |
asElement(TypeMirror t)
Returns the element corresponding to a type. |
|
TypeMirror |
asMemberOf(DeclaredType containing,
Element element)
Returns the type of an element when that element is viewed as a member of, or otherwise directly contained by, a given type. |
|
TypeElement |
boxedClass(PrimitiveType p)
Returns the class of a boxed value of a given primitive type. |
|
TypeMirror |
capture(TypeMirror t)
Applies capture conversion to a type. |
|
private static
|
cast(java.lang.Class<T> clazz,
java.lang.Object o)
Returns an object cast to the specified type. |
|
boolean |
contains(TypeMirror t1,
TypeMirror t2)
Tests whether one type argument contains another. |
|
java.util.List<Type> |
directSupertypes(TypeMirror t)
Returns the direct supertypes of a type. |
|
TypeMirror |
erasure(TypeMirror t)
Returns the erasure of a type. |
|
ArrayType |
getArrayType(TypeMirror componentType)
Returns an array type with the specified component type. |
|
DeclaredType |
getDeclaredType(DeclaredType enclosing,
TypeElement typeElem,
TypeMirror... typeArgs)
Returns the type corresponding to a type element and actual type arguments, given a containing type of which it is a member. |
|
DeclaredType |
getDeclaredType(TypeElement typeElem,
TypeMirror... typeArgs)
Returns the type corresponding to a type element and actual type arguments. |
|
private DeclaredType |
getDeclaredType0(Type outer,
Symbol.ClassSymbol sym,
TypeMirror... typeArgs)
|
|
NoType |
getNoType(TypeKind kind)
Returns a pseudo-type used where no actual type is appropriate. |
|
NullType |
getNullType()
Returns the null type. |
|
PrimitiveType |
getPrimitiveType(TypeKind kind)
Returns a primitive type. |
|
WildcardType |
getWildcardType(TypeMirror extendsBound,
TypeMirror superBound)
Returns a new wildcard type argument. |
|
static JavacTypes |
instance(Context context)
|
|
boolean |
isAssignable(TypeMirror t1,
TypeMirror t2)
Tests whether one type is assignable to another. |
|
boolean |
isSameType(TypeMirror t1,
TypeMirror t2)
Tests whether two TypeMirror objects represent the same type. |
|
boolean |
isSubsignature(ExecutableType m1,
ExecutableType m2)
Tests whether the signature of one method is a subsignature of another. |
|
boolean |
isSubtype(TypeMirror t1,
TypeMirror t2)
Tests whether one type is a subtype of another. |
|
void |
setContext(Context context)
Use a new context. |
|
PrimitiveType |
unboxedType(TypeMirror t)
Returns the type (a primitive type) of unboxed values of a given type. |
|
private void |
validateTypeNotIn(TypeMirror t,
java.util.Set<TypeKind> invalidKinds)
Throws an IllegalArgumentException if a type's kind is one of a set. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private Symtab syms
private Types types
private static final Context.Key<JavacTypes> KEY
private static final java.util.Set<TypeKind> EXEC_OR_PKG
| Constructor Detail |
|---|
public JavacTypes(Context context)
| Method Detail |
|---|
public static JavacTypes instance(Context context)
public void setContext(Context context)
public Element asElement(TypeMirror t)
TypesDeclaredType or TypeVariable.
Returns null if the type is not one with a
corresponding element.
asElement in interface Types
public boolean isSameType(TypeMirror t1,
TypeMirror t2)
TypesTypeMirror objects represent the same type.
Caveat: if either of the arguments to this method represents a wildcard, this method will return false. As a consequence, a wildcard is not the same type as itself. This might be surprising at first, but makes sense once you consider that an example like this must be rejected by the compiler:
List<?> list = new ArrayList<Object>();list.add(list.get(0));
isSameType in interface Typest1 - the first typet2 - the second type
true if and only if the two types are the same
public boolean isSubtype(TypeMirror t1,
TypeMirror t2)
Types
isSubtype in interface Typest1 - the first typet2 - the second type
true if and only if the first type is a subtype
of the second
public boolean isAssignable(TypeMirror t1,
TypeMirror t2)
Types
isAssignable in interface Typest1 - the first typet2 - the second type
true if and only if the first type is assignable
to the second
public boolean contains(TypeMirror t1,
TypeMirror t2)
Types
contains in interface Typest1 - the first typet2 - the second type
true if and only if the first type contains the second
public boolean isSubsignature(ExecutableType m1,
ExecutableType m2)
Types
isSubsignature in interface Typesm1 - the first methodm2 - the second method
true if and only if the first signature is a
subsignature of the secondpublic java.util.List<Type> directSupertypes(TypeMirror t)
Types
directSupertypes in interface Typest - the type being examined
public TypeMirror erasure(TypeMirror t)
Types
erasure in interface Typest - the type to be erased
public TypeElement boxedClass(PrimitiveType p)
Types
boxedClass in interface Typesp - the primitive type to be converted
ppublic PrimitiveType unboxedType(TypeMirror t)
Types
unboxedType in interface Typest - the type to be unboxed
tpublic TypeMirror capture(TypeMirror t)
Types
capture in interface Typest - the type to be converted
public PrimitiveType getPrimitiveType(TypeKind kind)
Types
getPrimitiveType in interface Typeskind - the kind of primitive type to return
public NullType getNullType()
Typesnull.
getNullType in interface Typespublic NoType getNoType(TypeKind kind)
TypesVOID or NONE.
For packages, use
Elements.getPackageElement(CharSequence).asType()
instead.
getNoType in interface Typeskind - the kind of type to return
VOID or NONEpublic ArrayType getArrayType(TypeMirror componentType)
Types
getArrayType in interface TypescomponentType - the component type
public WildcardType getWildcardType(TypeMirror extendsBound,
TypeMirror superBound)
Types
getWildcardType in interface TypesextendsBound - the extends (upper) bound, or null if nonesuperBound - the super (lower) bound, or null if none
public DeclaredType getDeclaredType(TypeElement typeElem,
TypeMirror... typeArgs)
TypesSet and the type mirror
for String,
for example, this method may be used to get the
parameterized type Set<String>.
The number of type arguments must either equal the number of the type element's formal type parameters, or must be zero. If zero, and if the type element is generic, then the type element's raw type is returned.
If a parameterized type is being returned, its type element
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
Types.getDeclaredType(DeclaredType, TypeElement, TypeMirror...).
getDeclaredType in interface TypestypeElem - the type elementtypeArgs - the actual type arguments
public DeclaredType getDeclaredType(DeclaredType enclosing,
TypeElement typeElem,
TypeMirror... typeArgs)
TypesOuter<String>.Inner<Number>,
for example, may be constructed by first using
Types.getDeclaredType(TypeElement, 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 typeElem's formal type parameters.
If it is not parameterized or if it is null, this method is
equivalent to getDeclaredType(typeElem, typeArgs).
getDeclaredType in interface Typesenclosing - the containing type, or null if nonetypeElem - the type elementtypeArgs - the actual type arguments
private DeclaredType getDeclaredType0(Type outer,
Symbol.ClassSymbol sym,
TypeMirror... typeArgs)
public TypeMirror asMemberOf(DeclaredType containing,
Element element)
Set<String>,
the Set.add method is an ExecutableType
whose parameter is of type String.
asMemberOf in interface Typescontaining - the containing typeelement - the element
java.lang.IllegalArgumentException - if the element is not a valid one
for the given type
private void validateTypeNotIn(TypeMirror t,
java.util.Set<TypeKind> invalidKinds)
private static <T> T cast(java.lang.Class<T> clazz,
java.lang.Object o)
java.lang.NullPointerException - if the object is null
java.lang.IllegalArgumentException - if the object is of the wrong type
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||