Save This Page
Home » openjdk-7 » com.sun.tools » javac » code » [javadoc | source]
com.sun.tools.javac.code
public class: Types [javadoc | source]
java.lang.Object
   com.sun.tools.javac.code.Types
Utility class containing various operations on types.

Unless other names are more illustrative, the following naming conventions should be observed in this file:

t
If the first argument to an operation is a type, it should be named t.
s
Similarly, if the second argument to an operation is a type, it should be named s.
ts
If an operations takes a list of types, the first should be named ts.
ss
A second list of types should be named ss.

This is NOT part of any supported API. 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.
Nested Class Summary:
class  Types.ImplementationCache   
class  Types.MembersClosureCache   
class  Types.TypePair   
class  Types.Adapter   
public static class  Types.AdaptFailure   
class  Types.Rewriter   
class  Types.SingletonType  A wrapper for a type that allows use in sets. 
abstract public static class  Types.DefaultTypeVisitor  A default visitor for types. All visitor methods except visitType are implemented by delegating to visitType. Concrete subclasses must provide an implementation of visitType and can override other methods as needed. 
abstract public static class  Types.DefaultSymbolVisitor  A default visitor for symbols. All visitor methods except visitSymbol are implemented by delegating to visitSymbol. Concrete subclasses must provide an implementation of visitSymbol and can override other methods as needed. 
abstract public static class  Types.SimpleVisitor  A simple visitor for types. This visitor is simple as captured wildcards, for-all types (generic methods), and undetermined type variables (part of inference) are hidden. Captured wildcards are hidden by treating them as type variables and the rest are hidden by visiting their qtypes. 
abstract public static class  Types.TypeRelation  A plain relation on types. That is a 2-ary function on the form Type × Type → Boolean.  
abstract public static class  Types.UnaryVisitor  A convenience visitor for implementing operations that only require one argument (the type itself), that is, unary operations. 
public static class  Types.MapVisitor  A visitor for implementing a mapping from types to types. The default behavior of this class is to implement the identity mapping (mapping a type to itself). This can be overridden in subclasses. 
Field Summary
protected static final  Key<Types> typesKey     
final  Symtab syms     
final  JavacMessages messages     
final  Names names     
final  boolean allowBoxing     
final  boolean allowCovariantReturns     
final  boolean allowObjectToPrimitiveCast     
final  ClassReader reader     
final  Check chk     
 List<Warner> warnStack     
final  Name capturedName     
public  Mapping fromUnknownFun    A mapping that turns all unknown types in this type to fresh unknown variables. 
 Map<Type, Boolean> isDerivedRawCache     
 TypeRelation hasSameArgs_strict     
 TypeRelation hasSameArgs_nonstrict     
 Set<TypePair> mergeCache     
Constructor:
 protected Types(Context context) 
