Search in sources :

Example 11 with InferredType

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;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) InferredType(org.checkerframework.framework.util.typeinference.solver.InferredValue.InferredType) Equalities(org.checkerframework.framework.util.typeinference.solver.TargetConstraints.Equalities) AnnotationMirrorSet(org.checkerframework.framework.util.AnnotationMirrorSet) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Aggregations

InferredType (org.checkerframework.framework.util.typeinference.solver.InferredValue.InferredType)11 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)10 AnnotationMirrorSet (org.checkerframework.framework.util.AnnotationMirrorSet)7 AnnotationMirror (javax.lang.model.element.AnnotationMirror)5 TypeVariable (javax.lang.model.type.TypeVariable)5 AnnotatedTypeVariable (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable)3 Equalities (org.checkerframework.framework.util.typeinference.solver.TargetConstraints.Equalities)3 QualifierHierarchy (org.checkerframework.framework.type.QualifierHierarchy)2 InferredValue (org.checkerframework.framework.util.typeinference.solver.InferredValue)2 InferredTarget (org.checkerframework.framework.util.typeinference.solver.InferredValue.InferredTarget)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Entry (java.util.Map.Entry)1 Types (javax.lang.model.util.Types)1 TypeHierarchy (org.checkerframework.framework.type.TypeHierarchy)1 InferenceResult (org.checkerframework.framework.util.typeinference.solver.InferenceResult)1 Subtypes (org.checkerframework.framework.util.typeinference.solver.TargetConstraints.Subtypes)1