Search in sources :

Example 1 with ConstraintMap

use of org.checkerframework.framework.util.typeinference.solver.ConstraintMap in project checker-framework by typetools.

the class DefaultTypeArgumentInference method inferFromAssignment.

/**
 * The Second half of step 6. Use the assignment context to infer a result.
 */
private InferenceResult inferFromAssignment(final AnnotatedTypeMirror assignedTo, final AnnotatedTypeMirror boxedReturnType, final AnnotatedExecutableType methodType, final Set<AFConstraint> afArgumentConstraints, final InferenceResult inferredArgs, final Set<TypeVariable> targets, final AnnotatedTypeFactory typeFactory) {
    ConstraintMap assignmentConstraints = createAssignmentConstraints(assignedTo, boxedReturnType, methodType, afArgumentConstraints, inferredArgs.toAtmMap(), targets, typeFactory);
    InferenceResult equalitiesResult = equalitiesSolver.solveEqualities(targets, assignmentConstraints, typeFactory);
    Set<TypeVariable> remainingTargets = equalitiesResult.getRemainingTargets(targets, true);
    InferenceResult subtypesResult = subtypesSolver.solveFromSubtypes(remainingTargets, assignmentConstraints, typeFactory);
    equalitiesResult.mergeSubordinate(subtypesResult);
    return equalitiesResult;
}
Also used : TypeVariable(javax.lang.model.type.TypeVariable) AnnotatedTypeVariable(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable) ConstraintMap(org.checkerframework.framework.util.typeinference.solver.ConstraintMap) InferenceResult(org.checkerframework.framework.util.typeinference.solver.InferenceResult)

Example 2 with ConstraintMap

use of org.checkerframework.framework.util.typeinference.solver.ConstraintMap in project checker-framework by typetools.

the class DefaultTypeArgumentInference method inferFromArguments.

/**
 * Step 2. Infer type arguments from the equality (TisU) and the supertype (TSuperU) constraints
 * of the methods arguments.
 */
private Pair<InferenceResult, InferenceResult> inferFromArguments(final AnnotatedTypeFactory typeFactory, final Set<AFConstraint> afArgumentConstraints, final Set<TypeVariable> targets) {
    Set<TUConstraint> tuArgConstraints = afToTuConstraints(afArgumentConstraints, targets);
    addConstraintsBetweenTargets(tuArgConstraints, targets, false, typeFactory);
    ConstraintMap argConstraints = constraintMapBuilder.build(targets, tuArgConstraints, typeFactory);
    InferenceResult inferredFromArgEqualities = equalitiesSolver.solveEqualities(targets, argConstraints, typeFactory);
    Set<TypeVariable> remainingTargets = inferredFromArgEqualities.getRemainingTargets(targets, true);
    InferenceResult fromSupertypes = supertypesSolver.solveFromSupertypes(remainingTargets, argConstraints, typeFactory);
    InferenceResult fromSubtypes = subtypesSolver.solveFromSubtypes(remainingTargets, argConstraints, typeFactory);
    fromSupertypes.mergeSubordinate(fromSubtypes);
    return Pair.of(inferredFromArgEqualities, fromSupertypes);
}
Also used : TypeVariable(javax.lang.model.type.TypeVariable) AnnotatedTypeVariable(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable) ConstraintMap(org.checkerframework.framework.util.typeinference.solver.ConstraintMap) InferenceResult(org.checkerframework.framework.util.typeinference.solver.InferenceResult) TUConstraint(org.checkerframework.framework.util.typeinference.constraint.TUConstraint)

Example 3 with ConstraintMap

use of org.checkerframework.framework.util.typeinference.solver.ConstraintMap in project checker-framework by typetools.

the class DefaultTypeArgumentInference method inferFromAssignmentEqualities.

/**
 * Step 3. Infer type arguments from the equality constraints of the assignment context.
 */
private InferenceResult inferFromAssignmentEqualities(final AnnotatedTypeMirror assignedTo, final AnnotatedTypeMirror boxedReturnType, final Set<TypeVariable> targets, final AnnotatedTypeFactory typeFactory) {
    Set<FIsA> afInitialAssignmentConstraints = createInitialAssignmentConstraints(assignedTo, boxedReturnType, typeFactory, targets);
    Set<TUConstraint> tuInitialAssignmentConstraints = afToTuConstraints(afInitialAssignmentConstraints, targets);
    ConstraintMap initialAssignmentConstraints = constraintMapBuilder.build(targets, tuInitialAssignmentConstraints, typeFactory);
    return equalitiesSolver.solveEqualities(targets, initialAssignmentConstraints, typeFactory);
}
Also used : FIsA(org.checkerframework.framework.util.typeinference.constraint.FIsA) ConstraintMap(org.checkerframework.framework.util.typeinference.solver.ConstraintMap) TUConstraint(org.checkerframework.framework.util.typeinference.constraint.TUConstraint)

Aggregations

ConstraintMap (org.checkerframework.framework.util.typeinference.solver.ConstraintMap)3 TypeVariable (javax.lang.model.type.TypeVariable)2 AnnotatedTypeVariable (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable)2 TUConstraint (org.checkerframework.framework.util.typeinference.constraint.TUConstraint)2 InferenceResult (org.checkerframework.framework.util.typeinference.solver.InferenceResult)2 FIsA (org.checkerframework.framework.util.typeinference.constraint.FIsA)1