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;
}
Aggregations