use of org.checkerframework.framework.util.typeinference.solver.InferredValue.InferredType in project checker-framework by typetools.
the class SupertypesSolver method mergeLubAnnosWithEqualities.
/**
* We previously found a type that is equal to target but not in all hierarchies. Use the
* primary annotations from the lub annos to fill in the missing annotations in this type. Use
* that type as the inferred argument.
*
* <p>If we failed to infer any annotation for a given hierarchy, either previously from
* equalities or from the lub, return null.
*/
protected InferredType mergeLubAnnosWithEqualities(final TypeVariable target, final AnnotationMirrorMap<AnnotationMirror> lubAnnos, final ConstraintMap constraintMap, final AnnotatedTypeFactory typeFactory) {
final Equalities equalities = constraintMap.getConstraints(target).equalities;
final AnnotationMirrorSet tops = new AnnotationMirrorSet(typeFactory.getQualifierHierarchy().getTopAnnotations());
if (!equalities.types.isEmpty()) {
// there should be only equality type if any at this point
final Entry<AnnotatedTypeMirror, AnnotationMirrorSet> eqEntry = equalities.types.entrySet().iterator().next();
final AnnotatedTypeMirror equalityType = eqEntry.getKey();
final AnnotationMirrorSet equalityAnnos = eqEntry.getValue();
boolean failed = false;
for (final AnnotationMirror top : tops) {
if (!equalityAnnos.contains(top)) {
final AnnotationMirror lubAnno = lubAnnos.get(top);
if (lubAnno == null) {
failed = true;
} else {
equalityType.replaceAnnotation(lubAnno);
equalityAnnos.add(top);
}
}
}
if (!failed) {
return new InferredType(equalityType);
}
}
return null;
}
Aggregations