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 top qualifier
-
Field Summary
Modifier and TypeFieldDescriptionprotected final AnnotatedTypeFactory
Annotated 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 ofqualHierarchy
to the top qualifier of that hierarchy.protected final QualifierHierarchy
The qualifier hierarchy to use.protected final AnnotationMirrorSet
The qualifiers at the top ofqualHierarchy
. -
Constructor Summary
ModifierConstructorDescriptionprotected
Creates anAbstractQualifierPolymorphism
instance that uses the given checker for querying type qualifiers and the given factory for getting annotated types. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract AnnotationMirror
combine
(AnnotationMirror polyQual, AnnotationMirror a1, AnnotationMirror a2) Returns annotation that is the combination of the two annotations.boolean
Returns true iftype
has any polymorphic qualifiersprotected abstract void
replace
(AnnotatedTypeMirror type, AnnotationMirrorMap<AnnotationMirror> replacements) Replaces the top-level polymorphic annotations intype
with the instantiations inreplacements
.protected void
reset()
Reset to allow reuse of the same instance.void
Resolves polymorphism annotations for the given type.void
Resolves polymorphism annotations for the given type.void
resolve
(VariableElement field, AnnotatedTypeMirror owner, AnnotatedTypeMirror type) Resolves polymorphism annotations for the given field type.void
resolve
(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 ofqualHierarchy
to 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 anAbstractQualifierPolymorphism
instance 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:QualifierPolymorphism
Returns true iftype
has any polymorphic qualifiers- Specified by:
hasPolymorphicQualifiers
in interfaceQualifierPolymorphism
- 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 interfaceQualifierPolymorphism
- Parameters:
tree
- the tree associated with the typetype
- the type to annotate
-
resolve
Description copied from interface:QualifierPolymorphism
Resolves polymorphism annotations for the given type.- Specified by:
resolve
in interfaceQualifierPolymorphism
- Parameters:
tree
- the tree associated with the typetype
- the type to annotate; is side-effected by this method
-
resolve
Description copied from interface:QualifierPolymorphism
Resolves polymorphism annotations for the given field type.- Specified by:
resolve
in 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:QualifierPolymorphism
Resolves polymorphism annotations for the given type.- Specified by:
resolve
in interfaceQualifierPolymorphism
- Parameters:
functionalInterface
- the function type ofmemberReference
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 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 whicha1
anda2
are instantiationsa1
- an annotation that is an instantiation ofpolyQual
a2
- 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 intype
with 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
-