| java.lang.Object com.sun.tools.javac.code.Types
Types | public class Types (Code) | | 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 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.
|
Inner Class :class TypePair | |
Inner Class :public static class AdaptFailure extends Exception | |
Inner Class :class SingletonType | |
Inner Class :abstract public static class DefaultTypeVisitor implements Type.Visitor<R, S> | |
Inner Class :abstract public static class SimpleVisitor extends DefaultTypeVisitor | |
Inner Class :abstract public static class TypeRelation extends SimpleVisitor | |
Inner Class :abstract public static class UnaryVisitor extends SimpleVisitor | |
Inner Class :public static class MapVisitor extends DefaultTypeVisitor | |
Method Summary | |
public void | adapt(Type source, Type target, ListBuffer<Type> from, ListBuffer<Type> to) 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. | 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. | public Type | asSub(Type t, Symbol sym) Return the least specific subtype of t that starts with symbol
sym. | public Type | asSuper(Type t, Symbol sym) Return the (most specific) base type of t that starts with the
given symbol. | public ClassSymbol | boxedClass(Type t) Return the class that boxes the given primitive. | public Type | capture(Type t) Capture conversion as specified by JLS 3rd Ed. | 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:
L(T) <: L(S) && U(S) <: U(T) This relation is only used by ClassType.isSubtype(), that
is,
C <: C if T contains S. | public boolean | containsTypeEquivalent(List<Type> ts, List<Type> ss) | public boolean | covariantReturnType(Type t, Type s, Warner warner) | 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. | public boolean | disjointTypes(List<Type> ts, List<Type> ss) | public Type | elemtype(Type t) The element type of an array. | public Type | erasure(Type t) The erasure of t
|t| -- the type that results when all
type parameters in t are deleted. | public List<Type> | erasure(List<Type> ts) | public List<Type> | getBounds(TypeVar t) Return list of bounds of the given type variable. | 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. | boolean | hasSameBounds(ForAll t, ForAll s) | public static int | hashCode(Type t) Compute a hash code on a type. | public List<Type> | insert(List<Type> cl, Type t) | 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) | public boolean | isArray(Type t) | public boolean | isAssignable(Type t, Type s) | public boolean | isAssignable(Type t, Type s, Warner warn) | 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, Warner warn) | public boolean | isConvertible(Type t, Type 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) | 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. | final public boolean | isSubtype(Type t, Type s) | public boolean | isSubtype(Type t, Type s, boolean capture) | final public boolean | isSubtypeNoCapture(Type t, Type s) | public boolean | isSubtypeUnchecked(Type t, Type s) | public boolean | isSubtypeUnchecked(Type t, Type s, Warner warn) | 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) | 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. | public Type | lowerBound(Type t) The "lvalue conversion".
The lower bound of most types is the type
itself. | public List<Type> | lowerBoundArgtypes(Type t) Returns the lower bounds of the formals of a method. | public Type | lub(Type t1, Type t2) Return the least upper bound of pair of types. | public Type | lub(List<Type> ts) Return the least upper bound (lub) of set of types. | public Type | makeCompoundType(List<Type> bounds, Type supertype) | public Type | makeCompoundType(List<Type> bounds) Same as
Types.makeCompoundType(List,Type) , except that the
second parameter is computed directly. | public Type | makeCompoundType(Type bound1, Type bound2) A convenience wrapper for
Types.makeCompoundType(List) ; the
arguments are converted to a list and passed to the other
method. | public Type | memberType(Type t, Symbol sym) The type of given symbol, seen as a member of t. | 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. | 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. | 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. | public boolean | returnTypeSubstitutable(Type r1, Type r2) Return-Type-Substitutable.
See Also: The Java
* Language Specification, Third Ed. | public boolean | returnTypeSubstitutable(Type r1, Type r2, Type r2res, Warner warner) | 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 void | setBounds(TypeVar t, List<Type> bounds) Same as
Types.setBounds(Type.TypeVar,List,Type) , except that
third parameter is computed directly. | 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'. | 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) This toString is slightly more descriptive than the one on Type. | public Type | unboxedType(Type t) Return the primitive type corresponding to a boxed type. | public List<Type> | union(List<Type> cl1, List<Type> cl2) | public Type | upperBound(Type t) The "rvalue conversion".
The upper bound of most types is the type
itself. |
allowBoxing | final boolean allowBoxing(Code) | | |
fromUnknownFun | public Mapping fromUnknownFun(Code) | | A mapping that turns all unknown types in this type to fresh
unknown variables.
|
adapt | public void adapt(Type source, Type target, ListBuffer<Type> from, ListBuffer<Type> to) throws AdaptFailure(Code) | | Adapt a type by computing a substitution which maps a source
type to a target type.
Parameters: source - the source type Parameters: target - the target type Parameters: from - the type variables of the computed substitution Parameters: to - the types of the computed substitution. |
asEnclosingSuper | public Type asEnclosingSuper(Type t, Symbol sym)(Code) | | Return the base type of t or any of its enclosing types that
starts with the given symbol. If none exists, return null.
Parameters: t - a type Parameters: sym - a symbol |
asOuterSuper | public Type asOuterSuper(Type t, Symbol sym)(Code) | | Return the base type of t or any of its outer types that starts
with the given symbol. If none exists, return null.
Parameters: t - a type Parameters: sym - a symbol |
asSub | public Type asSub(Type t, Symbol sym)(Code) | | 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.
|
asSuper | public Type asSuper(Type t, Symbol sym)(Code) | | Return the (most specific) base type of t that starts with the
given symbol. If none exists, return null.
Parameters: t - a type Parameters: sym - a symbol |
boxedClass | public ClassSymbol boxedClass(Type t)(Code) | | Return the class that boxes the given primitive.
|
capture | public Type capture(Type t)(Code) | | Capture conversion as specified by JLS 3rd Ed.
|
classBound | public Type classBound(Type t)(Code) | | If the given type is a (possibly selected) type variable,
return the bounding class of this type, otherwise return the
type itself.
|
closure | public List<Type> closure(Type t)(Code) | | Returns the closure of a class or interface type.
|
containsType | public boolean containsType(Type t, Type s)(Code) | | Check if t contains s.
T contains S if:
L(T) <: L(S) && U(S) <: U(T) This relation is only used by ClassType.isSubtype(), that
is,
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:
U(S) <: U(T) if T is "super" bound (U(T) *is* the bound)
L(T) <: L(S) if T is "extends" bound (L(T) is bottom) Parameters: t - a type Parameters: s - a type |
covariantReturnType | public boolean covariantReturnType(Type t, Type s, Warner warner)(Code) | | Is t an appropriate return type in an overrider for a
method that returns s?
|
dimensions | public int dimensions(Type t)(Code) | | The number of dimensions of an array type.
|
disjointType | public boolean disjointType(Type t, Type s)(Code) | | 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.
|
elemtype | public Type elemtype(Type t)(Code) | | The element type of an array.
|
erasure | public Type erasure(Type t)(Code) | | The erasure of t
|t| -- the type that results when all
type parameters in t are deleted.
|
getBounds | public List<Type> getBounds(TypeVar t)(Code) | | Return list of bounds of the given type variable.
|
hasSameArgs | public boolean hasSameArgs(Type t, Type s)(Code) | | 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.
|
hasSameBounds | boolean hasSameBounds(ForAll t, ForAll s)(Code) | | Does t have the same bounds for quantified variables as s?
|
hashCode | public static int hashCode(Type t)(Code) | | Compute a hash code on a type.
|
interfaces | public List<Type> interfaces(Type t)(Code) | | Return the interfaces implemented by this class.
|
isAssignable | public boolean isAssignable(Type t, Type s, Warner warn)(Code) | | Is t assignable to s?
Equivalent to subtype except for constant values and raw
types.
(not defined for Method and ForAll types)
|
isCaptureOf | public boolean isCaptureOf(Type s, WildcardType t)(Code) | | |
isCastable | public boolean isCastable(Type t, Type s, Warner warn)(Code) | | Is t is castable to s?
s is assumed to be an erased type.
(not defined for Method and ForAll types).
|
isConvertible | public boolean isConvertible(Type t, Type s, Warner warn)(Code) | | Is t a subtype of or convertiable via boxing/unboxing
convertions to s?
|
isConvertible | public boolean isConvertible(Type t, Type s)(Code) | | Is t a subtype of or convertiable via boxing/unboxing
convertions to s?
|
isDerivedRaw | public boolean isDerivedRaw(Type t)(Code) | | |
isDerivedRawInternal | public boolean isDerivedRawInternal(Type t)(Code) | | |
isReifiable | public boolean isReifiable(Type t)(Code) | | |
isSameType | public boolean isSameType(Type t, Type s)(Code) | | Is t the same type as s?
|
isSameTypes | public boolean isSameTypes(List<Type> ts, List<Type> ss)(Code) | | Are corresponding elements of the lists the same type? If
lists are of different length, return false.
|
isSameWildcard | public boolean isSameWildcard(WildcardType t, Type s)(Code) | | |
isSubSignature | public boolean isSubSignature(Type t, Type s)(Code) | | Returns true iff the first signature is a sub
signature of the other. This is not an equivalence
relation.
See Also: "The Java Language Specification, Third Ed. (8.4.2)." See Also: Types.overrideEquivalent(Type t,Type s) Parameters: t - first signature (possibly raw). Parameters: s - second signature (could be subjected to erasure). true if t is a sub signature of s. |
isSubtype | final public boolean isSubtype(Type t, Type s)(Code) | | Is t a subtype of s?
(not defined for Method and ForAll types)
|
isSubtype | public boolean isSubtype(Type t, Type s, boolean capture)(Code) | | |
isSubtypeNoCapture | final public boolean isSubtypeNoCapture(Type t, Type s)(Code) | | |
isSubtypeUnchecked | public boolean isSubtypeUnchecked(Type t, Type s)(Code) | | Is t an unchecked subtype of s?
|
isSubtypeUnchecked | public boolean isSubtypeUnchecked(Type t, Type s, Warner warn)(Code) | | Is t an unchecked subtype of s?
|
isSubtypeUnchecked | public boolean isSubtypeUnchecked(Type t, List<Type> ts, Warner warn)(Code) | | Is t a subtype of every type in given list `ts'?
(not defined for Method and ForAll types)
Allows unchecked conversions.
|
isSubtypes | public boolean isSubtypes(List<Type> ts, List<Type> ss)(Code) | | Are corresponding elements of ts subtypes of ss? If lists are
of different length, return false.
|
isSubtypesUnchecked | public boolean isSubtypesUnchecked(List<Type> ts, List<Type> ss, Warner warn)(Code) | | Are corresponding elements of ts subtypes of ss, allowing
unchecked conversions? If lists are of different length,
return false.
|
isSuperType | public boolean isSuperType(Type t, Type s)(Code) | | Is t a supertype of s?
|
isUnbounded | public boolean isUnbounded(Type t)(Code) | | 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.
Parameters: t - a type true iff the given type is unbounded or raw |
lowerBound | public Type lowerBound(Type t)(Code) | | The "lvalue conversion".
The lower bound of most types is the type
itself. Wildcards, on the other hand have upper
and lower bounds.
Parameters: t - a type the lower bound of the given type |
lowerBoundArgtypes | public List<Type> lowerBoundArgtypes(Type t)(Code) | | Returns the lower bounds of the formals of a method.
|
lub | public Type lub(Type t1, Type t2)(Code) | | Return the least upper bound of pair of types. if the lub does
not exist return null.
|
lub | public Type lub(List<Type> ts)(Code) | | Return the least upper bound (lub) of set of types. If the lub
does not exist return the type of null (bottom).
|
makeCompoundType | public Type makeCompoundType(List<Type> bounds, Type supertype)(Code) | | Make a compound type from non-empty list of types
Parameters: bounds - the types from which the compound type is formed Parameters: supertype - is objectType if all bounds are interfaces,null otherwise. |
makeCompoundType | public Type makeCompoundType(List<Type> bounds)(Code) | | Same as
Types.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.
|
makeCompoundType | public Type makeCompoundType(Type bound1, Type bound2)(Code) | | A convenience wrapper for
Types.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.
|
memberType | public Type memberType(Type t, Symbol sym)(Code) | | The type of given symbol, seen as a member of t.
Parameters: t - a type Parameters: sym - a symbol |
newInstances | public List<Type> newInstances(List<Type> tvars)(Code) | | Create new vector of type variables from list of variables
changing all recursive bounds from old to new list.
|
notSoftSubtype | public boolean notSoftSubtype(Type t, Type s)(Code) | | 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.
|
overrideEquivalent | public boolean overrideEquivalent(Type t, Type s)(Code) | | Returns true iff these signatures are related by override
equivalence. This is the natural extension of
isSubSignature to an equivalence relation.
See Also: "The Java Language Specification, Third Ed. (8.4.2)." See Also: Types.isSubSignature(Type t,Type s) Parameters: t - a signature (possible raw, could be subjected toerasure). Parameters: s - a signature (possible raw, could be subjected toerasure). true if either argument is a sub signature of the other. |
rank | public int rank(Type t)(Code) | | 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.
|
resultSubtype | public boolean resultSubtype(Type t, Type s, Warner warner)(Code) | | 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.
|
setBounds | public void setBounds(TypeVar t, List<Type> bounds, Type supertype)(Code) | | Set the bounds field of the given type variable to reflect a
(possibly multiple) list of bounds.
Parameters: t - a type variable Parameters: bounds - the bounds, must be nonempty Parameters: supertype - is objectType if all bounds are interfaces,null otherwise. |
setBounds | public void setBounds(TypeVar t, List<Type> bounds)(Code) | | Same as
Types.setBounds(Type.TypeVar,List,Type) , except that
third parameter is computed directly. Note that this test
might cause a symbol completion. Hence, this version of
setBounds may not be called during a classfile read.
|
subst | public Type subst(Type t, List<Type> from, List<Type> to)(Code) | | 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.
|
toString | public String toString(Type t)(Code) | | This toString is slightly more descriptive than the one on Type.
|
unboxedType | public Type unboxedType(Type t)(Code) | | Return the primitive type corresponding to a boxed type.
|
upperBound | public Type upperBound(Type t)(Code) | | The "rvalue conversion".
The upper bound of most types is the type
itself. Wildcards, on the other hand have upper
and lower bounds.
Parameters: t - a type the upper bound of the given type |
|
|