APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.tools.javac.code

public Class Types

extends Object
Class Inheritance
Imports
java.lang.ref.SoftReference, java.lang.runtime.ExactConversionsSupport, java.util.HashSet, .HashMap, .Locale, .Map, .Optional, .Set, .WeakHashMap, java.util.function.BiPredicate, .Function, .Predicate, java.util.stream.Collector, javax.tools.JavaFileObject, com.sun.tools.javac.code.Attribute.RetentionPolicy, .Lint.LintCategory, .Type.UndetVar.InferenceBound, .TypeMetadata.Annotations, com.sun.tools.javac.comp.AttrContext, .Check, .Enter, .Env, com.sun.tools.javac.jvm.ClassFile, com.sun.tools.javac.util.*, com.sun.tools.javac.resources.CompilerProperties.Fragments

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 and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
public static class
public class
pack-priv class
Types.CaptureScanner

This visitor scans a type recursively looking for occurrences of captured type variables.

pack-priv class
public abstract static class
Types.DefaultSymbolVisitor<
the return type of the operation implemented by this visitor; use Void if no return type is needed.
R
,
the type of the second argument (the first being the symbol itself) of the operation implemented by this visitor; use Void if a second argument is not needed.
S
>

A default visitor for symbols.

public abstract static class
Types.DefaultTypeVisitor<
the return type of the operation implemented by this visitor; use Void if no return type is needed.
R
,
the type of the second argument (the first being the type itself) of the operation implemented by this visitor; use Void if a second argument is not needed.
S
>

A default visitor for types.

pack-priv class
Types.DescriptorCache

A cache that keeps track of function descriptors associated with given functional interfaces.

pack-priv class
Types.DescriptorFilter

Scope filter used to skip methods that should be ignored (such as methods overridden by j.l.Object) during function interface conversion interface check

pack-priv class
public static class
Types.FunctionDescriptorLookupError

Exception used to report a function descriptor lookup failure.

private static class
private class
pack-priv class
public static class
Types.MapVisitor<
the type of the second argument (the first being the type itself) of this mapping; use Void if a second argument is not needed.
S
>

A visitor for implementing a mapping from types to types.

pack-priv class
private class
public static enum
Types.MostSpecificReturnCheck

This enum defines the strategy for implementing most specific return type check during the most specific and functional interface checks.

pack-priv static enum
Types.ProjectionKind

A projection kind.

pack-priv class
public abstract class
public abstract static class
Types.SimpleVisitor<
the return type of the operation implemented by this visitor; use Void if no return type is needed.
R
,
the type of the second argument (the first being the type itself) of the operation implemented by this visitor; use Void if a second argument is not needed.
S
>

A simple visitor for types.

private class
pack-priv abstract class
Types.TypeEqualityVisitor

Type-equality relation - type variables are considered equals if they share the same object identity.

public static class
Types.TypeMapping<S>

