Search in sources :

Example 1 with SubtypeOfBound

use of com.github.javaparser.symbolsolver.resolution.typeinference.bounds.SubtypeOfBound in project javaparser by javaparser.

the class TypeInference method boundSetup.

// /
// / Private instance methods
// /
/**
 * When inference begins, a bound set is typically generated from a list of type parameter declarations P1, ..., Pp
 * and associated inference variables α1, ..., αp
 *
 * @param typeParameterDeclarations
 * @param inferenceVariables
 * @return
 */
private BoundSet boundSetup(List<ResolvedTypeParameterDeclaration> typeParameterDeclarations, List<InferenceVariable> inferenceVariables) {
    if (typeParameterDeclarations.size() != inferenceVariables.size()) {
        throw new IllegalArgumentException();
    }
    // When inference begins, a bound set is typically generated from a list of
    // type parameter declarations P1, ..., Pp and associated inference variables α1, ..., αp.
    // Such a bound set is constructed as follows. For each l (1 ≤ l ≤ p):
    BoundSet boundSet = BoundSet.empty();
    for (int l = 0; l < typeParameterDeclarations.size(); l++) {
        ResolvedTypeParameterDeclaration Pl = typeParameterDeclarations.get(l);
        InferenceVariable alphaL = inferenceVariables.get(l);
        if (Pl.getBounds().isEmpty()) {
            boundSet = boundSet.withBound(new SubtypeOfBound(alphaL, object));
        } else {
            for (ResolvedTypeParameterDeclaration.Bound bound : Pl.getBounds()) {
                ResolvedType T = bound.getType();
                Substitution substitution = Substitution.empty();
                for (int j = 0; j < typeParameterDeclarations.size(); j++) {
                    substitution = substitution.withPair(typeParameterDeclarations.get(j), inferenceVariables.get(j));
                }
                ResolvedType TWithSubstitutions = substitution.apply(T);
                boundSet = boundSet.withBound(new SubtypeOfBound(alphaL, TWithSubstitutions));
                if (boundSet.getProperUpperBoundsFor(alphaL).isEmpty()) {
                    boundSet = boundSet.withBound(new SubtypeOfBound(alphaL, object));
                }
            }
        }
    }
    return boundSet;
}
Also used : SubtypeOfBound(com.github.javaparser.symbolsolver.resolution.typeinference.bounds.SubtypeOfBound) ResolvedTypeParameterDeclaration(com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration) ResolvedType(com.github.javaparser.resolution.types.ResolvedType)

Aggregations

ResolvedTypeParameterDeclaration (com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration)1 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)1 SubtypeOfBound (com.github.javaparser.symbolsolver.resolution.typeinference.bounds.SubtypeOfBound)1