Method from com.sun.tools.javac.code.Types Summary:
adapt,   asEnclosingSuper,   asOuterSuper,   asSub,   asSuper,   boxedClass,   boxedTypeOrType,   capture,   capture,   classBound,   closure,   containedBy,   containsType,   containsType,   containsTypeEquivalent,   covariantReturnType,   createErrorType,   createErrorType,   createErrorType,   createMethodTypeWithParameters,   createMethodTypeWithReturn,   createMethodTypeWithThrown,   dimensions,   disjointType,   disjointTypes,   elemtype,   elemtypeOrType,   erasedSupertypes,   erasure,   erasure,   erasureRecursive,   erasureRecursive,   freshTypeVariables,   getBounds,   getRetention,   glb,   glb,   hasSameArgs,   hasSameArgs,   hasSameBounds,   hashCode,   implementation,   insert,   instance,   interfaces,   intersect,   isArray,   isAssignable,   isAssignable,   isCaptureOf,   isCastable,   isCastable,   isConvertible,   isConvertible,   isDerivedRaw,   isDerivedRaw,   isDerivedRawInternal,   isReifiable,   isSameType,   isSameTypes,   isSameWildcard,   isSubSignature,   isSubSignature,   isSubtype,   isSubtype,   isSubtypeNoCapture,   isSubtypeUnchecked,   isSubtypeUnchecked,   isSubtypeUnchecked,   isSubtypes,   isSubtypesUnchecked,   isSuperType,   isUnbounded,   lowerBound,   lowerBoundArgtypes,   lub,   lub,   makeCompoundType,   makeCompoundType,   makeCompoundType,   memberType,   membersClosure,   newInstances,   notSoftSubtype,   overrideEquivalent,   rank,   resultSubtype,   returnTypeSubstitutable,   returnTypeSubstitutable,   setBounds,   setBounds,   subst,   subst,   substBound,   substBounds,   supertype,   toString,   toString,   toString,   unboxedType,   union,   upperBound
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.sun.tools.javac.code.Types Detail:
 public  void adapt(Type source,
    Type target,
    ListBuffer<Type> from,
    ListBuffer<Type> to) throws AdaptFailure 
    Adapt a type by computing a substitution which maps a source type to a target type.
 public Type asEnclosingSuper(Type t,
    Symbol sym) 
    Return the base type of t or any of its enclosing types that starts with the given symbol. If none exists, return null.
 public Type asOuterSuper(Type t,
    Symbol sym) 
    Return the base type of t or any of its outer types that starts with the given symbol. If none exists, return null.
 public Type asSub(Type t,
    Symbol sym) 
    Return the least specific subtype of t that starts with symbol sym. If none exists, return null. The least specific subtype is determined as follows:

    If there is exactly one parameterized instance of sym that is a subtype of t, that parameterized instance is returned.
    Otherwise, if the plain type or raw type `sym' is a subtype of type t, the type `sym' itself is returned. Otherwise, null is returned.

 public Type asSuper(Type t,
    Symbol sym) 
    Return the (most specific) base type of t that starts with the given symbol. If none exists, return null.
 public ClassSymbol boxedClass(Type t) 
    Return the class that boxes the given primitive.
 public Type boxedTypeOrType(Type t) 
    Return the boxed type if 't' is primitive, otherwise return 't' itself.
 public List<Type> capture(List<Type> ts) 
    Capture conversion as specified by the JLS.
 public Type capture(Type t) 
 public Type classBound(Type t) 
    If the given type is a (possibly selected) type variable, return the bounding class of this type, otherwise return the type itself.
 public List<Type> closure(Type t) 
    Returns the closure of a class or interface type.
 public boolean containedBy(Type t,
    Type s) 
 boolean containsType(List<Type> ts,
    List<Type> ss) 
 public boolean containsType(Type t,
    Type s) 
    Check if t contains s.

    T contains S if:

    {@code L(T) <: L(S) && U(S) <: U(T)}

    This relation is only used by ClassType.isSubtype(), that is,

    {@code C <: C if T contains S.}

    Because of F-bounds, this relation can lead to infinite recursion. Thus we must somehow break that recursion. Notice that containsType() is only called from ClassType.isSubtype(). Since the arguments have already been checked against their bounds, we know:

    {@code U(S) <: U(T) if T is "super" bound (U(T) *is* the bound)}

    {@code L(T) <: L(S) if T is "extends" bound (L(T) is bottom)}

 public boolean containsTypeEquivalent(List<Type> ts,
    List<Type> ss) 
 public boolean covariantReturnType(Type t,
    Type s,
    Warner warner) 
    Is t an appropriate return type in an overrider for a method that returns s?
 public Type createErrorType(Type originalType) 
 public Type createErrorType(ClassSymbol c,
    Type originalType) 
 public Type createErrorType(Name name,
    TypeSymbol container,
    Type originalType) 
 public Type createMethodTypeWithParameters(Type original,
    List<Type> newParams) 
 public Type createMethodTypeWithReturn(Type original,
    Type newReturn) 
 public Type createMethodTypeWithThrown(Type original,
    List<Type> newThrown) 
 public int dimensions(Type t) 
    The number of dimensions of an array type.
 public boolean disjointType(Type t,
    Type s) 
    Two types or wildcards are considered disjoint if it can be proven that no type can be contained in both. It is conservative in that it is allowed to say that two types are not disjoint, even though they actually are. The type C is castable to C exactly if X and Y are not disjoint.
 public boolean disjointTypes(List<Type> ts,
    List<Type> ss) 
 public Type elemtype(Type t) 
    The element type of an array.
 public Type elemtypeOrType(Type t) 
 List<Type> erasedSupertypes(Type t) 
 public Type erasure(Type t) 
    The erasure of t {@code |t|} -- the type that results when all type parameters in t are deleted.
 public List<Type> erasure(List<Type> ts) 
 public Type erasureRecursive(Type t) 
 public List<Type> erasureRecursive(List<Type> ts) 
 public List<Type> freshTypeVariables(List<Type> types) 
 public List<Type> getBounds(TypeVar t) 
    Return list of bounds of the given type variable.
 public RetentionPolicy getRetention(Compound a) 
 public Type glb(List<Type> ts) 
 public Type glb(Type t,
    Type s) 
 public boolean hasSameArgs(Type t,
    Type s) 
    Does t have the same arguments as s? It is assumed that both types are (possibly polymorphic) method types. Monomorphic method types "have the same arguments", if their argument lists are equal. Polymorphic method types "have the same arguments", if they have the same arguments after renaming all type variables of one to corresponding type variables in the other, where correspondence is by position in the type parameter list.
 public boolean hasSameArgs(Type t,
    Type s,
    boolean strict) 
 boolean hasSameBounds(ForAll t,
    ForAll s) 
    Does t have the same bounds for quantified variables as s?
 public static int hashCode(Type t) 
    Compute a hash code on a type.
 public MethodSymbol implementation(MethodSymbol ms,
    TypeSymbol origin,
    boolean checkResult,
    Filter<Symbol> implFilter) 
 public List<Type> insert(List<Type> cl,
    Type t) 
    Insert a type in a closure
 public static Types instance(Context context) 
 public List<Type> interfaces(Type t) 
    Return the interfaces implemented by this class.
 public List<Type> intersect(List<Type> cl1,
    List<Type> cl2) 
    Intersect two closures
 public boolean isArray(Type t) 
 public boolean isAssignable(Type t,
    Type s) 
 public boolean isAssignable(Type t,
    Type s,
    Warner warn) 
    Is t assignable to s?
    Equivalent to subtype except for constant values and raw types.
    (not defined for Method and ForAll types)
 public boolean isCaptureOf(Type s,
    WildcardType t) 
 public boolean isCastable(Type t,
    Type s) 
 public boolean isCastable(Type t,
    Type s,
    Warner warn) 
    Is t is castable to s?
    s is assumed to be an erased type.
    (not defined for Method and ForAll types).
 public boolean isConvertible(Type t,
    Type s) 
    Is t a subtype of or convertiable via boxing/unboxing convertions to s?
 public boolean isConvertible(Type t,
    Type s,
    Warner warn) 
    Is t a subtype of or convertiable via boxing/unboxing convertions to s?
 public boolean isDerivedRaw(Type t) 
 public boolean isDerivedRaw(List<Type> ts) 
 public boolean isDerivedRawInternal(Type t) 
 public boolean isReifiable(Type t) 
 public boolean isSameType(Type t,
    Type s) 
    Is t the same type as s?
 public boolean isSameTypes(List<Type> ts,
    List<Type> ss) 
    Are corresponding elements of the lists the same type? If lists are of different length, return false.
 public boolean isSameWildcard(WildcardType t,
    Type s) 
 public boolean isSubSignature(Type t,
    Type s) 
    Returns true iff the first signature is a sub signature of the other. This is not an equivalence relation.
 public boolean isSubSignature(Type t,
    Type s,
    boolean strict) 
 public final boolean isSubtype(Type t,
    Type s) 
    Is t a subtype of s?
    (not defined for Method and ForAll types)
 public boolean isSubtype(Type t,
    Type s,
    boolean capture) 
 public final boolean isSubtypeNoCapture(Type t,
    Type s) 
 public boolean isSubtypeUnchecked(Type t,
    Type s) 
    Is t an unchecked subtype of s?
 public boolean isSubtypeUnchecked(Type t,
    Type s,
    Warner warn) 
    Is t an unchecked subtype of s?
 public boolean isSubtypeUnchecked(Type t,
    List<Type> ts,
    Warner warn) 
    Is t a subtype of every type in given list `ts'?
    (not defined for Method and ForAll types)
    Allows unchecked conversions.
 public boolean isSubtypes(List<Type> ts,
    List<Type> ss) 
    Are corresponding elements of ts subtypes of ss? If lists are of different length, return false.
 public boolean isSubtypesUnchecked(List<Type> ts,
    List<Type> ss,
    Warner warn) 
    Are corresponding elements of ts subtypes of ss, allowing unchecked conversions? If lists are of different length, return false.
 public boolean isSuperType(Type t,
    Type s) 
    Is t a supertype of s?
 public boolean isUnbounded(Type t) 
    Checks that all the arguments to a class are unbounded wildcards or something else that doesn't make any restrictions on the arguments. If a class isUnbounded, a raw super- or subclass can be cast to it without a warning.
 public Type lowerBound(Type t) 
    The "lvalue conversion".
    The lower bound of most types is the type itself. Wildcards, on the other hand have upper and lower bounds.
 public List<Type> lowerBoundArgtypes(Type t) 
    Returns the lower bounds of the formals of a method.
 public Type lub(List<Type> ts) 
    Return the least upper bound (lub) of set of types. If the lub does not exist return the type of null (bottom).
 public Type lub(Type t1,
    Type t2) 
    Return the least upper bound of pair of types. if the lub does not exist return null.
 public Type makeCompoundType(List<Type> bounds) 
    Same as #makeCompoundType(List,Type) , except that the second parameter is computed directly. Note that this might cause a symbol completion. Hence, this version of makeCompoundType may not be called during a classfile read.
 public Type makeCompoundType(List<Type> bounds,
    Type supertype) 
    Make a compound type from non-empty list of types
 public Type makeCompoundType(Type bound1,
    Type bound2) 
    A convenience wrapper for #makeCompoundType(List) ; the arguments are converted to a list and passed to the other method. Note that this might cause a symbol completion. Hence, this version of makeCompoundType may not be called during a classfile read.
 public Type memberType(Type t,
    Symbol sym) 
    The type of given symbol, seen as a member of t.
 public CompoundScope membersClosure(Type site,
    boolean skipInterface) 
 public List<Type> newInstances(List<Type> tvars) 
    Create new vector of type variables from list of variables changing all recursive bounds from old to new list.
 public boolean notSoftSubtype(Type t,
    Type s) 
    This relation answers the question: is impossible that something of type `t' can be a subtype of `s'? This is different from the question "is `t' not a subtype of `s'?" when type variables are involved: Integer is not a subtype of T where but it is not true that Integer cannot possibly be a subtype of T.
 public boolean overrideEquivalent(Type t,
    Type s) 
    Returns true iff these signatures are related by override equivalence. This is the natural extension of isSubSignature to an equivalence relation.
 public int rank(Type t) 
    The rank of a class is the length of the longest path between the class and java.lang.Object in the class inheritance graph. Undefined for all but reference types.
 public boolean resultSubtype(Type t,
    Type s,
    Warner warner) 
    Does t have a result that is a subtype of the result type of s, suitable for covariant returns? It is assumed that both types are (possibly polymorphic) method types. Monomorphic method types are handled in the obvious way. Polymorphic method types require renaming all type variables of one to corresponding type variables in the other, where correspondence is by position in the type parameter list.
 public boolean returnTypeSubstitutable(Type r1,
    Type r2) 
    Return-Type-Substitutable.
 public boolean returnTypeSubstitutable(Type r1,
    Type r2,
    Type r2res,
    Warner warner) 
 public  void setBounds(TypeVar t,
    List<Type> bounds) 
    Same as #setBounds(Type.TypeVar,List,Type) , except that third parameter is computed directly, as follows: if all all bounds are interface types, the computed supertype is Object, otherwise the supertype is simply left null (in this case, the supertype is assumed to be the head of the bound list passed as second argument). Note that this check might cause a symbol completion. Hence, this version of setBounds may not be called during a classfile read.
 public  void setBounds(TypeVar t,
    List<Type> bounds,
    Type supertype) 
    Set the bounds field of the given type variable to reflect a (possibly multiple) list of bounds.
 public List<Type> subst(List<Type> ts,
    List<Type> from,
    List<Type> to) 
 public Type subst(Type t,
    List<Type> from,
    List<Type> to) 
    Substitute all occurrences of a type in `from' with the corresponding type in `to' in 't'. Match lists `from' and `to' from the right: If lists have different length, discard leading elements of the longer list.
 public TypeVar substBound(TypeVar t,
    List<Type> from,
    List<Type> to) 
 public List<Type> substBounds(List<Type> tvars,
    List<Type> from,
    List<Type> to) 
 public Type supertype(Type t) 
 public String toString(Type t) 
Deprecated! Types.toString - (Type t, Locale l) provides better support for localization

    This toString is slightly more descriptive than the one on Type.
 public String toString(Type t,
    Locale locale) 
    Helper method for generating a string representation of a given type accordingly to a given locale
 public String toString(Symbol t,
    Locale locale) 
    Helper method for generating a string representation of a given type accordingly to a given locale
 public Type unboxedType(Type t) 
    Return the primitive type corresponding to a boxed type.
 public List<Type> union(List<Type> cl1,
    List<Type> cl2) 
    Form the union of two closures
 public Type upperBound(Type t) 
    The "rvalue conversion".
    The upper bound of most types is the type itself. Wildcards, on the other hand have upper and lower bounds.