An abstract class for mappings from types to types (see Type#map(TypeMapping).

pack-priv class
pack-priv class
Types.TypeProjection

This visitor performs upwards and downwards projections on types.

public abstract static class
Types.TypeRelation

A plain relation on types.

public abstract static class
Types.UnaryVisitor<
the return type of the operation implemented by this visitor; use Void if no return type is needed.
R
>

A convenience visitor for implementing operations that only require one argument (the type itself), that is, unary operations.

public static class
Types.UniqueType

A wrapper for a type that allows use in sets.

Field Summary

Modifier and TypeField and Description
private Type
private final Types.SimpleVisitor<Type, Symbol>
private Types.SimpleVisitor<Type, Symbol>
pack-priv BiPredicate<Type, Type>
private Predicate<Symbol>
public Types.CandidatesCache
pack-priv final Name
pack-priv final Check
private Types.UnaryVisitor<Type>
private Map<Type, List<Type>>
closureCache

A cache for closures.

private Types.TypeRelation
private final Types.TypeMapping<Void>
private Types.DescriptorCache
pack-priv JCDiagnostic.Factory
private final Types.UnaryVisitor<List<Type>>
private Types.TypeRelation
public final boolean
private Types.TypeMapping<Void>
elemTypeFun

Mapping to take element type of an arraytype

pack-priv final Enter
private Types.TypeMapping<Boolean>
pack-priv Types.TypeEqualityVisitor
private static final Types.HashCodeVisitor
private static final Types.HashCodeVisitor
pack-priv Types.TypeRelation
pack-priv Types.TypeRelation
private Types.ImplementationCache
private Types.UnaryVisitor<List<Type>>
private Types.TypeRelation
pack-priv Map<Type, Boolean>
private Types.UnaryVisitor<Boolean>
pack-priv Types.TypeEqualityVisitor
private Types.TypeRelation
private final Types.UnaryVisitor<Boolean>
private Types.MembersClosureCache
private Types.SimpleVisitor<Type, Symbol>
pack-priv Set<Types.TypePair>
pack-priv final JavacMessages
private final Types.MapVisitor<List<Type>>
private final Types.MapVisitor<Type>
private final Types.MapVisitor<List<Type>>
pack-priv final Names
private static final Types.TypeMapping<Void>
public final Warner
private Types.UnaryVisitor<Type>
pack-priv final Symtab
protected static final Context.Key<Types>
pack-priv List<Warner>

Constructor Summary

AccessConstructor and Description
protected
Types(Context context)

Method Summary

Modifier and TypeMethod and Description
public void
adapt(Type
the source type
source
,
Type
the target type
target
,
ListBuffer<Type>
the type variables of the computed substitution
from
,
ListBuffer<Type>
the types of the computed substitution.
to
)

Adapt a type by computing a substitution which maps a source type to a target type.

private void
private void
private Type
public Type
asEnclosingSuper(Type
a type
t
,
Symbol
a symbol
sym
)

This method returns the first type in a sequence (starting at `t`) that is a subclass of `sym`.

public Type
asOuterSuper(Type
a type
t
,
Symbol
a symbol
sym
)

This method returns the first type in a sequence (starting at `t`) that is a subclass of `sym`.

public Type
asSub(Type t, Symbol sym)

Return the least specific subtype of t that starts with symbol sym.

public Type
asSuper(Type
a type
t
,
Symbol
a symbol
sym
)

Return the (most specific) base type of t that starts with the given symbol.

public Symbol.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
public List<Type>

Returns:

the set of captured variables found in t
captures
(Type
the type where occurrences of captured variables have to be found
t
)

Computes the set of captured variables mentioned in a given type.

private void
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 Collector<Type, Types.ClosureHolder, List<Type>>
closureCollector(boolean minClosure, BiPredicate<Type, Type> shouldSkip)

Collect types into a new closure (using a ClosureHolder)

public List<Type>
closureMin(List<Type> cl)

Return the minimum types of a closure, suitable for computing compoundMin or glb.

private Type
compoundMin(List<Type> cl)

Return the minimum type of a closure, a compound type if no unique minimum exists.

public Type
public boolean
pack-priv boolean
public boolean
containsType(Type
a type
t
,
Type
a type
s
)

Check if t contains s.

public boolean
private boolean
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
public Type
createErrorType(Name name, Symbol.TypeSymbol container, Type originalType)

public Type
public Type
createMethodTypeWithReturn(Type original, Type newReturn)

public Type
createMethodTypeWithThrown(Type original, List<Type> newThrown)

public Type
cvarLowerBound(Type
a type
t
)

Get a capture variable's lower bound, returning other types unchanged.

public List<Type>
public Type
cvarUpperBound(Type
a type
t
)

Get a capture variable's upper bound, returning other types unchanged.

public int
dimensions(Type t)

The number of dimensions of an array type.

public List<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
public Type
elemtype(Type t)

The element type of an array.

public Type
public List<Type>
private boolean
public Type
erasure(Type t)

The erasure of t |t| -- the type that results when all type parameters in t are deleted.

private Type
erasure(Type t, boolean recurse)

public List<Type>
public Type
public List<Type>
public Symbol
findDescriptorSymbol(Symbol.TypeSymbol origin)

Find the method descriptor associated to this class symbol - if the symbol 'origin' is not a functional interface, an exception is thrown.

public Type
findDescriptorType(Type origin)

Find the type of the method descriptor associated to this class symbol - if the symbol 'origin' is not a functional interface, an exception is thrown.

public Symbol.MethodSymbol
firstUnimplementedAbstract(Symbol.ClassSymbol sym)

Return first abstract member of class `sym'.

private Symbol.MethodSymbol
public List<Type>
public List<Symbol>
functionalInterfaceBridges(Symbol.TypeSymbol origin)

Find the minimal set of methods that are overridden by the functional descriptor in 'origin'.

public List<Type>
getBounds(Type.TypeVar t)

Return list of bounds of the given type variable.

public Attribute.RetentionPolicy
public Attribute.RetentionPolicy
private boolean
giveWarning(Type from, Type to)

public Type
glb(List<Type> ts)

public Type
glb(Type t, Type s)

private Type
glbFlattened(List<Type>
List of type to glb
flatBounds
,
Type
Original type to use if the result is an error type
errT
)

Perform glb for a list of non-primitive, non-error, non-compound types; redundant elements are removed.

public int
hashCode(Type t)

Compute a hash code on a type.

public int
hashCode(Type t, boolean strict)

public boolean
hasSameArgs(Type t, Type s)

Does t have the same arguments as s?

public boolean
hasSameArgs(Type t, Type s, boolean strict)

private boolean
hasSameArgs(Type t, Type s, Types.TypeRelation hasSameArgs)

public boolean
hasSameBounds(Type.ForAll t, Type.ForAll s)

Does t have the same bounds for quantified variables as s?

public Symbol.MethodSymbol
implementation(Symbol.MethodSymbol ms, Symbol.TypeSymbol origin, boolean checkResult, Predicate<Symbol> implFilter)

public List<Type>
insert(List<Type> cl, Type t, BiPredicate<Type, Type> shouldSkip)

Insert a type in a closure

public List<Type>
insert(List<Type> cl, Type t)

public static Types
instance(Context context)

public List<Symbol.MethodSymbol>
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
public boolean
public boolean
isAssignable(Type t, Type s, Warner warn)

Is t assignable to s?

public boolean
public boolean
public boolean
isCastable(Type t, Type s, Warner warn)

Is t castable to s?

public boolean
isConvertible(Type t, Type s, Warner warn)

Is t a subtype of or convertible via boxing/unboxing conversion to s?

public boolean
isConvertible(Type t, Type s)

Is t a subtype of or convertible via boxing/unboxing conversions to s?

public boolean
public boolean
public boolean
public boolean
public boolean
isFunctionalInterface(Symbol.TypeSymbol tsym)

Is given type a functional interface?

public boolean
public boolean
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?

public boolean
public boolean
isSignaturePolymorphic(Symbol.MethodSymbol msym)

A polymorphic signature method (JLS 15.12.3) is a method that (i) is declared in the java.lang.invoke.MethodHandle/VarHandle classes; (ii) takes a single variable arity parameter; (iii) whose declared type is Object[]; (iv) has any return type, Object signifying a polymorphic return type; and (v) is native.

public boolean

Returns:

true if t is a subsignature of s.
isSubSignature
(Type
first signature (possibly raw).
t
,
Type
second signature (could be subjected to erasure).
s
)

Returns true iff the first signature is a subsignature of the other.

public final boolean
isSubtype(Type t, Type s)

Is t a subtype of s?

public boolean
isSubtype(Type t, Type s, boolean capture)

public final boolean
public boolean
isSubtypes(List<Type> ts, List<Type> ss)

Are corresponding elements of ts subtypes of ss?

public boolean
isSubtypesUnchecked(List<Type> ts, List<Type> ss, Warner warn)

Are corresponding elements of ts subtypes of ss, allowing unchecked conversions?

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'?

private boolean
isSubtypeUncheckedInternal(Type t, Type s, boolean capture, Warner warn)

public boolean
isSuperType(Type t, Type s)

Is t a supertype of s?

public boolean

Returns:

true iff the given type is unbounded or raw
isUnbounded
(Type
a 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 boolean
isUnconditionallyExactCombined(Type currentType, Type testType)

Check both type or value-based unconditional exactness between any combination of reference or primitive types for the value of a constant expression according to JLS 5.7.2.

public boolean
isUnconditionallyExactTypeBased(Type
Source primitive or reference type
source
,
Type
Target primitive or reference type
target
)

Check type-based unconditional exactness between any combination of reference or primitive types according to JLS 5.7.2.

public boolean
isUnconditionallyExactValueBased(Type
Source primitive or reference type, should be a numeric value
source
,
Type
Target primitive or reference type
target
)

Check value-based unconditional exactness between any combination of reference or primitive types for the value of a constant expression according to JLS 5.7.2.

public Type
lub(List<Type> ts)

Return the least upper bound of list of types.

public Type
lub(Type... ts)

Return the least upper bound (lub) of set of types.

public Type.ArrayType

Returns:

the ArrayType for the given component
makeArrayType
(Type
The component type of the ArrayType
t
)

Returns an ArrayType with the component type t

private Type.WildcardType
makeExtendsWildcard(Type
the upper bound
bound
,
Type.TypeVar
the formal type parameter that will be substituted by the wildcard
formal
)

Create a wildcard with the given upper (extends) bound; create an unbounded wildcard if bound is Object.

public Symbol.ClassSymbol
makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, Type target, long cflags)

Create a symbol for a class that implements a given functional interface and overrides its functional descriptor.

public Type.IntersectionClassType
makeIntersectionType(List<Type>
the types from which the intersection type is formed
bounds
)

Make an intersection type from non-empty list of types.

public Type.IntersectionClassType
makeIntersectionType(List<Type>
the types from which the intersection type is formed
bounds
,
boolean
are all bounds interface types?
allInterfaces
)

Make an intersection type from non-empty list of types.

private Type.WildcardType
makeSuperWildcard(Type
the lower bound
bound
,
Type.TypeVar
the formal type parameter that will be substituted by the wildcard
formal
)

Create a wildcard with the given lower (super) bound; create an unbounded wildcard if bound is bottom (type of null).

public Scope.CompoundScope
membersClosure(Type site, boolean skipInterface)

public Type
memberType(Type
a type
t
,
Symbol
a symbol
sym
)

The type of given symbol, seen as a member of t.

private Type
merge(Type c1, Type c2)

public Optional<Symbol>
mergeAbstracts(List<Symbol> ambiguousInOrder, Type site, boolean sigCheck)

Merge multiple abstract methods.

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 void
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'?

public Symbol
public boolean

Returns:

true if either argument is a subsignature of the other.
overrideEquivalent
(Type
a signature (possible raw, could be subjected to erasure).
t
,
Type
a signature (possible raw, could be subjected to erasure).
s
)

Returns true iff these signatures are related by override equivalence.

public boolean
private boolean
public List<Symbol.MethodSymbol>
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.

private Type
public Type
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?

public boolean
returnTypeSubstitutable(Type r1, Type r2)

Return-Type-Substitutable.

public boolean
returnTypeSubstitutable(Type r1, Type r2, Type r2res, Warner warner)

private Type

Returns:

the type rewritten with wildcards (existential quantifiers) only
rewriteQuantifiers
(Type
a type
t
,
boolean
if true return an upper bound; otherwise a lower bound
high
,
boolean
only rewrite captured wildcards if false; otherwise rewrite all type variables
rewriteTypeVars
)

Rewrite all type variables (universal quantifiers) in the given type to wildcards (existential quantifiers).

public void
setBounds(Type.TypeVar
a type variable
t
,
List<Type>
the bounds, must be nonempty
bounds
)

Same as Types#setBounds(TypeVar, List, boolean), 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).

public void
setBounds(Type.TypeVar
a type variable
t
,
List<Type>
the bounds, must be nonempty
bounds
,
boolean
are all bounds interface types?
allInterfaces
)

Set the bounds field of the given type variable to reflect a (possibly multiple) list of bounds.

private boolean
sideCast(Type from, Type to, Warner warn)

private boolean
sideCastFinal(Type from, Type to, Warner warn)

public Type
skipTypeVars(Type site, boolean capture)

Recursively skip type-variables until a class/array type is found; capture conversion is then (optionally) applied to the resulting type.

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 Type.TypeVar
public List<Type>
substBounds(List<Type> tvars, List<Type> from, List<Type> to)

public Type
private List<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 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.

private String
public Type
unboxedType(Type t)

Return the primitive type corresponding to a boxed type.

public Type
unboxedTypeOrType(Type t)

Return the unboxed type if 't' is a boxed class, otherwise return 't' itself.

public List<Type>
union(List<Type> cl1, List<Type> cl2, BiPredicate<Type, Type> shouldSkip)

Form the union of two closures

public List<Type>
union(List<Type> cl1, List<Type> cl2)

public Type

Returns:

the type obtained as result of the projection
upward
(Type
the type to be projected
t
,
List<Type>
the set of type variables to be mapped
vars
)

Computes an upward projection of given type, and vars.

public Type
wildLowerBound(Type
a type argument, either a wildcard or a type
t
)

Get a wildcard's lower bound, returning non-wildcards unchanged.

public Type
wildUpperBound(Type
a type argument, either a wildcard or a type
t
)

Get a wildcard's upper bound, returning non-wildcards unchanged.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait