public abstract class DefaultQualifiedTypeFactory<Q> extends Object implements QualifiedTypeFactory<Q>
QualifiedTypeFactory
. Most type systems
should extend this class (or a subclass) instead of implementing QualifiedTypeFactory
directly.
This implementation decomposes the problem of type checking using several
helper classes:
AnnotationConverter
: Converts annotations written in the source
code into type qualifiers for use in type checking. TypeAnnotator
: A visitor for
ExtendedTypeMirror
s that
adds a qualifier to each component of the type, producing a QualifiedTypeMirror
. TreeAnnotator
: A visitor for Tree
s that computes the
qualified type of each AST node based on the qualified types of its
subnodes. QualifierHierarchy
: Used to perform subtyping checks between
two type qualifiers (independent of any Java types). TypeHierarchy
: Used to perform subtyping checks between two
QualifiedTypeMirror
s. TypeAnnotator
, TreeAnnotator
, and TypeHierarchy
. The type system must provide
implementations for AnnotationConverter
and QualifierHierarchy
.Constructor and Description |
---|
DefaultQualifiedTypeFactory(QualifierContext<Q> context) |
public DefaultQualifiedTypeFactory(QualifierContext<Q> context)
public final QualifiedTypeMirror<Q> getQualifiedType(Element element)
QualifiedTypeFactory
Element
.getQualifiedType
in interface QualifiedTypeFactory<Q>
public final QualifiedTypeMirror<Q> getQualifiedType(Tree tree)
QualifiedTypeFactory
getQualifiedType
in interface QualifiedTypeFactory<Q>
public final QualifiedTypeMirror<Q> getQualifiedTypeFromTypeTree(Tree typeTree)
QualifiedTypeFactory
Tree
form.getQualifiedTypeFromTypeTree
in interface QualifiedTypeFactory<Q>
public final QualifiedTypeParameterBounds<Q> getQualifiedTypeParameterBounds(ExtendedParameterDeclaration etm)
QualifiedTypeFactory
Element
.getQualifiedTypeParameterBounds
in interface QualifiedTypeFactory<Q>
protected QualifiedTypeParameterBounds<Q> computeQualifiedTypeParameterBounds(ExtendedParameterDeclaration etm)
TypeAnnotator
.protected TreeAnnotator<Q> createTreeAnnotator()
TreeAnnotator
to be used by this type factory.
Checkers that need custom TreeAnnotator
behavior should
override this method to return an instance of their custom TreeAnnotator
subclass.protected TypeAnnotator<Q> createTypeAnnotator()
TypeAnnotator
to be used by this type factory.
Checkers that need custom TypeAnnotator
behavior should
override this method to return an instance of their custom TypeAnnotator
subclass.public final QualifiedTypes<Q> getQualifiedTypes()
QualifiedTypeFactory
QualifiedTypes
helper object used with this type
system.getQualifiedTypes
in interface QualifiedTypeFactory<Q>
protected QualifiedTypes<Q> createQualifiedTypes()
public QualifierHierarchy<Q> getQualifierHierarchy()
QualifiedTypeFactory
QualifierHierarchy
used with this type system.getQualifierHierarchy
in interface QualifiedTypeFactory<Q>
protected abstract QualifierHierarchy<Q> createQualifierHierarchy()
QualifierHierarchy
for the current type system.
Every checker must override this method to return an appropriate QualifierHierarchy
subclass for that checker.public TypeHierarchy<Q> getTypeHierarchy()
QualifiedTypeFactory
TypeHierarchy
used with this type system.getTypeHierarchy
in interface QualifiedTypeFactory<Q>
protected TypeHierarchy<Q> createTypeHierarchy(QualifierHierarchy<Q> qualifierHierarchy)
TypeHierarchy
for the current type system. The
default implementation constructs a DefaultTypeHierarchy
.qualifierHierarchy
- a reference to the QualifierHierarchy
used by this type systempublic AnnotationConverter<Q> getAnnotationConverter()
AnnotationConverter
for the current type system.protected abstract AnnotationConverter<Q> createAnnotationConverter()
AnnotationConverter
for the current type system.
Every checker must override this method to return an appropriate AnnotationConverter
subclass for that checker.public List<QualifiedTypeMirror<Q>> postDirectSuperTypes(QualifiedTypeMirror<Q> subtype, List<? extends QualifiedTypeMirror<Q>> supertypes)
QualifiedTypeFactory
directSuperTypes
.postDirectSuperTypes
in interface QualifiedTypeFactory<Q>
subtype
- the target of the directSuperTypes
callsupertypes
- the supertypes produced by the default
directSuperTypes
implementationsupertypes
after applying checker-specific
adjustmentspublic QualifiedTypeMirror<Q> postAsMemberOf(QualifiedTypeMirror<Q> memberType, QualifiedTypeMirror<Q> receiverType, Element memberElement)
QualifiedTypeFactory
asMemberOf
.postAsMemberOf
in interface QualifiedTypeFactory<Q>
memberType
- the type of the element being accessed, according to the default
asMemberOf
implementationreceiverType
- the type of the object instance whose element is being accessedmemberElement
- the element being accessedmemberType
after applying checker-specific
adjustmentspublic Pair<QualifiedTypeMirror.QualifiedExecutableType<Q>,List<QualifiedTypeMirror<Q>>> methodFromUse(MethodInvocationTree tree)
QualifiedTypeFactory
methodFromUse
in interface QualifiedTypeFactory<Q>
tree
- the AST node for the method callpublic Pair<QualifiedTypeMirror.QualifiedExecutableType<Q>,List<QualifiedTypeMirror<Q>>> methodFromUse(ExpressionTree tree, ExecutableElement methodElt, QualifiedTypeMirror<Q> receiverType)
methodFromUse
in interface QualifiedTypeFactory<Q>
QualifiedTypeFactory.methodFromUse(MethodInvocationTree)
public Pair<QualifiedTypeMirror.QualifiedExecutableType<Q>,List<QualifiedTypeMirror<Q>>> constructorFromUse(NewClassTree tree)
QualifiedTypeFactory
constructorFromUse
in interface QualifiedTypeFactory<Q>
tree
- the AST node for the constructor callpublic QualAnalysis<Q> createFlowAnalysis(List<Pair<VariableElement,QualValue<Q>>> fieldValues)
QualifiedTypeFactory
Analysis
to configure dataflow.createFlowAnalysis
in interface QualifiedTypeFactory<Q>
fieldValues
- the initial field valuesQualAnalysis
to usepublic QualifierContext<Q> getContext()
public QualifiedTypeMirror<Q> getReceiverType(ExpressionTree expression)
QualifiedTypeFactory
getReceiverType
in interface QualifiedTypeFactory<Q>
expression
- the expression for which to determine the receiver typepublic ExtendedTypeMirror getDecoratedElement(Element element)
QualifiedTypeFactory
ExtendedTypeMirror
for an Element
that has all the Annotations
that were located on the element in source code or in stub files.getDecoratedElement
in interface QualifiedTypeFactory<Q>
element
- the Element
ExtendedTypeMirror
public TypeVariableSubstitutor<Q> createTypeVariableSubstitutor()
createTypeVariableSubstitutor
in interface QualifiedTypeFactory<Q>
public Set<AnnotationMirror> getDeclAnnotations(Element elt)
getDeclAnnotations
in interface QualifiedTypeFactory<Q>