Class AbstractQualifierPolymorphism

  • All Implemented Interfaces:
    QualifierPolymorphism
    Direct Known Subclasses:
    DefaultQualifierPolymorphism

    public abstract class AbstractQualifierPolymorphism
    extends java.lang.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 Detail

      • qualHierarchy

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

        protected final AnnotationMirrorMap<javax.lang.model.element.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<javax.lang.model.element.AnnotationMirror> polyInstantiationForQualifierParameter
        Mapping from poly qualifier to its instantiation for types with a qualifier parameter.
      • polyScanner

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

      • AbstractQualifierPolymorphism

        protected AbstractQualifierPolymorphism​(javax.annotation.processing.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 Detail

      • 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

        public void resolve​(javax.lang.model.element.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
      • combine

        protected abstract javax.lang.model.element.AnnotationMirror combine​(javax.lang.model.element.AnnotationMirror polyQual,
                                                                             javax.lang.model.element.AnnotationMirror a1,
                                                                             javax.lang.model.element.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<javax.lang.model.element.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