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?
|
annotations, atypes, elements, env, fromTreeCache, qualHierarchy, root, trees, types, uid, visitorState
Constructor and Description |
---|
BasicAnnotatedTypeFactory(Checker checker,
@Nullable CompilationUnitTree root)
Creates a type factory for checking the given compilation unit with
respect to the given annotation.
|
BasicAnnotatedTypeFactory(Checker checker,
@Nullable 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 |
---|---|
protected void |
annotateImplicit(@Nullable Element elt,
@Mutable AnnotatedTypeMirror type)
Adds implicit annotations to a type obtained from a
Element . |
protected void |
annotateImplicit(@Nullable Tree tree,
@Mutable AnnotatedTypeMirror type)
Adds implicit annotations to a type obtained from a
Tree . |
protected void |
annotateImplicit(@Nullable Tree tree,
@Mutable AnnotatedTypeMirror type,
boolean iUseFlow) |
Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<@Mutable AnnotatedTypeMirror>> |
constructorFromUse(NewClassTree tree)
Determines the
AnnotatedTypeMirror.AnnotatedExecutableType of a constructor
invocation. |
protected Flow |
createFlow(Checker checker,
@Nullable CompilationUnitTree root,
Set<@Nullable AnnotationMirror> flowQuals)
Returns a
Flow instance that performs flow sensitive analysis
to infer qualifiers on unqualified types. |
protected Set<@Nullable AnnotationMirror> |
createFlowQualifiers(Checker checker)
Returns the set of annotations to be inferred in flow analysis
|
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. |
@Mutable AnnotatedTypeMirror |
getDefaultedAnnotatedType(@Nullable Tree tree)
Get the defaulted type of a variable, without considering
flow inference from the initializer expression.
|
Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<@Mutable AnnotatedTypeMirror>> |
methodFromUse(MethodInvocationTree tree)
Determines the type of the invoked method based on the passed method
invocation tree.
|
protected void |
postDirectSuperTypes(@Mutable AnnotatedTypeMirror type,
List<? extends @Mutable 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, aliasedAnnotation, annotateInheritedFromClass, canHaveAnnotatedTypeParameters, createLRUCache, declarationFromElement, fromClass, fromElement, fromElement, fromElement, fromExpression, fromMember, fromNewClass, fromTypeTree, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFromTypeTree, getBoxedType, getCurrentClassTree, getCurrentClassType, getCurrentMethodReceiver, getDeclAnnotation, getEnclosingType, getImplicitReceiverType, getPath, getQualifierHierarchy, getReceiverType, getSelfType, getUnboxedType, getVisitorState, isAnyEnclosingThisDeref, isMostEnclosingThisDeref, isSupportedQualifier, isWithinConstructor, postAsMemberOf, toAnnotatedType, toString, typeVariablesFromUse, unify
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, @Nullable 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, @Nullable 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, @Nullable CompilationUnitTree root, Set<@Nullable 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 void postDirectSuperTypes(@Mutable AnnotatedTypeMirror type, List<? extends @Mutable 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 AnnotatedTypeFactoryprotected void annotateImplicit(@Nullable Tree tree, @Mutable AnnotatedTypeMirror type, boolean iUseFlow)
protected void annotateImplicit(@Nullable Tree tree, @Mutable 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 @Mutable AnnotatedTypeMirror getDefaultedAnnotatedType(@Nullable Tree tree)
AnnotatedTypeFactory
getDefaultedAnnotatedType
in class AnnotatedTypeFactory
protected void annotateImplicit(@Nullable Element elt, @Mutable 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<@Mutable 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.methodFromUse
in class AnnotatedTypeFactory
tree
- the method invocation treepublic Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<@Mutable 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?constructorFromUse
in class AnnotatedTypeFactory
tree
- the constructor invocation treeprotected Set<@Nullable AnnotationMirror> createFlowQualifiers(Checker checker)