Class SupertypesSolver


  • public class SupertypesSolver
    extends java.lang.Object
    Infers type arguments by using the Least Upper Bound computation on the supertype relationships in a constraint map.
    • Constructor Detail

      • SupertypesSolver

        public SupertypesSolver()
    • Method Detail

      • solveFromSupertypes

        public InferenceResult solveFromSupertypes​(java.util.Set<javax.lang.model.type.TypeVariable> remainingTargets,
                                                   ConstraintMap constraintMap,
                                                   AnnotatedTypeFactory typeFactory)
        Infers type arguments using supertype constraints.
        Parameters:
        remainingTargets - targets for which we still need to infer a value
        constraintMap - the set of constraints for all targets
        Returns:
        a mapping from target to inferred type. Note this class always infers concrete types and will not infer that the target is equivalent to another target.
      • mergeLubTypeWithEqualities

        protected @Nullable InferredValue.InferredType mergeLubTypeWithEqualities​(javax.lang.model.type.TypeVariable target,
                                                                                  AnnotatedTypeMirror lub,
                                                                                  ConstraintMap constraintMap,
                                                                                  AnnotatedTypeFactory typeFactory)
        We previously found a type that is equal to target but not in all hierarchies. Use the primary annotations from the lub type to fill in the missing annotations in this type. Use that type as the inferred argument.

        If we failed to infer any annotation for a given hierarchy, either previously from equalities or from the lub, return null.

      • mergeLubAnnosWithEqualities

        protected @Nullable InferredValue.InferredType mergeLubAnnosWithEqualities​(javax.lang.model.type.TypeVariable target,
                                                                                   AnnotationMirrorMap<javax.lang.model.element.AnnotationMirror> lubAnnos,
                                                                                   ConstraintMap constraintMap,
                                                                                   AnnotatedTypeFactory typeFactory)
        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.

        If we failed to infer any annotation for a given hierarchy, either previously from equalities or from the lub, return null.

      • propagatePreviousLubs

        protected static void propagatePreviousLubs​(TargetConstraints targetRecord,
                                                    org.checkerframework.framework.util.typeinference.solver.SupertypesSolver.Lubs solution,
                                                    java.util.Map<AnnotatedTypeMirror,​AnnotationMirrorSet> subtypesOfTarget)
        If the target corresponding to targetRecord must be a supertype of another target for which we have already determined a lub, add that target's lub to this list.
      • groundMissingHierarchies

        public static AnnotatedTypeMirror groundMissingHierarchies​(java.util.Map.Entry<AnnotatedTypeMirror,​AnnotationMirrorSet> typeToHierarchies,
                                                                   AnnotationMirrorMap<javax.lang.model.element.AnnotationMirror> lowerBoundAnnos)
        For each type in typeToHierarchies, if that type does not have a corresponding annotation for a given hierarchy replace it with the corresponding value in lowerBoundAnnos.