Class GenericAnnotatedTypeFactory<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value,Store>,TransferFunction extends CFAbstractTransfer<Value,Store,TransferFunction>,FlowAnalysis extends CFAbstractAnalysis<Value,Store,TransferFunction>>
- java.lang.Object
-
- org.checkerframework.framework.type.AnnotatedTypeFactory
-
- org.checkerframework.framework.type.GenericAnnotatedTypeFactory<Value,Store,TransferFunction,FlowAnalysis>
-
- All Implemented Interfaces:
AnnotationProvider
- Direct Known Subclasses:
AccumulationAnnotatedTypeFactory
,BaseAnnotatedTypeFactory
,InitializationParentAnnotatedTypeFactory
,KeyForAnnotatedTypeFactory
,LockAnnotatedTypeFactory
,NullnessNoInitAnnotatedTypeFactory
public abstract class GenericAnnotatedTypeFactory<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value,Store>,TransferFunction extends CFAbstractTransfer<Value,Store,TransferFunction>,FlowAnalysis extends CFAbstractAnalysis<Value,Store,TransferFunction>> extends AnnotatedTypeFactory
A factory that extendsAnnotatedTypeFactory
to optionally use flow-sensitive qualifier inference.It also adds other features: qualifier polymorphism, default annotations via
DefaultFor
, user-specified defaults viaDefaultQualifier
, standardization viaDependentTypesHelper
, etc. Those features, andaddComputedTypeAnnotations(com.sun.source.tree.Tree, org.checkerframework.framework.type.AnnotatedTypeMirror)
(other than the part related to flow-sensitivity), could and should be in the superclassAnnotatedTypeFactory
; it is not clear why they are defined in this class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
GenericAnnotatedTypeFactory.ScanState
Track the state of org.checkerframework.dataflow analysis scanning for each class tree in the compilation unit.-
Nested classes/interfaces inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
AnnotatedTypeFactory.ParameterizedExecutableType
-
-
Field Summary
Fields Modifier and Type Field Description protected FlowAnalysis
analysis
protected boolean
arraysAreRelevant
Whether users may write type annotations on arrays.protected CFGVisualizer<Value,Store,TransferFunction>
cfgVisualizer
The CFGVisualizer to be used by all CFAbstractAnalysis instances.protected ContractsFromMethod
contractsUtils
To handle method pre- and postconditions.protected QualifierDefaults
defaults
to handle defaults specified by the userprotected DependentTypesHelper
dependentTypesHelper
To handle dependent type annotations and contract expressions.protected Store
emptyStore
An empty store.protected java.util.IdentityHashMap<com.sun.source.tree.Tree,Store>
exceptionalExitStores
A mapping from methods (or other code blocks) to their exceptional exit store.protected static boolean
flowByDefault
Should flow be used by default?protected @MonotonicNonNull AnalysisResult<Value,Store>
flowResult
The result of the flow analysis.protected java.util.Map<TransferInput<Value,Store>,java.util.IdentityHashMap<Node,TransferResult<Value,Store>>>
flowResultAnalysisCaches
protected static java.util.regex.Pattern
formalParameterPattern
Matches parameter expressions as they appear inEnsuresQualifier
andRequiresQualifier
annotations, e.g.boolean
hasOrIsSubchecker
True if this checker either has one or more subcheckers, or if this checker is a subchecker.protected Store
initializationStaticStore
protected Store
initializationStore
protected QualifierPolymorphism
poly
to handle any polymorphic typesprotected java.util.IdentityHashMap<com.sun.source.tree.Tree,Store>
regularExitStores
A mapping from methods (or other code blocks) to their regular exit store (used to check postconditions).@Nullable java.util.Set<javax.lang.model.type.TypeMirror>
relevantJavaTypes
The Java types on which users may write this type system's type annotations.protected java.util.IdentityHashMap<com.sun.source.tree.MethodTree,java.util.List<org.plumelib.util.IPair<ReturnNode,TransferResult<Value,Store>>>>
returnStatementStores
A mapping from methods to a list with all return statements and the corresponding store.protected java.util.Map<com.sun.source.tree.ClassTree,GenericAnnotatedTypeFactory.ScanState>
scannedClasses
Map from ClassTree to their dataflow analysis state.protected boolean
shouldClearSubcheckerSharedCFGs
If true,setRoot(CompilationUnitTree)
should clear thesubcheckerSharedCFG
map, freeing memory.boolean
sideEffectsUnrefineAliases
Should the analysis assume that side effects to a value can change the type of aliased references?protected @MonotonicNonNull java.util.Map<com.sun.source.tree.Tree,ControlFlowGraph>
subcheckerSharedCFG
Subcheckers share the same ControlFlowGraph for each analyzed code statement.protected TransferFunction
transfer
protected TreeAnnotator
treeAnnotator
to annotate types based on the given un-annotated typesprotected TypeAnnotator
typeAnnotator
to annotate types based on the given tree-
Fields inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
ajavaTypes, annotatedForValueElement, checker, currentFileAjavaTypes, elements, ensuresQualifierExpressionElement, ensuresQualifierIfExpressionElement, ensuresQualifierIfListTM, ensuresQualifierIfListValueElement, ensuresQualifierIfResultElement, ensuresQualifierIfTM, ensuresQualifierListTM, ensuresQualifierListValueElement, ensuresQualifierTM, fieldInvariantFieldElement, fieldInvariantQualifierElement, fromExpressionTreeCache, fromMemberTreeCache, fromTypeTreeCache, hasQualifierParameterValueElement, ignoreUninferredTypeArguments, loader, methodValClassNameElement, methodValMethodNameElement, methodValParamsElement, noQualifierParameterValueElement, objectGetClass, processingEnv, qualHierarchy, qualifierUpperBounds, reflectionResolver, requiresQualifierExpressionElement, requiresQualifierListTM, requiresQualifierListValueElement, requiresQualifierTM, root, shouldCache, stubTypes, trees, typeArgumentInference, typeFormatter, typeHierarchy, types, typeVarSubstitutor, uid, viewpointAdapter
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
GenericAnnotatedTypeFactory(BaseTypeChecker checker)
Creates a type factory.protected
GenericAnnotatedTypeFactory(BaseTypeChecker checker, boolean useFlow)
Creates a type factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addAnnotationsFromDefaultForType(@Nullable javax.lang.model.element.Element element, AnnotatedTypeMirror type)
Adds default qualifiers based on the underlying type oftype
totype
.protected void
addCheckedCodeDefaults(QualifierDefaults defs)
Adds default qualifiers for type-checked code by readingDefaultFor
andDefaultQualifierInHierarchy
meta-annotations.protected void
addCheckedStandardDefaults(QualifierDefaults defs)
Adds the standard CLIMB defaults that do not conflict with previously added defaults.protected void
addComputedTypeAnnotations(com.sun.source.tree.Tree tree, AnnotatedTypeMirror type)
This method is final; overrideaddComputedTypeAnnotations(Tree, AnnotatedTypeMirror, boolean)
instead.protected void
addComputedTypeAnnotations(com.sun.source.tree.Tree tree, AnnotatedTypeMirror type, boolean iUseFlow)
void
addComputedTypeAnnotations(javax.lang.model.element.Element elt, AnnotatedTypeMirror type)
To add annotations to the type of method or constructor parameters, add aTypeAnnotator
usingcreateTypeAnnotator()
and see the comment inTypeAnnotator.visitExecutable(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType, Void)
.void
addDefaultAnnotations(AnnotatedTypeMirror type)
Adds default annotations totype
.boolean
addSharedCFGForTree(com.sun.source.tree.Tree tree, ControlFlowGraph cfg)
Add a new entry to the shared CFG.protected void
addUncheckedStandardDefaults(QualifierDefaults defs)
Adds standard unchecked defaults that do not conflict with previously added defaults.protected void
analyze(java.util.Queue<org.plumelib.util.IPair<com.sun.source.tree.ClassTree,Store>> classQueue, java.util.Queue<org.plumelib.util.IPair<com.sun.source.tree.LambdaExpressionTree,Store>> lambdaQueue, UnderlyingAST ast, java.util.List<CFAbstractAnalysis.FieldInitialValue<Value>> fieldValues, com.sun.source.tree.ClassTree currentClass, boolean isInitializationCode, boolean updateInitializationStore, boolean isStatic, @Nullable Store capturedStore)
Analyze the ASTast
and store the result.AnnotationMirrorSet
annotationsForIrrelevantJavaType(javax.lang.model.type.TypeMirror tm)
Returns the annotations that should appear on the given irrelevant Java type.protected void
applyInferredAnnotations(AnnotatedTypeMirror type, Value inferred)
Applies the annotations inferred by the org.checkerframework.dataflow analysis to the typetype
.protected void
applyQualifierParameterDefaults(@Nullable javax.lang.model.element.Element elt, AnnotatedTypeMirror type)
Applies defaults for types in a class with an qualifier parameter.protected void
applyQualifierParameterDefaults(com.sun.source.tree.Tree tree, AnnotatedTypeMirror type)
Applies defaults for types in a class with an qualifier parameter.protected void
checkAndPerformFlowAnalysis(com.sun.source.tree.Tree tree)
Flow analysis will be performed if all of the following are true.protected void
checkForDefaultQualifierInHierarchy(QualifierDefaults defs)
Check that a default qualifier (in at least one hierarchy) has been set and issue an error if not.AnnotatedTypeFactory.ParameterizedExecutableType
constructorFromUse(com.sun.source.tree.NewClassTree tree)
Determines the type of the invoked constructor based on the passed new class tree.protected void
constructorFromUsePreSubstitution(com.sun.source.tree.NewClassTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type)
A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared constructor type before type variable substitution.protected QualifierDefaults
createAndInitQualifierDefaults()
CreateQualifierDefaults
which handles checker specified defaults, and initialize the createdQualifierDefaults
.protected @Nullable CFGVisualizer<Value,Store,TransferFunction>
createCFGVisualizer()
Create a new CFGVisualizer.protected ContractsFromMethod
createContractsFromMethod()
Creates anContractsFromMethod
and returns it.protected DefaultForTypeAnnotator
createDefaultForTypeAnnotator()
Creates anDefaultForTypeAnnotator
.protected DefaultQualifierForUseTypeAnnotator
createDefaultForUseTypeAnnotator()
Creates anDefaultQualifierForUseTypeAnnotator
.protected DependentTypesHelper
createDependentTypesHelper()
Creates aDependentTypesHelper
and returns it.protected FlowAnalysis
createFlowAnalysis()
Returns the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis.TransferFunction
createFlowTransferFunction(CFAbstractAnalysis<Value,Store,TransferFunction> analysis)
Returns the appropriate transfer function that is used for the given org.checkerframework.dataflow analysis.protected QualifierDefaults
createQualifierDefaults()
CreateQualifierDefaults
which handles checker specified defaults.protected QualifierPolymorphism
createQualifierPolymorphism()
Creates theQualifierPolymorphism
instance which supports the QualifierPolymorphism mechanism.protected @Nullable javax.lang.model.element.AnnotationMirror
createRequiresOrEnsuresQualifier(java.lang.String expression, javax.lang.model.element.AnnotationMirror qualifier, AnnotatedTypeMirror declaredType, Analysis.BeforeOrAfter preOrPost, @Nullable java.util.List<javax.lang.model.element.AnnotationMirror> preconds)
Creates aRequiresQualifier("...")
orEnsuresQualifier("...")
annotation for the given expression.protected TreeAnnotator
createTreeAnnotator()
Returns aTreeAnnotator
that adds annotations to a type based on the contents of a tree.protected TypeAnnotator
createTypeAnnotator()
Returns aDefaultForTypeAnnotator
that adds annotations to a type based on the content of the type itself.AnnotatedTypeMirror
getAnnotatedTypeBefore(JavaExpression expr, com.sun.source.tree.ExpressionTree tree)
Returns the type of a JavaExpressionexpr
if it were evaluated before a treetree
.AnnotatedTypeMirror
getAnnotatedTypeLhs(com.sun.source.tree.Tree lhsTree)
Returns the type of a left-hand side of an assignment.AnnotatedTypeMirror
getAnnotatedTypeLhsNoTypeVarDefault(com.sun.source.tree.Tree lhsTree)
Returns the type of the left-hand side of an assignment without applying local variable defaults to type variables.AnnotatedTypeMirror
getAnnotatedTypeRhsUnaryAssign(com.sun.source.tree.UnaryTree tree)
Returns the type ofv + 1
orv - 1
wherev
is the expression in the postfixed increment or decrement expression.@Nullable AnnotatedTypeMirror
getAnnotatedTypeVarargsArray(com.sun.source.tree.Tree tree)
Returns the type of a varargs array of a method invocation or a constructor invocation.@Nullable javax.lang.model.element.AnnotationMirror
getAnnotationFromJavaExpression(JavaExpression expr, com.sun.source.tree.Tree tree, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the primary annotation on an expression, at a particular location.@Nullable javax.lang.model.element.AnnotationMirror
getAnnotationFromJavaExpressionString(java.lang.String expression, com.sun.source.tree.Tree tree, com.sun.source.util.TreePath path, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the primary annotation on expression if it were evaluated at path.@Nullable javax.lang.model.element.AnnotationMirror
getAnnotationMirrorFromJavaExpressionString(java.lang.String expression, com.sun.source.tree.Tree tree, com.sun.source.util.TreePath currentPath)
Returns the annotation mirror from dataflow forexpression
.@Nullable AnnotationMirrorSet
getAnnotationsFromJavaExpression(JavaExpression expr, com.sun.source.tree.Tree tree)
Returns the primary annotations on an expression, at a particular location.CFGVisualizer<Value,Store,TransferFunction>
getCFGVisualizer()
The CFGVisualizer to be used by all CFAbstractAnalysis instances.@Nullable java.util.List<java.lang.String>
getContractExpressions(Contract.Kind kind, javax.lang.model.element.AnnotationMirror contractAnnotation)
IfcontractAnnotation
is a framework annotation, return itsexpression
element.ContractsFromMethod
getContractsFromMethod()
Returns the helper for method pre- and postconditions.AnnotatedTypeMirror
getDefaultAnnotations(com.sun.source.tree.Tree tree, AnnotatedTypeMirror type)
Removes all primary annotations on a copy of the type and calculates the default annotations that apply to the copied type, without type refinements.DefaultForTypeAnnotator
getDefaultForTypeAnnotator()
Returns theDefaultForTypeAnnotator
.AnnotatedTypeMirror
getDefaultValueAnnotatedType(javax.lang.model.type.TypeMirror typeMirror)
Return the type of the default value of the given type.DependentTypesHelper
getDependentTypesHelper()
Returns the DependentTypesHelper.Store
getEmptyStore()
Returns the empty store.@Nullable java.lang.Boolean
getEnsuresQualifierIfResult(Contract.Kind kind, javax.lang.model.element.AnnotationMirror contractAnnotation)
If kind = CONDITIONALPOSTCONDITION, return the result element, e.g.@Nullable Store
getExceptionalExitStore(com.sun.source.tree.Tree tree)
Returns the exceptional exit store for a method or another code block (such as static initializers).AnnotationMirrorSet
getExplicitNewClassAnnos(com.sun.source.tree.NewClassTree newClassTree)
Returns the annotations explicitly written on a NewClassTree.protected java.util.List<AnnotatedTypeMirror>
getExplicitNewClassClassTypeArgs(com.sun.source.tree.NewClassTree newClassTree)
Returns the partially-annotated explicit class type arguments of the new class tree.org.plumelib.util.IPair<JavaExpression,java.lang.String>
getExpressionAndOffsetFromJavaExpressionString(java.lang.String expression, com.sun.source.util.TreePath currentPath)
Produces the JavaExpression and offset associated with an expression.java.util.Map<javax.lang.model.element.VariableElement,Value>
getFinalLocalValues()
Returns the value of effectively final local variables.<T extends Node>
@Nullable TgetFirstNodeOfKindForTree(com.sun.source.tree.Tree tree, java.lang.Class<T> kind)
@Nullable Value
getInferredValueFor(com.sun.source.tree.Tree tree)
Returns the inferred value (by the org.checkerframework.dataflow analysis) for a given tree.AnnotatedTypeMirror
getMethodReturnType(com.sun.source.tree.MethodTree m)
Returns the return type of the methodm
.java.util.Set<Node>
getNodesForTree(com.sun.source.tree.Tree tree)
QualifierPolymorphism
getQualifierPolymorphism()
Gives the currentQualifierPolymorphism
instance which supports the QualifierPolymorphism mechanism.@Nullable Store
getRegularExitStore(com.sun.source.tree.Tree tree)
Returns the regular exit store for a method or another code block (such as static initializers).AnnotatedTypeMirror
getResultingTypeOfConstructorMemberReference(com.sun.source.tree.MemberReferenceTree memberReferenceTree, AnnotatedTypeMirror.AnnotatedExecutableType constructorType)
Gets the type of the resulting constructor call of a MemberReferenceTree.java.util.List<org.plumelib.util.IPair<ReturnNode,TransferResult<Value,Store>>>
getReturnStatementStores(com.sun.source.tree.MethodTree methodTree)
Returns a list of all return statements ofmethod
paired with their correspondingTransferResult
.@Nullable ControlFlowGraph
getSharedCFGForTree(com.sun.source.tree.Tree tree)
Get the shared control flow graph used fortree
by this checker's topmost superchecker.boolean
getShouldDefaultTypeVarLocals()
Should the local variable default annotation be applied to type variables?protected java.lang.String
getSortedQualifierNames()
Creates and returns a string containing the number of qualifiers and the canonical class names of each qualifier that has been added to this checker's supported qualifier set.@Nullable Store
getStoreAfter(com.sun.source.tree.Tree tree)
Returns the store immediately after a given tree.Store
getStoreAfter(java.util.Set<Node> nodes)
Returns the store immediately after a given set of nodes.Store
getStoreAfter(Node node)
Returns the store immediately after a givenNode
.Store
getStoreBefore(com.sun.source.tree.Tree tree)
Returns the store immediately before a givenTree
.Store
getStoreBefore(java.util.Set<Node> nodes)
Returns the store immediately before a given Set ofNode
s.@Nullable Store
getStoreBefore(Node node)
Returns the store immediately before a given node.java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>>
getSupportedMonotonicTypeQualifiers()
Returns an immutable set of the monotonic type qualifiers supported by this checker.<T extends GenericAnnotatedTypeFactory<?,?,?,?>>
TgetTypeFactoryOfSubchecker(java.lang.Class<? extends BaseTypeChecker> subCheckerClass)
Returns the type factory used by a subchecker.<T extends GenericAnnotatedTypeFactory<?,?,?,?>>
@Nullable TgetTypeFactoryOfSubcheckerOrNull(java.lang.Class<? extends BaseTypeChecker> subCheckerClass)
Returns the type factory used by a subchecker.protected void
handleCFGViz(ControlFlowGraph cfg)
Handle the visualization of the CFG, if necessary.java.lang.String
irrelevantExtraMessage()
Returns a string that can be passed to the "anno.on.irrelevant" error, giving information about which types are relevant.boolean
isComputingAnnotatedTypeMirrorOfLhs()
Returns whethergetAnnotatedTypeLhs(Tree)
is running right now.boolean
isNotFullyInitializedReceiver(com.sun.source.tree.MethodTree methodDeclTree)
Returns true if the receiver of a method or constructor might not be fully initialized.boolean
isRelevant(javax.lang.model.type.TypeMirror tm)
Returns true if users can write type annotations from this type system directly on the given Java type.boolean
isRelevant(AnnotatedTypeMirror tm)
Returns true if users can write type annotations from this type system directly on the given Java type.protected boolean
isRelevantImpl(javax.lang.model.type.TypeMirror tm)
Returns true if users can write type annotations from this type system on the given Java type.AnnotatedTypeFactory.ParameterizedExecutableType
methodFromUse(com.sun.source.tree.MethodInvocationTree tree)
Determines the type of the invoked method based on the passed method invocation tree.void
methodFromUsePreSubstitution(com.sun.source.tree.ExpressionTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type)
A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared method type before type variable substitution.JavaExpression
parseJavaExpressionString(java.lang.String expression, com.sun.source.util.TreePath currentPath)
Produces the JavaExpression as ifexpression
were written atcurrentPath
.protected void
performFlowAnalysis(com.sun.source.tree.ClassTree classTree)
Perform a org.checkerframework.dataflow analysis over a single class tree and its nested classes.protected void
postAnalyze(ControlFlowGraph cfg)
Perform any additional operations on a CFG.void
postAsMemberOf(AnnotatedTypeMirror type, AnnotatedTypeMirror owner, javax.lang.model.element.Element element)
A callback method for the AnnotatedTypeFactory subtypes to customize AnnotatedTypes.asMemberOf().protected void
postDirectSuperTypes(AnnotatedTypeMirror type, java.util.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.void
preProcessClassTree(com.sun.source.tree.ClassTree classTree)
Performs flow-sensitive type refinement onclassTree
if this type factory is configured to do so.void
setRoot(@Nullable com.sun.source.tree.CompilationUnitTree root)
Set the CompilationUnitTree that should be used.java.util.List<AnnotatedTypeParameterBounds>
typeVariablesFromUse(AnnotatedTypeMirror.AnnotatedDeclaredType type, javax.lang.model.element.TypeElement element)
Adapt the upper bounds of the type variables of a class relative to the type instantiation.-
Methods inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
adaptGetClassReturnTypeToReceiver, addAliasedDeclAnnotation, addAliasedDeclAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, applyCaptureConversion, applyCaptureConversion, applyUnboxing, areSameByClass, binaryTreeArgTypes, binaryTreeArgTypes, binaryTreeArgTypes, canonicalAnnotation, compoundAssignmentTreeArgTypes, containsSameByClass, containsUninferredTypeArguments, createAnnotatedTypeFormatter, createAnnotationClassLoader, createAnnotationFormatter, createQualifierHierarchy, createQualifierUpperBounds, createSupportedTypeQualifiers, createTypeArgumentInference, createTypeHierarchy, createTypeVariableSubstitutor, createViewpointAdapter, declarationFromElement, doesAnnotatedForApplyToThisChecker, fromElement, fromElement, fromElement, fromNewClass, getAnnotatedNullType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFormatter, getAnnotatedTypeFromTypeTree, getAnnotationByClass, getAnnotationFormatter, getAnnotationMirror, getAnnotationOrTypeDeclarationBound, getAnnotationWithMetaAnnotation, getBoxedType, getBundledTypeQualifiers, getCacheSize, getChecker, getCheckerNames, getContractExpressions, getContractListValues, getCurrentClassTree, getCurrentMethodReceiver, getDeclAnnotation, getDeclAnnotationNoAliases, getDeclAnnotations, getDeclAnnotationWithMetaAnnotation, getDefaultTypeDeclarationBounds, getDummyAssignedTo, getElementUtils, getEnclosingClassOrMethod, getEnclosingSubType, getEnclosingType, getEnumConstructorQualifiers, getExpressionAndOffset, getFieldInvariantAnnotationTree, getFieldInvariantDeclarationAnnotations, getFieldInvariants, getFnInterfaceFromTree, getFunctionTypeFromTree, getFunctionTypeFromTree, getImplicitReceiverType, getIterableElementType, getIterableElementType, getMethodReturnType, getNarrowedAnnotations, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getQualifierParameterHierarchies, getQualifierParameterHierarchies, getQualifierUpperBounds, getReceiverType, getSelfType, getStringType, getSupportedTypeQualifierNames, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeDeclarationBounds, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, getUnboxedType, getUninferredWildcardType, getVisitorTreePath, getWidenedAnnotations, getWidenedType, getWidenedType, hasExplicitNoQualifierParameterInHierarchy, hasExplicitQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, initializeReflectionResolution, isFromByteCode, isFromStubFile, isImmutable, isSideEffectFree, isSupportedQualifier, isSupportedQualifier, isSupportedQualifier, isWithinConstructor, mergeAnnotationFileAnnosIntoType, methodFromUse, negateConstant, order, parseAnnotationFiles, postProcessClassTree, replaceAnnotations, replaceAnnotations, setPathForArtificialTree, setVisitorTreePath, shouldWarnIfStubRedundantWithBytecode, toAnnotatedType, toString, type
-
-
-
-
Field Detail
-
typeAnnotator
protected TypeAnnotator typeAnnotator
to annotate types based on the given tree
-
treeAnnotator
protected TreeAnnotator treeAnnotator
to annotate types based on the given un-annotated types
-
poly
protected QualifierPolymorphism poly
to handle any polymorphic types
-
defaults
protected QualifierDefaults defaults
to handle defaults specified by the user
-
dependentTypesHelper
protected DependentTypesHelper dependentTypesHelper
To handle dependent type annotations and contract expressions.
-
contractsUtils
protected final ContractsFromMethod contractsUtils
To handle method pre- and postconditions.
-
relevantJavaTypes
public final @Nullable java.util.Set<javax.lang.model.type.TypeMirror> relevantJavaTypes
The Java types on which users may write this type system's type annotations. null means no restrictions. Arrays are handled by separate field#arraysAreRelevant
.If the relevant type is generic, this contains its erasure.
Although a
Class<?>
object exists for every element, this does not contain thoseClass<?>
objects because the elements will be compared to TypeMirrors for which Class objects may not exist (they might not be on the classpath).
-
arraysAreRelevant
protected final boolean arraysAreRelevant
Whether users may write type annotations on arrays. Ignored unlessrelevantJavaTypes
is non-null.
-
flowByDefault
protected static boolean flowByDefault
Should flow be used by default?
-
sideEffectsUnrefineAliases
public boolean sideEffectsUnrefineAliases
Should the analysis assume that side effects to a value can change the type of aliased references?For many type systems, once a local variable's type is refined, side effects to the variable's value do not change the variable's type annotations. For some type systems, a side effect to the value could change them; set this field to true.
-
hasOrIsSubchecker
public final boolean hasOrIsSubchecker
True if this checker either has one or more subcheckers, or if this checker is a subchecker. False otherwise. All uses of the methodsaddSharedCFGForTree(Tree, ControlFlowGraph)
andgetSharedCFGForTree(Tree)
should be guarded by a check that this is true.
-
emptyStore
protected Store extends CFAbstractStore<Value,Store> emptyStore
An empty store.
-
analysis
protected FlowAnalysis extends CFAbstractAnalysis<Value,Store,TransferFunction> analysis
-
transfer
protected TransferFunction extends CFAbstractTransfer<Value,Store,TransferFunction> transfer
-
initializationStore
protected Store extends CFAbstractStore<Value,Store> initializationStore
-
initializationStaticStore
protected Store extends CFAbstractStore<Value,Store> initializationStaticStore
-
flowResultAnalysisCaches
protected final java.util.Map<TransferInput<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value,Store>>,java.util.IdentityHashMap<Node,TransferResult<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value,Store>>>> flowResultAnalysisCaches
Caches forAnalysisResult.runAnalysisFor(Node, Analysis.BeforeOrAfter, TransferInput, IdentityHashMap, Map)
. This cache is enabled ifAnnotatedTypeFactory.shouldCache
is true. The cache size is derived fromAnnotatedTypeFactory.getCacheSize()
.
-
subcheckerSharedCFG
protected @MonotonicNonNull java.util.Map<com.sun.source.tree.Tree,ControlFlowGraph> subcheckerSharedCFG
Subcheckers share the same ControlFlowGraph for each analyzed code statement. This maps from code statements to the shared control flow graphs. This map is null in all subcheckers (i.e. any checker for which getParentChecker() returns non-null). This map is also unused (and therefore null) for a checker with no subcheckers with which it can share CFGs.The initial capacity of the map is set by
AnnotatedTypeFactory.getCacheSize()
.
-
shouldClearSubcheckerSharedCFGs
protected boolean shouldClearSubcheckerSharedCFGs
If true,setRoot(CompilationUnitTree)
should clear thesubcheckerSharedCFG
map, freeing memory.For each compilation unit, all the subcheckers run first and finally the ultimate parent checker runs. The ultimate parent checker's
setRoot(CompilationUnitTree)
(the last to run) sets this field to true.In first subchecker to run for the next compilation unit,
setRoot(CompilationUnitTree)
observes the true value, clears thesubcheckerSharedCFG
map, and sets this field back to false. That first subchecker will create a CFG and re-populate the map, and subsequent subcheckers will use the map.
-
scannedClasses
protected final java.util.Map<com.sun.source.tree.ClassTree,GenericAnnotatedTypeFactory.ScanState> scannedClasses
Map from ClassTree to their dataflow analysis state.
-
flowResult
protected @MonotonicNonNull AnalysisResult<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value,Store>> flowResult
The result of the flow analysis. Invariant:scannedClasses.get(c) == FINISHED for some class c ⇒ flowResult != null
Note that flowResult contains analysis results for Trees from multiple classes which are produced by multiple calls to performFlowAnalysis.
-
regularExitStores
protected final java.util.IdentityHashMap<com.sun.source.tree.Tree,Store extends CFAbstractStore<Value,Store>> regularExitStores
A mapping from methods (or other code blocks) to their regular exit store (used to check postconditions).
-
exceptionalExitStores
protected final java.util.IdentityHashMap<com.sun.source.tree.Tree,Store extends CFAbstractStore<Value,Store>> exceptionalExitStores
A mapping from methods (or other code blocks) to their exceptional exit store.
-
returnStatementStores
protected final java.util.IdentityHashMap<com.sun.source.tree.MethodTree,java.util.List<org.plumelib.util.IPair<ReturnNode,TransferResult<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value,Store>>>>> returnStatementStores
A mapping from methods to a list with all return statements and the corresponding store.
-
cfgVisualizer
protected final CFGVisualizer<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value,Store>,TransferFunction extends CFAbstractTransfer<Value,Store,TransferFunction>> cfgVisualizer
The CFGVisualizer to be used by all CFAbstractAnalysis instances.
-
formalParameterPattern
protected static final java.util.regex.Pattern formalParameterPattern
Matches parameter expressions as they appear inEnsuresQualifier
andRequiresQualifier
annotations, e.g. "#1", "#2", etc.
-
-
Constructor Detail
-
GenericAnnotatedTypeFactory
protected GenericAnnotatedTypeFactory(BaseTypeChecker checker, boolean useFlow)
Creates a type factory. Its compilation unit is not yet set.- Parameters:
checker
- the checker to which this type factory belongsuseFlow
- whether flow analysis should be performed
-
GenericAnnotatedTypeFactory
protected GenericAnnotatedTypeFactory(BaseTypeChecker checker)
Creates a type factory. Its compilation unit is not yet set. This constructor might get reflectively called by BaseTypeVisitor.createTypeFactory and uses flowByDefault to determine whether flow refinement should be enabled. Subclasses should instead use the two-parameter constructor and explicitly set whether to use flow refinement.- Parameters:
checker
- the checker to which this type factory belongs
-
-
Method Detail
-
postInit
protected void postInit(@UnderInitialization(GenericAnnotatedTypeFactory.class) GenericAnnotatedTypeFactory<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value,Store>,TransferFunction extends CFAbstractTransfer<Value,Store,TransferFunction>,FlowAnalysis extends CFAbstractAnalysis<Value,Store,TransferFunction>> this)
Description copied from class:AnnotatedTypeFactory
Actions that logically belong in the constructor, but need to run after the subclass constructor has completed. In particular,AnnotationFileElementTypes.parseStubFiles()
may try to do type resolution with this AnnotatedTypeFactory.- Overrides:
postInit
in classAnnotatedTypeFactory
-
preProcessClassTree
public void preProcessClassTree(com.sun.source.tree.ClassTree classTree)
Performs flow-sensitive type refinement onclassTree
if this type factory is configured to do so.- Overrides:
preProcessClassTree
in classAnnotatedTypeFactory
- Parameters:
classTree
- tree on which to perform flow-sensitive type refinement
-
setRoot
public void setRoot(@Nullable com.sun.source.tree.CompilationUnitTree root)
Description copied from class:AnnotatedTypeFactory
Set the CompilationUnitTree that should be used.- Overrides:
setRoot
in classAnnotatedTypeFactory
- Parameters:
root
- the new compilation unit to use
-
getSupportedMonotonicTypeQualifiers
public final java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> getSupportedMonotonicTypeQualifiers()
Returns an immutable set of the monotonic type qualifiers supported by this checker.- Returns:
- the monotonic type qualifiers supported this processor, or an empty set if none
- See Also:
MonotonicQualifier
-
createTreeAnnotator
protected TreeAnnotator createTreeAnnotator()
Returns aTreeAnnotator
that adds annotations to a type based on the contents of a tree.The default tree annotator is a
ListTreeAnnotator
of the following:PropagationTreeAnnotator
: Propagates annotations from subtreesLiteralTreeAnnotator
: Adds annotations based onQualifierForLiterals
meta-annotationsDependentTypesTreeAnnotator
: Adapts dependent annotations based on context
Subclasses may override this method to specify additional tree annotators, for example:
new ListTreeAnnotator(super.createTreeAnnotator(), new KeyLookupTreeAnnotator(this));
- Returns:
- a tree annotator
-
createTypeAnnotator
protected TypeAnnotator createTypeAnnotator()
Returns aDefaultForTypeAnnotator
that adds annotations to a type based on the content of the type itself.Subclass may override this method. The default type annotator is a
ListTypeAnnotator
of the following:IrrelevantTypeAnnotator
: Adds top to types not listed in the@
RelevantJavaTypes
annotation on the checker.PropagationTypeAnnotator
: Propagates annotation onto wildcards.
- Returns:
- a type annotator
-
annotationsForIrrelevantJavaType
public AnnotationMirrorSet annotationsForIrrelevantJavaType(javax.lang.model.type.TypeMirror tm)
Returns the annotations that should appear on the given irrelevant Java type. If the type is relevant, this method's behavior is undefined.- Parameters:
tm
- an irrelevant Java type- Returns:
- the annotations that should appear on the given irrelevant Java type
-
createDefaultForUseTypeAnnotator
protected DefaultQualifierForUseTypeAnnotator createDefaultForUseTypeAnnotator()
Creates anDefaultQualifierForUseTypeAnnotator
.- Returns:
- a new
DefaultQualifierForUseTypeAnnotator
-
createDefaultForTypeAnnotator
protected DefaultForTypeAnnotator createDefaultForTypeAnnotator()
Creates anDefaultForTypeAnnotator
.- Returns:
- a new
DefaultForTypeAnnotator
-
getDefaultForTypeAnnotator
public DefaultForTypeAnnotator getDefaultForTypeAnnotator()
Returns theDefaultForTypeAnnotator
.- Returns:
- the
DefaultForTypeAnnotator
-
createFlowAnalysis
protected FlowAnalysis createFlowAnalysis()
Returns the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis.This implementation uses the checker naming convention to create the appropriate analysis. If no transfer function is found, it returns an instance of
CFAnalysis
.Subclasses have to override this method to create the appropriate analysis if they do not follow the checker naming convention.
- Returns:
- the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis
-
createFlowTransferFunction
public TransferFunction createFlowTransferFunction(CFAbstractAnalysis<Value,Store,TransferFunction> analysis)
Returns the appropriate transfer function that is used for the given org.checkerframework.dataflow analysis.This implementation uses the checker naming convention to create the appropriate transfer function. If no transfer function is found, it returns an instance of
CFTransfer
.Subclasses have to override this method to create the appropriate transfer function if they do not follow the checker naming convention.
- Parameters:
analysis
- a dataflow analysis- Returns:
- a new transfer function
-
createDependentTypesHelper
protected DependentTypesHelper createDependentTypesHelper()
Creates aDependentTypesHelper
and returns it. UsegetDependentTypesHelper()
to access the value.- Returns:
- a new
DependentTypesHelper
-
getDependentTypesHelper
public DependentTypesHelper getDependentTypesHelper()
Returns the DependentTypesHelper.- Returns:
- the DependentTypesHelper
-
createContractsFromMethod
protected ContractsFromMethod createContractsFromMethod()
Creates anContractsFromMethod
and returns it.- Returns:
- a new
ContractsFromMethod
-
getContractsFromMethod
public ContractsFromMethod getContractsFromMethod()
Returns the helper for method pre- and postconditions.- Returns:
- the helper for method pre- and postconditions
-
getExplicitNewClassClassTypeArgs
protected java.util.List<AnnotatedTypeMirror> getExplicitNewClassClassTypeArgs(com.sun.source.tree.NewClassTree newClassTree)
Description copied from class:AnnotatedTypeFactory
Returns the partially-annotated explicit class type arguments of the new class tree. TheAnnotatedTypeMirror
only include the annotations explicitly written on the explict type arguments. (IfnewClass
use a diamond operator, this method returns the empty list.) For example, when called withnew MyClass<@HERE String>()
this method would return a list containing@HERE String
.- Overrides:
getExplicitNewClassClassTypeArgs
in classAnnotatedTypeFactory
- Parameters:
newClassTree
- a new class tree- Returns:
- the partially annotated
AnnotatedTypeMirror
s for the (explicit) class type arguments of the new class tree
-
getExplicitNewClassAnnos
public AnnotationMirrorSet getExplicitNewClassAnnos(com.sun.source.tree.NewClassTree newClassTree)
Description copied from class:AnnotatedTypeFactory
Returns the annotations explicitly written on a NewClassTree.new @HERE Class()
- Overrides:
getExplicitNewClassAnnos
in classAnnotatedTypeFactory
- Parameters:
newClassTree
- a constructor invocation- Returns:
- the annotations explicitly written on a NewClassTree
-
createAndInitQualifierDefaults
protected final QualifierDefaults createAndInitQualifierDefaults()
CreateQualifierDefaults
which handles checker specified defaults, and initialize the createdQualifierDefaults
. Subclasses should overrideaddCheckedCodeDefaults(QualifierDefaults defs)
to add more defaults or use different defaults.- Returns:
- the QualifierDefaults object
-
createQualifierDefaults
protected QualifierDefaults createQualifierDefaults()
CreateQualifierDefaults
which handles checker specified defaults. Sub-classes override this method to provide a differentQualifierDefault
implementation.
-
getSortedQualifierNames
protected final java.lang.String getSortedQualifierNames()
Creates and returns a string containing the number of qualifiers and the canonical class names of each qualifier that has been added to this checker's supported qualifier set. The names are alphabetically sorted.- Returns:
- a string containing the number of qualifiers and canonical names of each qualifier
-
addCheckedCodeDefaults
protected void addCheckedCodeDefaults(QualifierDefaults defs)
Adds default qualifiers for type-checked code by readingDefaultFor
andDefaultQualifierInHierarchy
meta-annotations. Subclasses may override this method to add defaults that cannot be specified with aDefaultFor
orDefaultQualifierInHierarchy
meta-annotations.- Parameters:
defs
- the QualifierDefault object to which defaults are added
-
addCheckedStandardDefaults
protected void addCheckedStandardDefaults(QualifierDefaults defs)
Adds the standard CLIMB defaults that do not conflict with previously added defaults.- Parameters:
defs
-QualifierDefaults
object to which defaults are added
-
addUncheckedStandardDefaults
protected void addUncheckedStandardDefaults(QualifierDefaults defs)
Adds standard unchecked defaults that do not conflict with previously added defaults.- Parameters:
defs
-QualifierDefaults
object to which defaults are added
-
checkForDefaultQualifierInHierarchy
protected void checkForDefaultQualifierInHierarchy(QualifierDefaults defs)
Check that a default qualifier (in at least one hierarchy) has been set and issue an error if not.- Parameters:
defs
-QualifierDefaults
object to which defaults are added
-
createQualifierPolymorphism
protected QualifierPolymorphism createQualifierPolymorphism()
Creates theQualifierPolymorphism
instance which supports the QualifierPolymorphism mechanism.- Returns:
- the QualifierPolymorphism instance to use
-
getQualifierPolymorphism
public QualifierPolymorphism getQualifierPolymorphism()
Gives the currentQualifierPolymorphism
instance which supports the QualifierPolymorphism mechanism.- Returns:
- the QualifierPolymorphism instance to use
-
postDirectSuperTypes
protected void postDirectSuperTypes(AnnotatedTypeMirror type, java.util.List<? extends AnnotatedTypeMirror> supertypes)
Description copied from class:AnnotatedTypeFactory
A callback method for the AnnotatedTypeFactory subtypes to customize directSupertypes(). Overriding methods should merely change the annotations on the supertypes, without adding or removing new types.The default provided implementation adds
type
annotations tosupertypes
. This allows thetype
and its supertypes to have the qualifiers.- Overrides:
postDirectSuperTypes
in classAnnotatedTypeFactory
- Parameters:
type
- the type whose supertypes are desiredsupertypes
- the supertypes as specified by the base AnnotatedTypeFactory
-
getResultingTypeOfConstructorMemberReference
public AnnotatedTypeMirror getResultingTypeOfConstructorMemberReference(com.sun.source.tree.MemberReferenceTree memberReferenceTree, AnnotatedTypeMirror.AnnotatedExecutableType constructorType)
Gets the type of the resulting constructor call of a MemberReferenceTree.- Parameters:
memberReferenceTree
- MemberReferenceTree where the member is a constructorconstructorType
- AnnotatedExecutableType of the declaration of the constructor- Returns:
- AnnotatedTypeMirror of the resulting type of the constructor
-
getAnnotationFromJavaExpressionString
public @Nullable javax.lang.model.element.AnnotationMirror getAnnotationFromJavaExpressionString(java.lang.String expression, com.sun.source.tree.Tree tree, com.sun.source.util.TreePath path, java.lang.Class<? extends java.lang.annotation.Annotation> clazz) throws JavaExpressionParseUtil.JavaExpressionParseException
Returns the primary annotation on expression if it were evaluated at path.- Parameters:
expression
- a Java expressiontree
- current treepath
- location at which expression is evaluatedclazz
- class of the annotation- Returns:
- the annotation on expression or null if one does not exist
- Throws:
JavaExpressionParseUtil.JavaExpressionParseException
- thrown if the expression cannot be parsed
-
getAnnotationFromJavaExpression
public @Nullable javax.lang.model.element.AnnotationMirror getAnnotationFromJavaExpression(JavaExpression expr, com.sun.source.tree.Tree tree, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the primary annotation on an expression, at a particular location.- Parameters:
expr
- the expression for which the annotation is returnedtree
- current treeclazz
- the Class of the annotation- Returns:
- the annotation on expression or null if one does not exist
-
getAnnotationsFromJavaExpression
public @Nullable AnnotationMirrorSet getAnnotationsFromJavaExpression(JavaExpression expr, com.sun.source.tree.Tree tree)
Returns the primary annotations on an expression, at a particular location.- Parameters:
expr
- the expression for which the annotation is returnedtree
- current tree- Returns:
- the annotation on expression or null if one does not exist
-
parseJavaExpressionString
public JavaExpression parseJavaExpressionString(java.lang.String expression, com.sun.source.util.TreePath currentPath) throws JavaExpressionParseUtil.JavaExpressionParseException
Produces the JavaExpression as ifexpression
were written atcurrentPath
.- Parameters:
expression
- a Java expressioncurrentPath
- the current path- Returns:
- the JavaExpression associated with expression on currentPath
- Throws:
JavaExpressionParseUtil.JavaExpressionParseException
- thrown if the expression cannot be parsed
-
getExpressionAndOffsetFromJavaExpressionString
public org.plumelib.util.IPair<JavaExpression,java.lang.String> getExpressionAndOffsetFromJavaExpressionString(java.lang.String expression, com.sun.source.util.TreePath currentPath) throws JavaExpressionParseUtil.JavaExpressionParseException
Produces the JavaExpression and offset associated with an expression. For instance, "n+1" has no associated JavaExpression, but this method produces a pair of a JavaExpression (for "n") and an offset ("1").- Parameters:
expression
- a Java expression, possibly with a constant offsetcurrentPath
- location at which expression is evaluated- Returns:
- the JavaExpression and offset for the given expression
- Throws:
JavaExpressionParseUtil.JavaExpressionParseException
- thrown if the expression cannot be parsed
-
getAnnotationMirrorFromJavaExpressionString
public @Nullable javax.lang.model.element.AnnotationMirror getAnnotationMirrorFromJavaExpressionString(java.lang.String expression, com.sun.source.tree.Tree tree, com.sun.source.util.TreePath currentPath) throws JavaExpressionParseUtil.JavaExpressionParseException
Returns the annotation mirror from dataflow forexpression
.This will output a different annotation than
getAnnotationFromJavaExpressionString(String, Tree, TreePath, Class)
, because if the specified annotation isn't found in the store, the type from the factory is used.- Parameters:
expression
- a Java expressiontree
- the tree at the location to parse the expressioncurrentPath
- location at which expression is evaluated- Returns:
- an AnnotationMirror representing the type in the store at the given location from this type factory's type system, or null if one is not available
- Throws:
JavaExpressionParseUtil.JavaExpressionParseException
- thrown if the expression cannot be parsed
-
getRegularExitStore
public @Nullable Store getRegularExitStore(com.sun.source.tree.Tree tree)
Returns the regular exit store for a method or another code block (such as static initializers). Returnsnull
if there is no such store. This can happen because the method cannot exit through the regular exit block, or it is abstract or in an interface.- Parameters:
tree
- a MethodTree or other code block, such as a static initializer- Returns:
- the regular exit store, or
null
-
getExceptionalExitStore
public @Nullable Store getExceptionalExitStore(com.sun.source.tree.Tree tree)
Returns the exceptional exit store for a method or another code block (such as static initializers).- Parameters:
tree
- a MethodTree or other code block, such as a static initializer- Returns:
- the exceptional exit store, or
null
, if there is no such store
-
getReturnStatementStores
public java.util.List<org.plumelib.util.IPair<ReturnNode,TransferResult<Value,Store>>> getReturnStatementStores(com.sun.source.tree.MethodTree methodTree)
Returns a list of all return statements ofmethod
paired with their correspondingTransferResult
. Ifmethod
has no return statement, then the empty list is returned.- Parameters:
methodTree
- method whose return statements should be returned- Returns:
- a list of all return statements of
method
paired with their correspondingTransferResult
or an empty list ifmethod
has no return statements
-
getStoreBefore
public Store getStoreBefore(com.sun.source.tree.Tree tree)
Returns the store immediately before a givenTree
.- Returns:
- the store immediately before a given
Tree
-
getStoreBefore
public Store getStoreBefore(java.util.Set<Node> nodes)
Returns the store immediately before a given Set ofNode
s.- Returns:
- the store immediately before a given Set of
Node
s
-
getStoreBefore
public @Nullable Store getStoreBefore(Node node)
Returns the store immediately before a given node.- Parameters:
node
- a node whose pre-store to return- Returns:
- the store immediately before
node
-
getStoreAfter
public @Nullable Store getStoreAfter(com.sun.source.tree.Tree tree)
Returns the store immediately after a given tree.May return null; for example, after a
return
statement.- Parameters:
tree
- the tree whose post-store to return- Returns:
- the store immediately after a given tree
-
getStoreAfter
public Store getStoreAfter(java.util.Set<Node> nodes)
Returns the store immediately after a given set of nodes.- Parameters:
nodes
- the nodes whose post-stores to LUB- Returns:
- the LUB of the stores store immediately after
nodes
-
getStoreAfter
public Store getStoreAfter(Node node)
Returns the store immediately after a givenNode
.- Parameters:
node
- node after which the store is returned- Returns:
- the store immediately after a given
Node
-
getNodesForTree
public java.util.Set<Node> getNodesForTree(com.sun.source.tree.Tree tree)
- Returns:
- the
Node
s for a givenTree
- See Also:
AnalysisResult.getNodesForTree(Tree)
-
getFirstNodeOfKindForTree
public <T extends Node> @Nullable T getFirstNodeOfKindForTree(com.sun.source.tree.Tree tree, java.lang.Class<T> kind)
Return the firstNode
for a givenTree
that has classkind
.You probably don't want to use this function: iterate over the result of
getNodesForTree(Tree)
yourself or ask for a conservative approximation of the store usinggetStoreBefore(Tree)
orgetStoreAfter(Tree)
. This method is for code that uses aNode
in a rather unusual way. Callers should probably be rewritten to not use aNode
at all.- Type Parameters:
T
- the class of the node to return- Parameters:
tree
- a tree in which to search for a node of classkind
kind
- the class of the node to return- Returns:
- the first
Node
for a givenTree
that has classkind
- See Also:
getNodesForTree(Tree)
,getStoreBefore(Tree)
,getStoreAfter(Tree)
-
getFinalLocalValues
public java.util.Map<javax.lang.model.element.VariableElement,Value> getFinalLocalValues()
Returns the value of effectively final local variables.- Returns:
- the value of effectively final local variables
-
isNotFullyInitializedReceiver
@Pure public boolean isNotFullyInitializedReceiver(com.sun.source.tree.MethodTree methodDeclTree)
Returns true if the receiver of a method or constructor might not be fully initialized.- Parameters:
methodDeclTree
- the declaration of the method or constructor- Returns:
- true if the receiver of a method or constructor might not be fully initialized
-
performFlowAnalysis
protected void performFlowAnalysis(com.sun.source.tree.ClassTree classTree)
Perform a org.checkerframework.dataflow analysis over a single class tree and its nested classes.- Parameters:
classTree
- the class to analyze
-
analyze
protected void analyze(java.util.Queue<org.plumelib.util.IPair<com.sun.source.tree.ClassTree,Store>> classQueue, java.util.Queue<org.plumelib.util.IPair<com.sun.source.tree.LambdaExpressionTree,Store>> lambdaQueue, UnderlyingAST ast, java.util.List<CFAbstractAnalysis.FieldInitialValue<Value>> fieldValues, com.sun.source.tree.ClassTree currentClass, boolean isInitializationCode, boolean updateInitializationStore, boolean isStatic, @Nullable Store capturedStore)
Analyze the ASTast
and store the result. Additional operations that should be performed after analysis should be implemented inpostAnalyze(ControlFlowGraph)
.- Parameters:
classQueue
- the queue for encountered class trees and their initial storeslambdaQueue
- the queue for encountered lambda expression trees and their initial storesast
- the AST to analyzefieldValues
- the abstract values for all fields of the same classcurrentClass
- the class we are currently looking atisInitializationCode
- are we analyzing a (static/non-static) initializer block of a classupdateInitializationStore
- should the initialization store be updatedisStatic
- are we analyzing a static constructcapturedStore
- the input Store to use for captured variables, e.g. in a lambda- See Also:
postAnalyze(org.checkerframework.dataflow.cfg.ControlFlowGraph)
-
postAnalyze
protected void postAnalyze(ControlFlowGraph cfg)
Perform any additional operations on a CFG. Called once per CFG, after the CFG has been analyzed byanalyze(Queue, Queue, UnderlyingAST, List, ClassTree, boolean, boolean, boolean, CFAbstractStore)
. This method can be used to initialize additional state or to perform any analyses that are easier to perform on the CFG instead of the AST.
-
handleCFGViz
protected void handleCFGViz(ControlFlowGraph cfg)
Handle the visualization of the CFG, if necessary.- Parameters:
cfg
- the CFG
-
getAnnotatedTypeLhsNoTypeVarDefault
public AnnotatedTypeMirror getAnnotatedTypeLhsNoTypeVarDefault(com.sun.source.tree.Tree lhsTree)
Returns the type of the left-hand side of an assignment without applying local variable defaults to type variables.The type variables that are types of local variables are defaulted to top so that they can be refined by dataflow. When these types are used as context during type argument inference, this default is too conservative. So this method is used instead of
getAnnotatedTypeLhs(Tree)
.TypeArgInferenceUtil.assignedToVariable(AnnotatedTypeFactory, VariableTree)
explains why a different type is used.- Parameters:
lhsTree
- left-hand side of an assignment- Returns:
- AnnotatedTypeMirror of
lhsTree
-
isComputingAnnotatedTypeMirrorOfLhs
public boolean isComputingAnnotatedTypeMirrorOfLhs()
Returns whethergetAnnotatedTypeLhs(Tree)
is running right now. This controls which hierarchies' qualifiers are changed based on the receiver type and the declared annotations for a field.- Returns:
- whether
getAnnotatedTypeLhs(Tree)
is running right now - See Also:
getAnnotatedTypeLhs(Tree)
-
getAnnotatedTypeBefore
public AnnotatedTypeMirror getAnnotatedTypeBefore(JavaExpression expr, com.sun.source.tree.ExpressionTree tree)
Returns the type of a JavaExpressionexpr
if it were evaluated before a treetree
.This is used by
BaseTypeVisitor.visitMethodInvocation(MethodInvocationTree, Void)
to check the preconditions of method calls.- Parameters:
expr
- the expression to typetree
- a tree- Returns:
- the type of
expr
if it were evaluated before treetree
-
getAnnotatedTypeLhs
public AnnotatedTypeMirror getAnnotatedTypeLhs(com.sun.source.tree.Tree lhsTree)
Returns the type of a left-hand side of an assignment.The default implementation returns the type without considering dataflow type refinement. Subclass can override this method and add additional logic for computing the type of a LHS.
- Parameters:
lhsTree
- left-hand side of an assignment- Returns:
- AnnotatedTypeMirror of
lhsTree
-
getAnnotatedTypeVarargsArray
public @Nullable AnnotatedTypeMirror getAnnotatedTypeVarargsArray(com.sun.source.tree.Tree tree)
Returns the type of a varargs array of a method invocation or a constructor invocation. Returns null only if private fielduseFlow
is false.- Parameters:
tree
- a method invocation or a constructor invocation- Returns:
- AnnotatedTypeMirror of varargs array for a method or constructor invocation
tree
; returns null if private fielduseFlow
is false
-
getAnnotatedTypeRhsUnaryAssign
public AnnotatedTypeMirror getAnnotatedTypeRhsUnaryAssign(com.sun.source.tree.UnaryTree tree)
Returns the type ofv + 1
orv - 1
wherev
is the expression in the postfixed increment or decrement expression.- Parameters:
tree
- a postfixed increment or decrement tree- Returns:
- AnnotatedTypeMirror of a right-hand side of an assignment for unary operation
-
constructorFromUse
public AnnotatedTypeFactory.ParameterizedExecutableType constructorFromUse(com.sun.source.tree.NewClassTree tree)
Description copied from class:AnnotatedTypeFactory
Determines the type of the invoked constructor based on the passed new class tree.The returned method type has all type variables resolved, whether based on receiver type, passed type parameters if any, and constructor invocation parameter.
Subclasses may override this method to customize inference of types or qualifiers based on constructor invocation parameters.
As an implementation detail, this method depends on
AnnotatedTypes.asMemberOf(Types, AnnotatedTypeFactory, AnnotatedTypeMirror, Element)
, and customization based on receiver type should be in accordance with its specification.The return type is a pair of the type of the invoked constructor 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(com.sun.source.tree.Tree, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeParameterBounds>, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeMirror>, java.util.List<? extends com.sun.source.tree.Tree>, java.lang.CharSequence, java.util.List<?>)
for the checks of type argument well-formedness.Note that "this" and "super" constructor invocations are handled by method
AnnotatedTypeFactory.methodFromUse(com.sun.source.tree.MethodInvocationTree)
. This method only handles constructor invocations in a "new" expression.- Overrides:
constructorFromUse
in classAnnotatedTypeFactory
- Parameters:
tree
- the constructor invocation tree- Returns:
- the annotated type of the invoked constructor (as an executable type) and the (inferred) type arguments
-
constructorFromUsePreSubstitution
protected void constructorFromUsePreSubstitution(com.sun.source.tree.NewClassTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type)
Description copied from class:AnnotatedTypeFactory
A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared constructor type before type variable substitution.- Overrides:
constructorFromUsePreSubstitution
in classAnnotatedTypeFactory
- Parameters:
tree
- a NewClassTree from constructorFromUse()type
- declared method type before type variable substitution
-
getMethodReturnType
public AnnotatedTypeMirror getMethodReturnType(com.sun.source.tree.MethodTree m)
Description copied from class:AnnotatedTypeFactory
Returns the return type of the methodm
.- Overrides:
getMethodReturnType
in classAnnotatedTypeFactory
- Parameters:
m
- tree of a method declaration- Returns:
- the return type of the method
-
addDefaultAnnotations
public void addDefaultAnnotations(AnnotatedTypeMirror type)
Description copied from class:AnnotatedTypeFactory
Adds default annotations totype
. This method should only be used in places where the correct annotations cannot be computed because of uninferred type arguments. (SeeAnnotatedTypeMirror.AnnotatedWildcardType.isUninferredTypeArgument()
.)- Overrides:
addDefaultAnnotations
in classAnnotatedTypeFactory
- Parameters:
type
- annotated type to which default annotations are added
-
addComputedTypeAnnotations
protected final void addComputedTypeAnnotations(com.sun.source.tree.Tree tree, AnnotatedTypeMirror type)
This method is final; overrideaddComputedTypeAnnotations(Tree, AnnotatedTypeMirror, boolean)
instead.Changes annotations on a type obtained from a
Tree
. By default, this method does nothing. GenericAnnotatedTypeFactory uses this method to implement defaulting and inference (flow-sensitive type refinement). Its subclasses usually override it only to customize default annotations.Subclasses that override this method should also override
AnnotatedTypeFactory.addComputedTypeAnnotations(Element, AnnotatedTypeMirror)
.In classes that extend
GenericAnnotatedTypeFactory
, overrideaddComputedTypeAnnotations(Tree, AnnotatedTypeMirror, boolean)
instead of this method.- Overrides:
addComputedTypeAnnotations
in classAnnotatedTypeFactory
- Parameters:
tree
- an AST nodetype
- the type obtained fromtree
-
getDefaultAnnotations
public AnnotatedTypeMirror getDefaultAnnotations(com.sun.source.tree.Tree tree, AnnotatedTypeMirror type)
Removes all primary annotations on a copy of the type and calculates the default annotations that apply to the copied type, without type refinements.- Parameters:
tree
- tree where the type is usedtype
- type to determine the defaulted version for- Returns:
- the annotated type mirror with default annotations
-
addComputedTypeAnnotations
protected void addComputedTypeAnnotations(com.sun.source.tree.Tree tree, AnnotatedTypeMirror type, boolean iUseFlow)
LikeaddComputedTypeAnnotations(Tree, AnnotatedTypeMirror)
. Overriding implementations typically simply pass the boolean to calls to super.- Parameters:
tree
- an AST nodetype
- the type obtained from treeiUseFlow
- whether to use information from dataflow analysis
-
checkAndPerformFlowAnalysis
protected void checkAndPerformFlowAnalysis(com.sun.source.tree.Tree tree)
Flow analysis will be performed if all of the following are true.tree
is aClassTree
- Flow analysis has not already been performed on
tree
- Parameters:
tree
- the tree to check and possibly perform flow analysis on
-
getInferredValueFor
public @Nullable Value getInferredValueFor(com.sun.source.tree.Tree tree)
Returns the inferred value (by the org.checkerframework.dataflow analysis) for a given tree.- Parameters:
tree
- the tree- Returns:
- the value for the tree, if one has been computed by dataflow. If no value has been computed, null is returned (this does not mean that no value will ever be computed for the given tree).
-
applyInferredAnnotations
protected void applyInferredAnnotations(AnnotatedTypeMirror type, Value inferred)
Applies the annotations inferred by the org.checkerframework.dataflow analysis to the typetype
.- Parameters:
type
- the type to modifyinferred
- the inferred annotations to apply
-
applyQualifierParameterDefaults
protected void applyQualifierParameterDefaults(com.sun.source.tree.Tree tree, AnnotatedTypeMirror type)
Applies defaults for types in a class with an qualifier parameter.Within a class with
@HasQualifierParameter
, types with that class default to the polymorphic qualifier rather than the typical default. Local variables with a type that has a qualifier parameter are initialized to the type of their initializer, rather than the default for local variables.- Parameters:
tree
- a Tree whose type istype
type
- where the defaults are applied
-
applyQualifierParameterDefaults
protected void applyQualifierParameterDefaults(@Nullable javax.lang.model.element.Element elt, AnnotatedTypeMirror type)
Applies defaults for types in a class with an qualifier parameter.Within a class with
@HasQualifierParameter
, types with that class default to the polymorphic qualifier rather than the typical default. Local variables with a type that has a qualifier parameter are initialized to the type of their initializer, rather than the default for local variables.- Parameters:
elt
- an Element whose type istype
type
- where the defaults are applied
-
addComputedTypeAnnotations
public void addComputedTypeAnnotations(javax.lang.model.element.Element elt, AnnotatedTypeMirror type)
To add annotations to the type of method or constructor parameters, add aTypeAnnotator
usingcreateTypeAnnotator()
and see the comment inTypeAnnotator.visitExecutable(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType, Void)
.- Overrides:
addComputedTypeAnnotations
in classAnnotatedTypeFactory
- Parameters:
elt
- an elementtype
- the type obtained fromelt
-
methodFromUse
public AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(com.sun.source.tree.MethodInvocationTree tree)
Description copied from class:AnnotatedTypeFactory
Determines the type of the invoked method based on the passed method invocation tree.The returned method type has all type variables resolved, whether based on receiver type, passed type parameters if any, and method invocation parameter.
Subclasses may override this method to customize inference of types or qualifiers based on method invocation parameters.
As an implementation detail, this method depends on
AnnotatedTypes.asMemberOf(Types, AnnotatedTypeFactory, 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(com.sun.source.tree.Tree, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeParameterBounds>, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeMirror>, java.util.List<? extends com.sun.source.tree.Tree>, java.lang.CharSequence, java.util.List<?>)
for the checks of type argument well-formedness.Note that "this" and "super" constructor invocations are also handled by this method (explicit or implicit ones, at the beginning of a constructor). Method
AnnotatedTypeFactory.constructorFromUse(NewClassTree)
is only used for a constructor invocation in a "new" expression.- Overrides:
methodFromUse
in classAnnotatedTypeFactory
- Parameters:
tree
- the method invocation tree- Returns:
- the method type being invoked with tree and the (inferred) type arguments
-
methodFromUsePreSubstitution
public void methodFromUsePreSubstitution(com.sun.source.tree.ExpressionTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type)
Description copied from class:AnnotatedTypeFactory
A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared method type before type variable substitution.- Overrides:
methodFromUsePreSubstitution
in classAnnotatedTypeFactory
- Parameters:
tree
- either a method invocation or a member reference treetype
- declared method type before type variable substitution
-
typeVariablesFromUse
public java.util.List<AnnotatedTypeParameterBounds> typeVariablesFromUse(AnnotatedTypeMirror.AnnotatedDeclaredType type, javax.lang.model.element.TypeElement element)
Description copied from class:AnnotatedTypeFactory
Adapt the upper bounds of the type variables of a class relative to the type instantiation. In some type systems, the upper bounds depend on the instantiation of the class. For example, in the Generic Universe Type system, consider a class declaration
then the instantiationclass C<X extends @Peer Object>
is legal. The upper bounds of class C have to be adapted by the main modifier.@Rep C<@Rep Object>
An example of an adaptation follows. Suppose, I have a declaration:
And an instantiation:class MyClass<E extends List<E>>
new MyClass<@NonNull String>()
The upper bound of E adapted to the argument String, would be
List<@NonNull String>
and the lower bound would be an AnnotatedNullType.TODO: ensure that this method is consistently used instead of directly querying the type variables.
- Overrides:
typeVariablesFromUse
in classAnnotatedTypeFactory
- Parameters:
type
- the use of the typeelement
- the corresponding element- Returns:
- the adapted bounds of the type parameters
-
getEmptyStore
public Store getEmptyStore()
Returns the empty store.- Returns:
- the empty store
-
getTypeFactoryOfSubchecker
public final <T extends GenericAnnotatedTypeFactory<?,?,?,?>> T getTypeFactoryOfSubchecker(java.lang.Class<? extends BaseTypeChecker> subCheckerClass)
Returns the type factory used by a subchecker. Throws an exception if no matching subchecker was found or if the type factory is null. The caller must know the exact checker class to request.Because the visitor path is copied, call this method each time a subfactory is needed rather than store the returned subfactory in a field.
- Type Parameters:
T
- the type ofsubCheckerClass
'sAnnotatedTypeFactory
- Parameters:
subCheckerClass
- the exact class of the subchecker- Returns:
- the AnnotatedTypeFactory of the subchecker; never null
- See Also:
getTypeFactoryOfSubcheckerOrNull(java.lang.Class<? extends org.checkerframework.common.basetype.BaseTypeChecker>)
-
getTypeFactoryOfSubcheckerOrNull
public <T extends GenericAnnotatedTypeFactory<?,?,?,?>> @Nullable T getTypeFactoryOfSubcheckerOrNull(java.lang.Class<? extends BaseTypeChecker> subCheckerClass)
Returns the type factory used by a subchecker. Returns null if no matching subchecker was found or if the type factory is null. The caller must know the exact checker class to request.Because the visitor path is copied, call this method each time a subfactory is needed rather than store the returned subfactory in a field.
- Type Parameters:
T
- the type ofsubCheckerClass
'sAnnotatedTypeFactory
- Parameters:
subCheckerClass
- the exact class of the subchecker- Returns:
- the AnnotatedTypeFactory of the subchecker or null if no subchecker exists
- See Also:
getTypeFactoryOfSubchecker(java.lang.Class<? extends org.checkerframework.common.basetype.BaseTypeChecker>)
-
getShouldDefaultTypeVarLocals
public boolean getShouldDefaultTypeVarLocals()
Should the local variable default annotation be applied to type variables?It is initialized to true if data flow is used by the checker. It is set to false when getting the assignment context for type argument inference.
- Returns:
- shouldDefaultTypeVarLocals
- See Also:
getAnnotatedTypeLhsNoTypeVarDefault(com.sun.source.tree.Tree)
-
createCFGVisualizer
protected @Nullable CFGVisualizer<Value,Store,TransferFunction> createCFGVisualizer()
Create a new CFGVisualizer.- Returns:
- a new CFGVisualizer, or null if none will be used on this run
-
getCFGVisualizer
public CFGVisualizer<Value,Store,TransferFunction> getCFGVisualizer()
The CFGVisualizer to be used by all CFAbstractAnalysis instances.
-
postAsMemberOf
public void postAsMemberOf(AnnotatedTypeMirror type, AnnotatedTypeMirror owner, javax.lang.model.element.Element element)
Description copied from class:AnnotatedTypeFactory
A callback method for the AnnotatedTypeFactory subtypes to customize AnnotatedTypes.asMemberOf(). Overriding methods should merely change the annotations on the subtypes, without changing the types.- Overrides:
postAsMemberOf
in classAnnotatedTypeFactory
- Parameters:
type
- the annotated type of the elementowner
- the annotated type of the receiver of the accessing treeelement
- the element of the field or method
-
addAnnotationsFromDefaultForType
protected void addAnnotationsFromDefaultForType(@Nullable javax.lang.model.element.Element element, AnnotatedTypeMirror type)
Adds default qualifiers based on the underlying type oftype
totype
. Ifelement
is a local variable, or if the type already has an annotation from the relevant type hierarchy, then the defaults are not added.(This uses both the
DefaultQualifierForUseTypeAnnotator
andDefaultForTypeAnnotator
.)- Parameters:
element
- possibly null element whose type istype
type
- the type to which defaults are added
-
isRelevant
public final boolean isRelevant(javax.lang.model.type.TypeMirror tm)
Returns true if users can write type annotations from this type system directly on the given Java type.May return false for a compound type (for which it is possible to write type qualifiers on elements of the type).
Subclasses should override
#isRelevantImpl
instead of this method.- Parameters:
tm
- a type- Returns:
- true if users can write type annotations from this type system directly on the given Java type
-
isRelevant
public final boolean isRelevant(AnnotatedTypeMirror tm)
Returns true if users can write type annotations from this type system directly on the given Java type.May return false for a compound type (for which it is possible to write type qualifiers on elements of the type).
Subclasses should override
#isRelevantImpl
instead of this method.- Parameters:
tm
- a type- Returns:
- true if users can write type annotations from this type system directly on the given Java type
-
isRelevantImpl
protected boolean isRelevantImpl(javax.lang.model.type.TypeMirror tm)
Returns true if users can write type annotations from this type system on the given Java type. Does not use a cache.Clients should never call this. Call
isRelevant(javax.lang.model.type.TypeMirror)
instead. This is a helper method forisRelevant(javax.lang.model.type.TypeMirror)
.- Parameters:
tm
- a type- Returns:
- true if users can write type annotations from this type system on the given Java type
-
irrelevantExtraMessage
public java.lang.String irrelevantExtraMessage()
Returns a string that can be passed to the "anno.on.irrelevant" error, giving information about which types are relevant.- Returns:
- a string that can be passed to the "anno.on.irrelevant" error, possibly the empty string
-
getDefaultValueAnnotatedType
public AnnotatedTypeMirror getDefaultValueAnnotatedType(javax.lang.model.type.TypeMirror typeMirror)
Return the type of the default value of the given type. The default value is 0, false, or null.- Parameters:
typeMirror
- a type- Returns:
- the annotated type of
type
's default value
-
createRequiresOrEnsuresQualifier
protected @Nullable javax.lang.model.element.AnnotationMirror createRequiresOrEnsuresQualifier(java.lang.String expression, javax.lang.model.element.AnnotationMirror qualifier, AnnotatedTypeMirror declaredType, Analysis.BeforeOrAfter preOrPost, @Nullable java.util.List<javax.lang.model.element.AnnotationMirror> preconds)
Creates aRequiresQualifier("...")
orEnsuresQualifier("...")
annotation for the given expression.This is of the form
@RequiresQualifier(expression="expression", qualifier=MyQual.class)
or@EnsuresQualifier(expression="expression", qualifier=MyQual.class)
, where "expression" is exactly the stringexpression
and MyQual is the annotation represented byqualifier
.Returns null if the expression is invalid when combined with the kind of annotation: for example, precondition annotations on "this" and parameters ("#1", etc.) are not supported, because receiver/parameter annotations should be inferred instead.
This implementation returns null if no annotation can be created, because the qualifier has elements/arguments, which
@RequiresQualifier
and@EnsuresQualifier
do not support. Subclasses may override this method to return qualifiers that do have arguments instead of returning null.- Parameters:
expression
- the expression to which the qualifier appliesqualifier
- the qualifier that must be presentdeclaredType
- the declared type of the expression, which is used to avoid inferring redundant pre- or postcondition annotationspreOrPost
- whether to return a precondition or postcondition annotationpreconds
- the list of precondition annotations; used to suppress redundant postconditions; non-null exactly whenpreOrPost
isBeforeOrAfter.BEFORE
- Returns:
- a
RequiresQualifier("...")
orEnsuresQualifier("...")
annotation for the given expression, or null
-
addSharedCFGForTree
public boolean addSharedCFGForTree(com.sun.source.tree.Tree tree, ControlFlowGraph cfg)
Add a new entry to the shared CFG. If this is a subchecker, this method delegates to the superchecker's GenericAnnotatedTypeFactory, if it exists. Duplicate keys must map to the same CFG.Calls to this method should be guarded by checking
hasOrIsSubchecker
; it is nonsensical to have a shared CFG when a checker is running alone.- Parameters:
tree
- the source code corresponding to cfgcfg
- the control flow graph to use for tree- Returns:
- whether a shared CFG was found to actually add to (duplicate keys also return true)
-
getSharedCFGForTree
public @Nullable ControlFlowGraph getSharedCFGForTree(com.sun.source.tree.Tree tree)
Get the shared control flow graph used fortree
by this checker's topmost superchecker. Returns null if no information is available about the given tree, or if this checker has a parent checker that does not have a GenericAnnotatedTypeFactory.Calls to this method should be guarded by checking
hasOrIsSubchecker
; it is nonsensical to have a shared CFG when a checker is running alone.- Parameters:
tree
- the tree whose CFG should be looked up- Returns:
- the CFG stored by this checker's uppermost superchecker for tree, or null if it is not available
-
getEnsuresQualifierIfResult
public @Nullable java.lang.Boolean getEnsuresQualifierIfResult(Contract.Kind kind, javax.lang.model.element.AnnotationMirror contractAnnotation)
If kind = CONDITIONALPOSTCONDITION, return the result element, e.g.EnsuresQualifierIf.result()
. Otherwise, return null.- Parameters:
kind
- the kind ofcontractAnnotation
contractAnnotation
- aRequiresQualifier
,EnsuresQualifier
, orEnsuresQualifierIf
- Returns:
- the
result
element ofcontractAnnotation
, or null if it doesn't have aresult
element
-
getContractExpressions
public @Nullable java.util.List<java.lang.String> getContractExpressions(Contract.Kind kind, javax.lang.model.element.AnnotationMirror contractAnnotation)
IfcontractAnnotation
is a framework annotation, return itsexpression
element. Otherwise,contractAnnotation
is defined in a checker. If kind = CONDITIONALPOSTCONDITION, return itsexpression
element, else return itsvalue
element.- Parameters:
kind
- the kind ofcontractAnnotation
contractAnnotation
- aRequiresQualifier
,EnsuresQualifier
, orEnsuresQualifierIf
- Returns:
- the
result
element ofcontractAnnotation
, or null if it doesn't have aresult
element
-
-