Class AbstractQualifierPolymorphism

java.lang.Object
org.checkerframework.framework.type.poly.AbstractQualifierPolymorphism
All Implemented Interfaces:
QualifierPolymorphism
Direct Known Subclasses:
DefaultQualifierPolymorphism

public abstract class AbstractQualifierPolymorphism extends Object implements QualifierPolymorphism
Implements framework support for qualifier polymorphism.

DefaultQualifierPolymorphism implements the abstract methods in this class. Subclasses can alter the way instantiations of polymorphic qualifiers are combined.

An "instantiation" is a mapping from declaration type to use-site type — that is, a mapping from @Poly* to concrete qualifiers.

The implementation performs these steps:

  • the PolyCollector creates an instantiation
  • if the instantiation is non-empty: the Replacer does resolution -- that is, it replaces each occurrence of @Poly* by the concrete qualifier it maps to in the instantiation
  • if the instantiation is empty, the Completer replaces each @Poly* by the top qualifier
  • Field Details

    • atypeFactory

      protected final AnnotatedTypeFactory atypeFactory
      Annotated type factory.
    • qualHierarchy

      protected final QualifierHierarchy qualHierarchy
      The qualifier hierarchy to use.
    • polyQuals

      protected final AnnotationMirrorMap<AnnotationMirror> polyQuals
      The polymorphic qualifiers: mapping from a polymorphic qualifier of qualHierarchy to the top qualifier of that hierarchy.
    • topQuals

      protected final AnnotationMirrorSet topQuals
      The qualifiers at the top of qualHierarchy. These are the values in polyQuals.
    • polyInstantiationForQualifierParameter

      protected final AnnotationMirrorMap<AnnotationMirror> polyInstantiationForQualifierParameter
      Mapping from poly qualifier to its instantiation for types with a qualifier parameter.
    • polyScanner

      protected final SimpleAnnotatedTypeScanner<Boolean,Void> polyScanner
      The visit method returns true if the passed type has any polymorphic qualifiers.
  • Constructor Details

    • AbstractQualifierPolymorphism

      protected AbstractQualifierPolymorphism(ProcessingEnvironment env, AnnotatedTypeFactory factory)
      Creates an AbstractQualifierPolymorphism instance that uses the given checker for querying type qualifiers and the given factory for getting annotated types. Subclasses need to add polymorphic qualifiers to this.polyQuals.
      Parameters:
      env - the processing environment
      factory - the factory for the current checker
  • Method Details

    • reset

      protected void reset()
      Reset to allow reuse of the same instance. Subclasses should override this method. The overriding implementation should clear its additional state and then call the super implementation.
    • hasPolymorphicQualifiers

      protected boolean hasPolymorphicQualifiers(AnnotatedTypeMirror type)
      Returns true if type has any polymorphic qualifiers
      Parameters:
      type - a type that might have polymorphic qualifiers
      Returns:
      true if type has any polymorphic qualifiers
    • resolve

      Resolves polymorphism annotations for the given type.
      Specified by:
      resolve in interface QualifierPolymorphism
      Parameters:
      tree - the tree associated with the type
      type - the type to annotate
    • resolve

      public void resolve(NewClassTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type)
      Description copied from interface: QualifierPolymorphism
      Resolves polymorphism annotations for the given type.
      Specified by:
      resolve in interface QualifierPolymorphism
      Parameters:
      tree - the tree associated with the type
      type - the type to annotate; is side-effected by this method
    • resolve

      public void resolve(VariableElement field, AnnotatedTypeMirror owner, AnnotatedTypeMirror type)
      Description copied from interface: QualifierPolymorphism
      Resolves polymorphism annotations for the given field type.
      Specified by:
      resolve in interface QualifierPolymorphism
      Parameters:
      field - field element to whose poly annotation must be resolved
      owner - the type of the object whose field is being typed
      type - type of the field which still has poly annotations
    • resolve

      public void resolve(AnnotatedTypeMirror.AnnotatedExecutableType functionalInterface, AnnotatedTypeMirror.AnnotatedExecutableType memberReference)
      Description copied from interface: QualifierPolymorphism
      Resolves polymorphism annotations for the given type.
      Specified by:
      resolve in interface QualifierPolymorphism
      Parameters:
      functionalInterface - the function type of memberReference
      memberReference - the type of a member reference; is side-effected by this method
    • combine

      protected abstract AnnotationMirror combine(AnnotationMirror polyQual, AnnotationMirror a1, AnnotationMirror a2)
      Returns annotation that is the combination of the two annotations. The annotations are instantiations for polyQual.

      The combination is typically their least upper bound. (It could be the GLB in the case that all arguments to a polymorphic method must have the same annotation.)

      Parameters:
      polyQual - polymorphic qualifier for which a1 and a2 are instantiations
      a1 - an annotation that is an instantiation of polyQual
      a2 - an annotation that is an instantiation of polyQual
      Returns:
      an annotation that is the combination of the two annotations
    • replace

      protected abstract void replace(AnnotatedTypeMirror type, AnnotationMirrorMap<AnnotationMirror> replacements)
      Replaces the top-level polymorphic annotations in type with the instantiations in replacements.

      This method is called on all parts of a type.

      Parameters:
      type - the AnnotatedTypeMirror whose poly annotations are replaced; it is side-effected by this method
      replacements - a mapping from polymorphic annotation to instantiation