Class AbstractQualifierPolymorphism
java.lang.Object
org.checkerframework.framework.type.poly.AbstractQualifierPolymorphism
- All Implemented Interfaces:
QualifierPolymorphism
- Direct Known Subclasses:
DefaultQualifierPolymorphism
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 bottom qualifier
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AnnotatedTypeFactoryAnnotated type factory.protected final SimpleAnnotatedTypeScanner<Boolean, Void> The visit method returns true if the passed type has any polymorphic qualifiers.protected final AnnotationMirrorMap<AnnotationMirror> Mapping from poly qualifier to its instantiation for types with a qualifier parameter.protected final AnnotationMirrorMap<AnnotationMirror> The polymorphic qualifiers: mapping from a polymorphic qualifier ofqualHierarchyto the top qualifier of that hierarchy.protected final QualifierHierarchyThe qualifier hierarchy to use.protected final AnnotationMirrorSetThe qualifiers at the top ofqualHierarchy. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates anAbstractQualifierPolymorphisminstance that uses the given checker for querying type qualifiers and the given factory for getting annotated types. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract AnnotationMirrorcombine(AnnotationMirror polyQual, AnnotationMirror a1, AnnotationMirror a2) Returns annotation that is the combination of the two annotations.booleanReturns true iftypehas any polymorphic qualifiersprotected abstract voidreplace(AnnotatedTypeMirror type, AnnotationMirrorMap<AnnotationMirror> replacements) Replaces the top-level polymorphic annotations intypewith the instantiations inreplacements.protected voidreset()Reset to allow reuse of the same instance.voidResolves polymorphism annotations for the given type.voidResolves polymorphism annotations for the given type.voidresolve(VariableElement field, AnnotatedTypeMirror owner, AnnotatedTypeMirror type) Resolves polymorphism annotations for the given field type.voidresolve(AnnotatedTypeMirror.AnnotatedExecutableType functionalInterface, AnnotatedTypeMirror.AnnotatedExecutableType memberReference) Resolves polymorphism annotations for the given type.
-
Field Details
-
atypeFactory
Annotated type factory. -
qualHierarchy
The qualifier hierarchy to use. -
polyQuals
The polymorphic qualifiers: mapping from a polymorphic qualifier ofqualHierarchyto the top qualifier of that hierarchy. -
topQuals
The qualifiers at the top ofqualHierarchy. These are the values inpolyQuals. -
polyInstantiationForQualifierParameter
Mapping from poly qualifier to its instantiation for types with a qualifier parameter. -
hasPolyScanner
The visit method returns true if the passed type has any polymorphic qualifiers.
-
-
Constructor Details
-
AbstractQualifierPolymorphism
Creates anAbstractQualifierPolymorphisminstance that uses the given checker for querying type qualifiers and the given factory for getting annotated types. Subclasses need to add polymorphic qualifiers tothis.polyQuals.- Parameters:
env- the processing environmentfactory- 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
Description copied from interface:QualifierPolymorphismReturns true iftypehas any polymorphic qualifiers- Specified by:
hasPolymorphicQualifiersin interfaceQualifierPolymorphism- Parameters:
type- a type that might have polymorphic qualifiers- Returns:
- true if
typehas any polymorphic qualifiers
-
resolve
Resolves polymorphism annotations for the given type.- Specified by:
resolvein interfaceQualifierPolymorphism- Parameters:
tree- the tree associated with the typetype- the type to annotate
-
resolve
Description copied from interface:QualifierPolymorphismResolves polymorphism annotations for the given type.- Specified by:
resolvein interfaceQualifierPolymorphism- Parameters:
tree- the tree associated with the typetype- the type to annotate; is side-effected by this method
-
resolve
Description copied from interface:QualifierPolymorphismResolves polymorphism annotations for the given field type.- Specified by:
resolvein interfaceQualifierPolymorphism- Parameters:
field- field element to whose poly annotation must be resolvedowner- the type of the object whose field is being typedtype- type of the field which still has poly annotations
-
resolve
public void resolve(AnnotatedTypeMirror.AnnotatedExecutableType functionalInterface, AnnotatedTypeMirror.AnnotatedExecutableType memberReference) Description copied from interface:QualifierPolymorphismResolves polymorphism annotations for the given type.- Specified by:
resolvein interfaceQualifierPolymorphism- Parameters:
functionalInterface- the function type ofmemberReferencememberReference- 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 forpolyQual.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 whicha1anda2are instantiationsa1- an annotation that is an instantiation ofpolyQuala2- an annotation that is an instantiation ofpolyQual- 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 intypewith the instantiations inreplacements.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 methodreplacements- a mapping from polymorphic annotation to instantiation
-