Class AFConstraint
- java.lang.Object
-
- org.checkerframework.framework.util.typeinference.constraint.AFConstraint
-
public abstract class AFConstraint extends java.lang.Object
AFConstraint represent the initial constraints used to infer type arguments for method invocations and new class invocations. These constraints are simplified then converted to TUConstraints during type argument inference.Subclasses of AFConstraint represent the following types of constraints:
A 《 F and F 》 A both imply that A is convertible to F. F 《 A and A 》 F both imply that F is convertible to A (this may happen due to wildcard/typevar bounds and recursive types) A = F implies that A is exactly F
In the Checker Framework a type, A will be convertible to another type F, if AnnotatedTypes.asSuper will return a non-null value when A is passed as a subtype and F the supertype to the method.
In Java type A will be convertible to another type F if there exists a conversion context/method that transforms the one type into the other.
A 《 F and F 》 A are represented by class A2F F 《 A and A 》 F are represented by class F2A F = A is represented by class FIsA
-
-
Field Summary
Fields Modifier and Type Field Description AnnotatedTypeMirror
argument
The argument type.AnnotatedTypeMirror
formalParameter
The formal parameter type.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AFConstraint(AnnotatedTypeMirror argument, AnnotatedTypeMirror formalParameter)
Create a constraint for type arguments for a method invocation or new class invocation.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract AFConstraint
construct(AnnotatedTypeMirror newArgument, AnnotatedTypeMirror newFormalParameter)
Used to create a new constraint of the same subclass of AFConstraint.boolean
equals(@Nullable java.lang.Object thatObject)
int
hashCode()
boolean
isIrreducible(java.util.Set<javax.lang.model.type.TypeVariable> targets)
Returns true if this constraint can't be broken up into other constraints or further simplified.AFConstraint
substitute(java.util.Map<javax.lang.model.type.TypeVariable,AnnotatedTypeMirror> substitutions)
Given a partial solution to our type argument inference, replace any uses of type parameters that have been solved with their arguments.abstract TUConstraint
toTUConstraint()
Once AFConstraints are irreducible it can be converted to a TU constraint, constraints between individual type parameters for which we are inferring an argument (T) and Java types (U).
-
-
-
Field Detail
-
argument
public final AnnotatedTypeMirror argument
The argument type.
-
formalParameter
public final AnnotatedTypeMirror formalParameter
The formal parameter type.
-
-
Constructor Detail
-
AFConstraint
protected AFConstraint(AnnotatedTypeMirror argument, AnnotatedTypeMirror formalParameter)
Create a constraint for type arguments for a method invocation or new class invocation.
-
-
Method Detail
-
isIrreducible
public boolean isIrreducible(java.util.Set<javax.lang.model.type.TypeVariable> targets)
Returns true if this constraint can't be broken up into other constraints or further simplified. In general, if either argument or formal parameter is a use of the type parameters we are inferring over then the constraint cannot be reduced further.- Parameters:
targets
- the type parameters whose arguments we are trying to solve for- Returns:
- true if this constraint can't be broken up into other constraints or further simplified
-
equals
public boolean equals(@Nullable java.lang.Object thatObject)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toTUConstraint
public abstract TUConstraint toTUConstraint()
Once AFConstraints are irreducible it can be converted to a TU constraint, constraints between individual type parameters for which we are inferring an argument (T) and Java types (U).- Returns:
- a TUConstraint that represents this AFConstraint
-
substitute
public AFConstraint substitute(java.util.Map<javax.lang.model.type.TypeVariable,AnnotatedTypeMirror> substitutions)
Given a partial solution to our type argument inference, replace any uses of type parameters that have been solved with their arguments.That is: Let S be a partial solution to our inference (i.e. we have inferred type arguments for some types) Let S be a map
(T0 => A0, T1 => A1, ..., TN => AN)
where Ti is a type parameter and Ai is its solved argument. For all uses of Ti in this constraint, replace them with Ai.For the mapping
(T0 => A0)
, the following constraint:ArrayList<T0> << List<T1>
Becomes:
ArrayList<A0> << List<T1>
A constraint:
T0 << T1
Becomes:
A0 << T1
- Parameters:
substitutions
- a mapping of target type parameter to the type argument to- Returns:
- a new constraint that contains no use of the keys in substitutions
-
construct
protected abstract AFConstraint construct(AnnotatedTypeMirror newArgument, AnnotatedTypeMirror newFormalParameter)
Used to create a new constraint of the same subclass of AFConstraint.
-
-