public class DefaultTypeArgumentInference extends java.lang.Object implements TypeArgumentInference
Note, there are some deviations JLS 7 for the following cases:
<T> T get()
<S> void set(S s)
set(get())
Presumably, we want to detect these situations and combine the set of constraints with
T <: S
.
Constructor and Description |
---|
DefaultTypeArgumentInference(AnnotatedTypeFactory typeFactory) |
Modifier and Type | Method and Description |
---|---|
void |
addConstraintsBetweenTargets(java.util.Set<TUConstraint> constraints,
java.util.Set<javax.lang.model.type.TypeVariable> targets,
boolean asSubtype,
AnnotatedTypeFactory typeFactory)
Declarations of the form:
<A, B extends A> implies a TUConstraint of B <: A . |
AnnotatedTypeMirror.AnnotatedTypeVariable |
addOrGetDeclarations(javax.lang.model.type.TypeVariable target,
AnnotatedTypeFactory typeFactory,
java.util.Map<javax.lang.model.type.TypeVariable,AnnotatedTypeMirror.AnnotatedTypeVariable> declarations) |
protected java.util.Set<TUConstraint> |
afToTuConstraints(java.util.Set<? extends AFConstraint> afConstraints,
java.util.Set<javax.lang.model.type.TypeVariable> targets)
Convert AFConstraints to TUConstraints
|
protected java.util.Set<AFConstraint> |
createArgumentAFConstraints(AnnotatedTypeFactory typeFactory,
java.util.List<AnnotatedTypeMirror> argTypes,
AnnotatedTypeMirror.AnnotatedExecutableType methodType,
java.util.Set<javax.lang.model.type.TypeVariable> targets,
boolean useNullArguments)
Step 1: Create a constraint
Ai << Fi for each Argument(Ai) to formal parameter(Fi). |
ConstraintMap |
createAssignmentConstraints(AnnotatedTypeMirror assignedTo,
AnnotatedTypeMirror boxedReturnType,
AnnotatedTypeMirror.AnnotatedExecutableType methodType,
java.util.Set<AFConstraint> afArgumentConstraints,
java.util.Map<javax.lang.model.type.TypeVariable,AnnotatedTypeMirror> inferredArgs,
java.util.Set<javax.lang.model.type.TypeVariable> targets,
AnnotatedTypeFactory typeFactory)
The first half of Step 6.
|
protected java.util.Set<FIsA> |
createInitialAssignmentConstraints(AnnotatedTypeMirror assignedTo,
AnnotatedTypeMirror boxedReturnType,
AnnotatedTypeFactory typeFactory,
java.util.Set<javax.lang.model.type.TypeVariable> targets)
Create a set of constraints between return type and any type to which it is assigned.
|
java.util.Map<javax.lang.model.type.TypeVariable,AnnotatedTypeMirror> |
inferTypeArgs(AnnotatedTypeFactory typeFactory,
ExpressionTree expressionTree,
javax.lang.model.element.ExecutableElement methodElem,
AnnotatedTypeMirror.AnnotatedExecutableType methodType)
Infer the type arguments for the method or constructor invocation given by invocation.
|
protected void |
reduceAfConstraints(AnnotatedTypeFactory typeFactory,
java.util.Set<AFConstraint> outgoing,
java.util.Queue<AFConstraint> toProcess,
java.util.Set<javax.lang.model.type.TypeVariable> targets)
Given a set of AFConstraints, remove all constraints that are not relevant to inference and
return a set of AFConstraints in which the F is a use of one of the type parameters to infer.
|
public DefaultTypeArgumentInference(AnnotatedTypeFactory typeFactory)
public java.util.Map<javax.lang.model.type.TypeVariable,AnnotatedTypeMirror> inferTypeArgs(AnnotatedTypeFactory typeFactory, ExpressionTree expressionTree, javax.lang.model.element.ExecutableElement methodElem, AnnotatedTypeMirror.AnnotatedExecutableType methodType)
TypeArgumentInference
inferTypeArgs
in interface TypeArgumentInference
typeFactory
- the type factory used to create methodTypeexpressionTree
- a tree representing the method or constructor invocation for which we are
inferring type argumentsmethodElem
- the element for the declaration of the method being invokedmethodType
- the declaration type of method elemNote: We use the Java TypeVariable type because this uniquely identifies a declaration where as two uses of an AnnotatedTypeVariable may be uses of the same declaration but are not .equals to each other.
protected java.util.Set<AFConstraint> createArgumentAFConstraints(AnnotatedTypeFactory typeFactory, java.util.List<AnnotatedTypeMirror> argTypes, AnnotatedTypeMirror.AnnotatedExecutableType methodType, java.util.Set<javax.lang.model.type.TypeVariable> targets, boolean useNullArguments)
Ai << Fi
for each Argument(Ai) to formal parameter(Fi).
Remove any constraint that does not involve a type parameter to be inferred. Reduce the
remaining constraints so that Fi = Tj where Tj is a type parameter with an argument to be
inferred. Return the resulting constraint set.typeFactory
- AnnotatedTypeFactoryargTypes
- list of annotated types corresponding to the arguments to the methodmethodType
- annotated type of the methodtargets
- type variables to be inferreduseNullArguments
- whether or not null method arguments should be consideredprotected java.util.Set<FIsA> createInitialAssignmentConstraints(AnnotatedTypeMirror assignedTo, AnnotatedTypeMirror boxedReturnType, AnnotatedTypeFactory typeFactory, java.util.Set<javax.lang.model.type.TypeVariable> targets)
public ConstraintMap createAssignmentConstraints(AnnotatedTypeMirror assignedTo, AnnotatedTypeMirror boxedReturnType, AnnotatedTypeMirror.AnnotatedExecutableType methodType, java.util.Set<AFConstraint> afArgumentConstraints, java.util.Map<javax.lang.model.type.TypeVariable,AnnotatedTypeMirror> inferredArgs, java.util.Set<javax.lang.model.type.TypeVariable> targets, AnnotatedTypeFactory typeFactory)
This method creates constraints:
protected void reduceAfConstraints(AnnotatedTypeFactory typeFactory, java.util.Set<AFConstraint> outgoing, java.util.Queue<AFConstraint> toProcess, java.util.Set<javax.lang.model.type.TypeVariable> targets)
protected java.util.Set<TUConstraint> afToTuConstraints(java.util.Set<? extends AFConstraint> afConstraints, java.util.Set<javax.lang.model.type.TypeVariable> targets)
public void addConstraintsBetweenTargets(java.util.Set<TUConstraint> constraints, java.util.Set<javax.lang.model.type.TypeVariable> targets, boolean asSubtype, AnnotatedTypeFactory typeFactory)
<A, B extends A>
implies a TUConstraint of B <: A
.
Add these to the constraint list.public AnnotatedTypeMirror.AnnotatedTypeVariable addOrGetDeclarations(javax.lang.model.type.TypeVariable target, AnnotatedTypeFactory typeFactory, java.util.Map<javax.lang.model.type.TypeVariable,AnnotatedTypeMirror.AnnotatedTypeVariable> declarations)