Class AbstractQualifierPolymorphism
- java.lang.Object
-
- org.checkerframework.framework.type.poly.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 arecombined
.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
Fields Modifier and Type Field Description protected AnnotatedTypeFactory
atypeFactory
Annotated type factory.protected AnnotationMirrorMap<javax.lang.model.element.AnnotationMirror>
polyInstantiationForQualifierParameter
Mapping from poly qualifier to its instantiation for types with a qualifier parameter.protected AnnotationMirrorMap<javax.lang.model.element.AnnotationMirror>
polyQuals
The polymorphic qualifiers: mapping from a polymorphic qualifier ofqualHierarchy
to the top qualifier of that hierarchy.protected SimpleAnnotatedTypeScanner<java.lang.Boolean,java.lang.Void>
polyScanner
The visit method returns true if the passed type has any polymorphic qualifiers.protected QualifierHierarchy
qualHierarchy
The qualifier hierarchy to use.protected AnnotationMirrorSet
topQuals
The qualifiers at the top ofqualHierarchy
.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractQualifierPolymorphism(javax.annotation.processing.ProcessingEnvironment env, AnnotatedTypeFactory factory)
Creates anAbstractQualifierPolymorphism
instance that uses the given checker for querying type qualifiers and the given factory for getting annotated types.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.protected boolean
hasPolymorphicQualifiers(AnnotatedTypeMirror type)
Returns true iftype
has any polymorphic qualifiersprotected abstract void
replace(AnnotatedTypeMirror type, AnnotationMirrorMap<javax.lang.model.element.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
resolve(com.sun.source.tree.MethodInvocationTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type)
Resolves polymorphism annotations for the given type.void
resolve(com.sun.source.tree.NewClassTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type)
Resolves polymorphism annotations for the given type.void
resolve(javax.lang.model.element.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 Detail
-
atypeFactory
protected final AnnotatedTypeFactory atypeFactory
Annotated type factory.
-
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 ofqualHierarchy
to the top qualifier of that hierarchy.
-
topQuals
protected final AnnotationMirrorSet topQuals
The qualifiers at the top ofqualHierarchy
. These are the values inpolyQuals
.
-
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 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 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 iftype
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(com.sun.source.tree.MethodInvocationTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type)
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
public void resolve(com.sun.source.tree.NewClassTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type)
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
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 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 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 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<javax.lang.model.element.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
-
-