com.sun.tools.javac.comp
Class Infer

java.lang.Object
  extended by com.sun.tools.javac.comp.Infer

public class Infer
extends java.lang.Object

Helper class for type parameter inference, used by the attribution phase.

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.


Nested Class Summary
static class Infer.NoInstanceException
           
 
Field Summary
private  Infer.NoInstanceException ambiguousNoInstanceException
           
static Type anyPoly
          A value for prototypes that admit any type, including polymorphic ones.
(package private)  JCDiagnostic.Factory diags
           
(package private)  Type.Mapping fromTypeVarFun
          A mapping that turns type variables into undetermined type variables.
(package private)  Type.Mapping getInstFun
          A mapping that returns its type argument with every UndetVar replaced by its `inst' field.
protected static Context.Key<Infer> inferKey
           
(package private)  Symtab syms
           
(package private)  Types types
           
private  Infer.NoInstanceException unambiguousNoInstanceException
           
 
Constructor Summary
protected Infer(Context context)
           
 
Method Summary
private  void checkWithinBounds(List<Type> tvars, List<Type> arguments, Warner warn)
          check that type parameters are within their bounds.
static Infer instance(Context context)
           
private  Type instantiateArg(Type.ForAll that, Type to, List<Type> tvars, Warner warn)
          Try to instantiate argument type `that' to given type `to'.
 Type instantiateExpr(Type.ForAll that, Type to, Warner warn)
          Try to instantiate expression type `that' to given type `to'.
 Type instantiateMethod(List<Type> tvars, Type.MethodType mt, List<Type> argtypes, boolean allowBoxing, boolean useVarargs, Warner warn)
          Instantiate method type `mt' by finding instantiations of `tvars' so that method can be applied to `argtypes'.
private  boolean isSubClass(Type t, List<Type> ts)
           
(package private)  void maximizeInst(Type.UndetVar that, Warner warn)
          Instantiate undetermined type variable to its minimal upper bound.
(package private)  void minimizeInst(Type.UndetVar that, Warner warn)
          Instantiate undetermined type variable to the lub of all its lower bounds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inferKey

protected static final Context.Key<Infer> inferKey

anyPoly

public static final Type anyPoly
A value for prototypes that admit any type, including polymorphic ones.


syms

Symtab syms

types

Types types

diags

JCDiagnostic.Factory diags

ambiguousNoInstanceException

private final Infer.NoInstanceException ambiguousNoInstanceException

unambiguousNoInstanceException

private final Infer.NoInstanceException unambiguousNoInstanceException

fromTypeVarFun

Type.Mapping fromTypeVarFun
A mapping that turns type variables into undetermined type variables.


getInstFun

Type.Mapping getInstFun
A mapping that returns its type argument with every UndetVar replaced by its `inst' field. Throws a NoInstanceException if this not possible because an `inst' field is null.

Constructor Detail

Infer

protected Infer(Context context)
Method Detail

instance

public static Infer instance(Context context)

maximizeInst

void maximizeInst(Type.UndetVar that,
                  Warner warn)
            throws Infer.NoInstanceException
Instantiate undetermined type variable to its minimal upper bound. Throw a NoInstanceException if this not possible.

Throws:
Infer.NoInstanceException

isSubClass

private boolean isSubClass(Type t,
                           List<Type> ts)

minimizeInst

void minimizeInst(Type.UndetVar that,
                  Warner warn)
            throws Infer.NoInstanceException
Instantiate undetermined type variable to the lub of all its lower bounds. Throw a NoInstanceException if this not possible.

Throws:
Infer.NoInstanceException

instantiateExpr

public Type instantiateExpr(Type.ForAll that,
                            Type to,
                            Warner warn)
                     throws Infer.NoInstanceException
Try to instantiate expression type `that' to given type `to'. If a maximal instantiation exists which makes this type a subtype of type `to', return the instantiated type. If no instantiation exists, or if several incomparable best instantiations exist throw a NoInstanceException.

Throws:
Infer.NoInstanceException

instantiateMethod

public Type instantiateMethod(List<Type> tvars,
                              Type.MethodType mt,
                              List<Type> argtypes,
                              boolean allowBoxing,
                              boolean useVarargs,
                              Warner warn)
                       throws Infer.NoInstanceException
Instantiate method type `mt' by finding instantiations of `tvars' so that method can be applied to `argtypes'.

Throws:
Infer.NoInstanceException

instantiateArg

private Type instantiateArg(Type.ForAll that,
                            Type to,
                            List<Type> tvars,
                            Warner warn)
                     throws Infer.NoInstanceException
Try to instantiate argument type `that' to given type `to'. If this fails, try to insantiate `that' to `to' where every occurrence of a type variable in `tvars' is replaced by an unknown type.

Throws:
Infer.NoInstanceException

checkWithinBounds

private void checkWithinBounds(List<Type> tvars,
                               List<Type> arguments,
                               Warner warn)
                        throws Infer.NoInstanceException
check that type parameters are within their bounds.

Throws:
Infer.NoInstanceException