public class BasicAnnotatedTypeFactory<Checker extends BaseTypeChecker> extends AnnotatedTypeFactory
AnnotatedTypeFactory
to optionally use
flow-sensitive qualifier inference, qualifier polymorphism, implicit annotations
via ImplicitFor
, and user-specified defaults via DefaultQualifier
Flow
AnnotatedTypeFactory.InheritedFromClassAnnotator
Modifier and Type | Field and Description |
---|---|
protected Checker |
checker
The type checker to use.
|
protected QualifierDefaults |
defaults
to handle defaults specified by the user
|
protected Flow |
flow
Flow sensitive instance
|
protected static boolean |
FLOW_BY_DEFAULT
should use flow by default
|
protected QualifierPolymorphism |
poly
to handle any polymorphic types
|
protected TreeAnnotator |
treeAnnotator
to annotate types based on the given un-annotated types
|
protected TypeAnnotator |
typeAnnotator
to annotate types based on the given tree
|
protected boolean |
useFlow
Should use flow analysis?
|
elements, fromTreeCache, processingEnv, qualHierarchy, root, trees, types, uid, visitorState
Constructor and Description |
---|
BasicAnnotatedTypeFactory(Checker checker,
CompilationUnitTree root)
Creates a type factory for checking the given compilation unit with
respect to the given annotation.
|
BasicAnnotatedTypeFactory(Checker checker,
CompilationUnitTree root,
boolean useFlow)
Creates a type factory for checking the given compilation unit with
respect to the given annotation.
|
Modifier and Type | Method and Description |
---|---|
void |
annotateImplicit(Element elt,
AnnotatedTypeMirror type)
Adds implicit annotations to a type obtained from a
Element . |
void |
annotateImplicit(Tree tree,
AnnotatedTypeMirror type)
Adds implicit annotations to a type obtained from a
Tree . |
Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> |
constructorFromUse(NewClassTree tree)
Determines the
AnnotatedTypeMirror.AnnotatedExecutableType of a constructor
invocation. |
protected Flow |
createFlow(Checker checker,
CompilationUnitTree root,
Set<AnnotationMirror> flowQuals)
Returns a
Flow instance that performs flow sensitive analysis
to infer qualifiers on unqualified types. |
protected Set<AnnotationMirror> |
createFlowQualifiers(Checker checker)
Returns the set of annotations to be inferred in flow analysis
|
protected QualifierDefaults |
createQualifierDefaults()
Create
QualifierDefaults which handles user specified defaults |
protected QualifierPolymorphism |
createQualifierPolymorphism()
Creates
QualifierPolymorphism which supports
QualifierPolymorphism mechanism |
protected TreeAnnotator |
createTreeAnnotator(Checker checker)
Returns a
TreeAnnotator that adds annotations to a type based
on the contents of a tree. |
protected TypeAnnotator |
createTypeAnnotator(Checker checker)
Returns a
TypeAnnotator that adds annotations to a type based
on the content of the type itself. |
Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> |
methodFromUse(MethodInvocationTree tree)
Determines the type of the invoked method based on the passed method
invocation tree.
|
protected void |
postDirectSuperTypes(AnnotatedTypeMirror type,
List<? extends AnnotatedTypeMirror> supertypes)
A callback method for the AnnotatedTypeFactory subtypes to customize
directSuperTypes().
|
protected void |
postInit()
Actions that logically belong in the constructor, but need to run
after the subclass constructor has completed.
|
addAliasedAnnotation, addAliasedDeclAnnotation, aliasedAnnotation, annotateInheritedFromClass, canHaveAnnotatedTypeParameters, createLRUCache, declarationFromElement, fromClass, fromElement, fromElement, fromElement, fromExpression, fromMember, fromNewClass, fromTypeTree, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFromTypeTree, getAnnotationWithMetaAnnotation, getBoxedType, getCurrentClassTree, getCurrentClassType, getCurrentMethodReceiver, getDeclAnnotation, getDeclAnnotations, getDeclAnnotationTree, getDeclAnnotationWithMetaAnnotation, getDefaultedAnnotatedType, getElementUtils, getEnclosingType, getImplicitReceiverType, getPath, getProcessingEnv, getQualifierHierarchy, getReceiverType, getSelfType, getUnboxedType, getUninferredMethodTypeArgument, getVisitorState, isAnyEnclosingThisDeref, isMostEnclosingThisDeref, isSupportedQualifier, isWithinConstructor, postAsMemberOf, toAnnotatedType, toString, type, typeVariablesFromUse
protected Checker extends BaseTypeChecker checker
protected static boolean FLOW_BY_DEFAULT
protected final TypeAnnotator typeAnnotator
protected final TreeAnnotator treeAnnotator
protected final QualifierPolymorphism poly
protected final QualifierDefaults defaults
protected boolean useFlow
protected Flow flow
public BasicAnnotatedTypeFactory(Checker checker, CompilationUnitTree root, boolean useFlow)
checker
- the checker to which this type factory belongsroot
- the compilation unit to scanuseFlow
- whether flow analysis should be performedpublic BasicAnnotatedTypeFactory(Checker checker, CompilationUnitTree root)
checker
- the checker to which this type factory belongsroot
- the compilation unit to scanprotected void postInit()
AnnotatedTypeFactory
postInit
in class AnnotatedTypeFactory
protected TreeAnnotator createTreeAnnotator(Checker checker)
TreeAnnotator
that adds annotations to a type based
on the contents of a tree.
Subclasses may override this method to specify more appriopriate
TreeAnnotator
protected TypeAnnotator createTypeAnnotator(Checker checker)
TypeAnnotator
that adds annotations to a type based
on the content of the type itself.protected Flow createFlow(Checker checker, CompilationUnitTree root, Set<AnnotationMirror> flowQuals)
Flow
instance that performs flow sensitive analysis
to infer qualifiers on unqualified types.checker
- the checkerroot
- the compilation unit associated with this factoryflowQuals
- the qualifiers to inferprotected QualifierDefaults createQualifierDefaults()
QualifierDefaults
which handles user specified defaultsprotected QualifierPolymorphism createQualifierPolymorphism()
QualifierPolymorphism
which supports
QualifierPolymorphism mechanismprotected void postDirectSuperTypes(AnnotatedTypeMirror type, List<? extends AnnotatedTypeMirror> supertypes)
AnnotatedTypeFactory
type
annotations to
supertypes
. This allows the type
and its supertypes
to have the qualifiers, e.g. the supertypes of an Immutable
type are also Immutable
.postDirectSuperTypes
in class AnnotatedTypeFactory
type
- the type whose supertypes are desiredsupertypes
- the supertypes as specified by the base AnnotatedTypeFactorypublic void annotateImplicit(Tree tree, AnnotatedTypeMirror type)
AnnotatedTypeFactory
Tree
. By
default, this method does nothing. Subclasses should use this method to
implement implicit annotations specific to their type systems.annotateImplicit
in class AnnotatedTypeFactory
tree
- an AST nodetype
- the type obtained from tree
public void annotateImplicit(Element elt, AnnotatedTypeMirror type)
AnnotatedTypeFactory
Element
. By
default, this method does nothing. Subclasses should use this method to
implement implicit annotations specific to their type systems.annotateImplicit
in class AnnotatedTypeFactory
elt
- an elementtype
- the type obtained from elt
public Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> methodFromUse(MethodInvocationTree tree)
AnnotatedTypeFactory
AnnotatedTypes#asMemberOf(AnnotatedTypeMirror, Element)
, and
customization based on receiver type should be in accordance to its
specification.
The return type is a pair of the type of the invoked method and
the (inferred) type arguments.
Note that neither the explicitly passed nor the inferred type arguments
are guaranteed to be subtypes of the corresponding upper bounds.
See method
BaseTypeVisitor.checkTypeArguments(Tree, List, List, List)
for the checks of type argument well-formedness.
Note that "this" and "super" constructor invocations are also handled by this
method. Method constructorFromUse
is only used for a constructor invocation
in a "new" expression.methodFromUse
in class AnnotatedTypeFactory
tree
- the method invocation treepublic Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> constructorFromUse(NewClassTree tree)
AnnotatedTypeFactory
AnnotatedTypeMirror.AnnotatedExecutableType
of a constructor
invocation. Note that this is different than calling
AnnotatedTypeFactory.getAnnotatedType(Tree)
or
AnnotatedTypeFactory.fromExpression(ExpressionTree)
on the constructor invocation;
those determine the type of the result of invoking the
constructor, which is probably an AnnotatedTypeMirror.AnnotatedDeclaredType
.
TODO: Should the result of getAnnotatedType be the return type
from the AnnotatedExecutableType computed here?
Note that "this" and "super" constructor invocations are handled by
method methodFromUse
. This method only handles constructor invocations
in a "new" expression.constructorFromUse
in class AnnotatedTypeFactory
tree
- the constructor invocation treeprotected Set<AnnotationMirror> createFlowQualifiers(Checker checker)