Class GenericAnnotatedTypeFactory<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value,Store>,TransferFunction extends CFAbstractTransfer<Value,Store,TransferFunction>,FlowAnalysis extends CFAbstractAnalysis<Value,Store,TransferFunction>>
- All Implemented Interfaces:
AnnotationProvider
- Direct Known Subclasses:
AccumulationAnnotatedTypeFactory
,BaseAnnotatedTypeFactory
,InitializationAnnotatedTypeFactory
,KeyForAnnotatedTypeFactory
,LockAnnotatedTypeFactory
AnnotatedTypeFactory
to optionally use flow-sensitive qualifier
inference.
It also adds other features: qualifier polymorphism, default annotations via DefaultFor
, user-specified defaults via DefaultQualifier
, standardization via DependentTypesHelper
, etc. Those features, and addComputedTypeAnnotations(com.sun.source.tree.Tree, org.checkerframework.framework.type.AnnotatedTypeMirror)
(other than
the part related to flow-sensitivity), could and should be in the superclass AnnotatedTypeFactory
; it is not clear why they are defined in this class.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static enum
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.CapturedTypeVarSubstitutor, AnnotatedTypeFactory.ParameterizedExecutableType
-
Field Summary
Modifier and TypeFieldDescriptionprotected FlowAnalysis
protected final boolean
Whether users may write type annotations on arrays.protected final CFGVisualizer<Value,
Store, TransferFunction> The CFGVisualizer to be used by all CFAbstractAnalysis instances.protected final ContractsFromMethod
To handle method pre- and postconditions.protected QualifierDefaults
to handle defaults specified by the userprotected DependentTypesHelper
To handle dependent type annotations and contract expressions.protected Store
An empty store.protected final IdentityHashMap<Tree,
Store> A mapping from methods (or other code blocks) to their exceptional exit store.protected static boolean
Should flow be used by default?protected @MonotonicNonNull AnalysisResult<Value,
Store> The result of the flow analysis.protected final Map<TransferInput<Value,
Store>, IdentityHashMap<Node, TransferResult<Value, Store>>> protected static final Pattern
Matches parameter expressions as they appear inEnsuresQualifier
andRequiresQualifier
annotations, e.g.final boolean
True if this checker either has one or more subcheckers, or if this checker is a subchecker.protected Store
protected Store
protected IdentityHashMap<MethodInvocationTree,
Store> A mapping from methods to their a list with all return statements and the corresponding store.protected QualifierPolymorphism
to handle any polymorphic typesprotected final IdentityHashMap<Tree,
Store> A mapping from methods (or other code blocks) to their regular exit store (used to check postconditions).final @Nullable Set<TypeMirror>
The Java types on which users may write this type system's type annotations.protected final IdentityHashMap<MethodTree,
List<org.plumelib.util.IPair<ReturnNode, TransferResult<Value, Store>>>> A mapping from methods to a list with all return statements and the corresponding store.protected final Map<ClassTree,
GenericAnnotatedTypeFactory.ScanState> Map from ClassTree to their dataflow analysis state.protected boolean
If true,setRoot(CompilationUnitTree)
should clear thesubcheckerSharedCFG
map, freeing memory.boolean
Should the analysis assume that side effects to a value can change the type of aliased references?protected @MonotonicNonNull Map<Tree,
ControlFlowGraph> Subcheckers share the same ControlFlowGraph for each analyzed code statement.protected TransferFunction
protected TreeAnnotator
to annotate types based on the given un-annotated typesprotected TypeAnnotator
to annotate types based on the given treeFields inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
ajavaTypes, annotatedForValueElement, artificialTreeToEnclosingElementMap, capturedTypeVarSubstitutor, checker, currentFileAjavaTypes, elements, ensuresQualifierExpressionElement, ensuresQualifierIfExpressionElement, ensuresQualifierIfListTM, ensuresQualifierIfListValueElement, ensuresQualifierIfResultElement, ensuresQualifierIfTM, ensuresQualifierListTM, ensuresQualifierListValueElement, ensuresQualifierTM, fieldInvariantFieldElement, fieldInvariantQualifierElement, fromExpressionTreeCache, fromMemberTreeCache, fromTypeTreeCache, hasQualifierParameterValueElement, ignoreRawTypeArguments, loader, methodValClassNameElement, methodValMethodNameElement, methodValParamsElement, noQualifierParameterValueElement, objectGetClass, processingEnv, qualHierarchy, qualifierUpperBounds, reflectionResolver, requiresQualifierExpressionElement, requiresQualifierListTM, requiresQualifierListValueElement, requiresQualifierTM, root, shouldCache, stubTypes, trees, typeArgumentInference, typeFormatter, typeHierarchy, types, typeVarSubstitutor, uid, wpiOutputFormat
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a type factory.protected
GenericAnnotatedTypeFactory
(BaseTypeChecker checker, boolean useFlow) Creates a type factory. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addAnnotationsFromDefaultForType
(@Nullable Element element, AnnotatedTypeMirror type) Adds default qualifiers based on the underlying type oftype
totype
.protected void
Adds default qualifiers for type-checked code by readingDefaultFor
andDefaultQualifierInHierarchy
meta-annotations.protected void
Adds the standard CLIMB defaults that do not conflict with previously added defaults.protected final void
addComputedTypeAnnotations
(Tree tree, AnnotatedTypeMirror type) This method is final; overrideaddComputedTypeAnnotations(Tree, AnnotatedTypeMirror, boolean)
instead.protected void
addComputedTypeAnnotations
(Tree tree, AnnotatedTypeMirror type, boolean iUseFlow) void
addComputedTypeAnnotations
(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)
.protected void
addComputedTypeAnnotationsForWarnRedundant
(Tree tree, AnnotatedTypeMirror type, boolean iUseFlow) void
Adds default annotations totype
.boolean
addSharedCFGForTree
(Tree tree, ControlFlowGraph cfg) Add a new entry to the shared CFG.protected void
Adds standard unchecked defaults that do not conflict with previously added defaults.protected void
analyze
(Queue<org.plumelib.util.IPair<ClassTree, Store>> classQueue, Queue<org.plumelib.util.IPair<LambdaExpressionTree, Store>> lambdaQueue, UnderlyingAST ast, List<CFAbstractAnalysis.FieldInitialValue<Value>> fieldValues, ClassTree currentClass, boolean isInitializationCode, boolean updateInitializationStore, boolean isStatic, @Nullable Store capturedStore) Analyze the ASTast
and store the result.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
Applies defaults for types in a class with an qualifier parameter.protected void
applyQualifierParameterDefaults
(Tree tree, AnnotatedTypeMirror type) Applies defaults for types in a class with an qualifier parameter.protected void
Flow analysis will be performed if all of the following are true.protected void
Check that a default qualifier (in at least one hierarchy) has been set and issue an error if not.constructorFromUse
(NewClassTree tree, boolean inferTypeArgs) protected void
constructorFromUsePreSubstitution
(NewClassTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type, boolean resolvePolyQuals) A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared constructor type before type variable substitution.protected final QualifierDefaults
CreateQualifierDefaults
which handles checker specified defaults, and initialize the createdQualifierDefaults
.protected @Nullable CFGVisualizer<Value,
Store, TransferFunction> Create a new CFGVisualizer.protected ContractsFromMethod
Creates anContractsFromMethod
and returns it.protected DefaultForTypeAnnotator
Creates anDefaultForTypeAnnotator
.protected DefaultQualifierForUseTypeAnnotator
Creates anDefaultQualifierForUseTypeAnnotator
.protected DependentTypesHelper
Creates aDependentTypesHelper
and returns it.protected FlowAnalysis
Returns the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis.Returns the appropriate transfer function that is used for the given org.checkerframework.dataflow analysis.protected QualifierDefaults
CreateQualifierDefaults
which handles checker specified defaults.protected QualifierPolymorphism
Creates theQualifierPolymorphism
instance which supports the QualifierPolymorphism mechanism.protected @Nullable AnnotationMirror
createRequiresOrEnsuresQualifier
(String expression, AnnotationMirror qualifier, AnnotatedTypeMirror declaredType, Analysis.BeforeOrAfter preOrPost, @Nullable List<AnnotationMirror> preconds) Creates aRequiresQualifier("...")
orEnsuresQualifier("...")
annotation for the given expression.protected TreeAnnotator
Returns aTreeAnnotator
that adds annotations to a type based on the contents of a tree.protected TypeAnnotator
Returns aDefaultForTypeAnnotator
that adds annotations to a type based on the content of the type itself.getAnnotatedTypeLhs
(Tree lhsTree) Returns the type of a left-hand side of an assignment.getAnnotatedTypeLhsNoTypeVarDefault
(Tree lhsTree) Returns the type of the left-hand side of an assignment without applying local variable defaults to type variables.Returns the type ofv + 1
orv - 1
wherev
is the expression in the postfixed increment or decrement expression.Returns the type of a varargs array of a method invocation or a constructor invocation.getAnnotationFromJavaExpression
(JavaExpression expr, Tree tree, Class<? extends Annotation> clazz) Returns the primary annotation on an expression, at a particular location.getAnnotationFromJavaExpressionString
(String expression, Tree tree, TreePath path, Class<? extends Annotation> clazz) Returns the primary annotation on expression if it were evaluated at path.getAnnotationMirrorFromJavaExpressionString
(String expression, Tree tree, TreePath currentPath) Returns the annotation mirror from dataflow forexpression
.getAnnotationsFromJavaExpression
(JavaExpression expr, Tree tree) Returns the primary annotations on an expression, at a particular location.The CFGVisualizer to be used by all CFAbstractAnalysis instances.getContractAnnotations
(org.checkerframework.afu.scenelib.el.AMethod m) Return the contract annotations (that is, pre- and post-conditions) for the given AMethod.Return the contract annotations (that is, pre- and post-conditions) for the given CallableDeclarationAnnos.getContractExpressions
(Contract.Kind kind, AnnotationMirror contractAnnotation) IfcontractAnnotation
is a framework annotation, return itsexpression
element.Returns the helper for method pre- and postconditions.getDefaultAnnotations
(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.Returns theDefaultForTypeAnnotator
.getDefaultValueAnnotatedType
(TypeMirror typeMirror) Return the type of the default value of the given type.Returns the DependentTypesHelper.Returns the empty store.getEnsuresQualifierIfResult
(Contract.Kind kind, AnnotationMirror contractAnnotation) If kind = CONDITIONALPOSTCONDITION, return the result element, e.g.getExceptionalExitStore
(Tree tree) Returns the exceptional exit store for a method or another code block (such as static initializers).getExplicitNewClassAnnos
(NewClassTree newClassTree) Returns the annotations explicitly written on a NewClassTree.protected List<AnnotatedTypeMirror>
getExplicitNewClassClassTypeArgs
(NewClassTree newClassTree) Returns the partially-annotated explicit class type arguments of the new class tree.org.plumelib.util.IPair<JavaExpression,
String> getExpressionAndOffsetFromJavaExpressionString
(String expression, TreePath currentPath) Produces the JavaExpression and offset associated with an expression.Returns the value of effectively final local variables.getFirstNodeOfKindForTree
(Tree tree, Class<T> kind) getInferredValueFor
(Tree tree) Returns the inferred value (by the org.checkerframework.dataflow analysis) for a given tree.Returns the return type of the methodm
.getNodesForTree
(Tree tree) final List<AnnotationMirror>
getPostconditionAnnotations
(String expression, AnnotatedTypeMirror inferredType, AnnotatedTypeMirror declaredType, List<AnnotationMirror> preconds) Returns a list of inferred@EnsuresQualifier
annotations for the given expression.getPostconditionAnnotations
(org.checkerframework.afu.scenelib.el.AMethod m, List<AnnotationMirror> preconds) Return the postcondition annotations for the given AMethod.getPostconditionAnnotations
(WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos methodAnnos, List<AnnotationMirror> preconds) Return the postcondition annotations for the given CallableDeclarationAnnos.final List<AnnotationMirror>
getPreconditionAnnotations
(String expression, AnnotatedTypeMirror inferredType, AnnotatedTypeMirror declaredType) Returns a list of inferred@RequiresQualifier
annotations for the given expression.getPreconditionAnnotations
(org.checkerframework.afu.scenelib.el.AMethod m) Return the precondition annotations for the given AMethod.getPreconditionAnnotations
(WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos methodAnnos) Return the precondition annotations for the given CallableDeclarationAnnos.protected List<AnnotationMirror>
getPreOrPostconditionAnnotations
(String expression, AnnotatedTypeMirror inferredType, AnnotatedTypeMirror declaredType, Analysis.BeforeOrAfter preOrPost, @Nullable List<AnnotationMirror> preconds) Creates pre- and postcondition annotations.Gives the currentQualifierPolymorphism
instance which supports the QualifierPolymorphism mechanism.getRegularExitStore
(Tree tree) Returns the regular exit store for a method or another code block (such as static initializers).List<org.plumelib.util.IPair<ReturnNode,
TransferResult<Value, Store>>> getReturnStatementStores
(MethodTree methodTree) Returns a list of all return statements ofmethod
paired with their correspondingTransferResult
.getSharedCFGForTree
(Tree tree) Get the shared control flow graph used fortree
by this checker's topmost superchecker.boolean
Should the local variable default annotation be applied to type variables?protected final String
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.getStoreAfter
(Tree tree) Returns the store immediately after a given tree.getStoreAfter
(Set<Node> nodes) Returns the store immediately after a given set of nodes.getStoreAfter
(Node node) Returns the store immediately after a givenNode
.getStoreBefore
(Tree tree) Returns the store immediately before a givenTree
.getStoreBefore
(Set<Node> nodes) Returns the store immediately before a given Set ofNode
s.getStoreBefore
(Node node) Returns the store immediately before a given node.final Set<Class<? extends Annotation>>
Returns an immutable set of the monotonic type qualifiers supported by this checker.final <T extends GenericAnnotatedTypeFactory<?,
?, ?, ?>>
TgetTypeFactoryOfSubchecker
(Class<? extends BaseTypeChecker> subCheckerClass) Returns the type factory used by a subchecker.<T extends GenericAnnotatedTypeFactory<?,
?, ?, ?>>
@Nullable TgetTypeFactoryOfSubcheckerOrNull
(Class<? extends BaseTypeChecker> subCheckerClass) Returns the type factory used by a subchecker.protected void
Handle the visualization of the CFG, if necessary.Returns a string that can be passed to the "anno.on.irrelevant" error, giving information about which types are relevant.boolean
isIgnoredExceptionType
(TypeMirror typeMirror) Returns true iftypeMirror
is an exception type that should be ignored.final boolean
isRelevant
(TypeMirror tm) Returns true if users can write type annotations from this type system directly on the given Java type.final boolean
Returns true if users can write type annotations from this type system directly on the given Java type.protected boolean
Returns true if users can write type annotations from this type system on the given Java type.boolean
isUnreachable
(ExpressionTree exprTree) Returns true if theexprTree
is unreachable.methodFromUse
(MethodInvocationTree tree, boolean inferTypeArg) void
methodFromUsePreSubstitution
(ExpressionTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type, boolean resolvePolyQuals) A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared method type before type variable substitution.parseJavaExpressionString
(String expression, TreePath currentPath) Produces the JavaExpression as ifexpression
were written atcurrentPath
.protected void
performFlowAnalysis
(ClassTree classTree) Perform a org.checkerframework.dataflow analysis over a single class tree and its nested classes.protected void
Perform any additional operations on a CFG.void
postAsMemberOf
(AnnotatedTypeMirror type, AnnotatedTypeMirror owner, Element element) A callback method for the AnnotatedTypeFactory subtypes to customize AnnotatedTypes.asMemberOf().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.void
preProcessClassTree
(ClassTree classTree) Performs flow-sensitive type refinement onclassTree
if this type factory is configured to do so.void
Set the CompilationUnitTree that should be used.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, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, applyCaptureConversion, applyCaptureConversion, applyUnboxing, areSameByClass, binaryTreeArgTypes, binaryTreeArgTypes, canonicalAnnotation, checkInvalidOptionsInferSignatures, compoundAssignmentTreeArgTypes, constructorFromUse, constructorFromUseWithoutTypeArgInference, containsCapturedTypes, containsSameByClass, createAnnotatedTypeFormatter, createAnnotationClassLoader, createAnnotationFormatter, createQualifierHierarchy, createQualifierUpperBounds, createSupportedTypeQualifiers, createTypeArgumentInference, createTypeHierarchy, createTypeVariableSubstitutor, declarationFromElement, doesAnnotatedForApplyToThisChecker, fromElement, fromElement, fromElement, getAnnotatedNullType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFormatter, getAnnotatedTypeFromTypeTree, getAnnotationByClass, getAnnotationFormatter, getAnnotationMirror, getAnnotationWithMetaAnnotation, getBoxedType, getBundledTypeQualifiers, getCacheSize, getChecker, getCheckerNames, getContractExpressions, getContractListValues, getDeclAnnotation, getDeclAnnotationNoAliases, getDeclAnnotations, getDeclAnnotationWithMetaAnnotation, getDefaultTypeDeclarationBounds, getDummyAssignedTo, getElementUtils, getEnclosingClassOrMethod, getEnclosingElementForArtificialTree, getEnclosingSubType, getEnclosingType, getEnumConstructorQualifiers, getExpressionAndOffset, getFieldInvariantAnnotationTree, getFieldInvariantDeclarationAnnotations, getFieldInvariants, getFnInterfaceFromTree, getFunctionTypeFromTree, getFunctionTypeFromTree, getImplicitReceiverType, getIterableElementType, getIterableElementType, getMethodReturnType, getNarrowedAnnotations, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getQualifierParameterHierarchies, getQualifierParameterHierarchies, getQualifierUpperBounds, getReceiverType, getResultingTypeOfConstructorMemberReference, getSelfType, getStringType, getSupportedTypeQualifierNames, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeDeclarationBounds, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, getUnboxedType, getVisitorTreePath, getWholeProgramInference, getWidenedAnnotations, getWidenedType, getWidenedType, hasExplicitNoQualifierParameterInHierarchy, hasExplicitQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, initializeAtm, initializeReflectionResolution, isDeterministic, isFromByteCode, isFromStubFile, isImmutable, isSideEffectFree, isSupportedQualifier, isSupportedQualifier, isSupportedQualifier, isTop, isWithinConstructor, logGat, makeConditionConsistentWithOtherMethod, mergeAnnotationFileAnnosIntoType, methodFromUse, methodFromUse, methodFromUse, methodFromUseWithoutTypeArgInference, methodFromUseWithoutTypeArgInference, negateConstant, order, parseAnnotationFiles, postProcessClassTree, replaceAnnotations, replaceAnnotations, setEnclosingElementForArtificialTree, setVisitorTreePath, shouldWarnIfStubRedundantWithBytecode, toAnnotatedType, toString, type, wpiAdjustForUpdateField, wpiAdjustForUpdateNonField, wpiPrepareMethodForWriting, wpiPrepareMethodForWriting, wpiShouldInferTypesForReceivers
-
Field Details
-
typeAnnotator
to annotate types based on the given tree -
treeAnnotator
to annotate types based on the given un-annotated types -
poly
to handle any polymorphic types -
defaults
to handle defaults specified by the user -
dependentTypesHelper
To handle dependent type annotations and contract expressions. -
contractsUtils
To handle method pre- and postconditions. -
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 arraysAreRelevantWhether users may write type annotations on arrays. Ignored unlessrelevantJavaTypes
is non-null. -
flowByDefault
protected static boolean flowByDefaultShould flow be used by default? -
sideEffectsUnrefineAliases
public boolean sideEffectsUnrefineAliasesShould 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 hasOrIsSubcheckerTrue 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
An empty store. -
analysis
-
transfer
-
initializationStore
-
initializationStaticStore
-
flowResultAnalysisCaches
protected final Map<TransferInput<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value, flowResultAnalysisCachesStore>>, IdentityHashMap<Node, TransferResult<Value extends CFAbstractValue<Value>, Store extends CFAbstractStore<Value, Store>>>> Caches forAnalysisResult.runAnalysisFor(Node, Analysis.BeforeOrAfter, TransferInput, IdentityHashMap, Map)
. This cache is enabled ifAnnotatedTypeFactory.shouldCache
is true. The cache size is derived fromAnnotatedTypeFactory.getCacheSize()
. -
scannedClasses
Map from ClassTree to their dataflow analysis state. -
flowResult
protected @MonotonicNonNull AnalysisResult<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value, flowResultStore>> 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
A mapping from methods (or other code blocks) to their regular exit store (used to check postconditions). -
exceptionalExitStores
protected final IdentityHashMap<Tree,Store extends CFAbstractStore<Value, exceptionalExitStoresStore>> A mapping from methods (or other code blocks) to their exceptional exit store. -
returnStatementStores
protected final IdentityHashMap<MethodTree,List<org.plumelib.util.IPair<ReturnNode, returnStatementStoresTransferResult<Value extends CFAbstractValue<Value>, Store extends CFAbstractStore<Value, Store>>>>> A mapping from methods to a list with all return statements and the corresponding store. -
methodInvocationStores
protected IdentityHashMap<MethodInvocationTree,Store extends CFAbstractStore<Value, methodInvocationStoresStore>> A mapping from methods to their a list with all return statements and the corresponding store. -
cfgVisualizer
protected final CFGVisualizer<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value, cfgVisualizerStore>, TransferFunction extends CFAbstractTransfer<Value, Store, TransferFunction>> The CFGVisualizer to be used by all CFAbstractAnalysis instances. -
formalParameterPattern
Matches parameter expressions as they appear inEnsuresQualifier
andRequiresQualifier
annotations, e.g. "#1", "#2", etc.
-
-
Constructor Details
-
GenericAnnotatedTypeFactory
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
Creates a type factory. Its compilation unit is not yet set.- Parameters:
checker
- the checker to which this type factory belongs
-
-
Method Details
-
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
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
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
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:
-
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
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
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
Creates anDefaultQualifierForUseTypeAnnotator
.- Returns:
- a new
DefaultQualifierForUseTypeAnnotator
-
createDefaultForTypeAnnotator
Creates anDefaultForTypeAnnotator
.- Returns:
- a new
DefaultForTypeAnnotator
-
getDefaultForTypeAnnotator
Returns theDefaultForTypeAnnotator
.- Returns:
- the
DefaultForTypeAnnotator
-
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
Creates aDependentTypesHelper
and returns it. UsegetDependentTypesHelper()
to access the value.- Returns:
- a new
DependentTypesHelper
-
getDependentTypesHelper
Returns the DependentTypesHelper.- Returns:
- the DependentTypesHelper
-
createContractsFromMethod
Creates anContractsFromMethod
and returns it.- Returns:
- a new
ContractsFromMethod
-
getContractsFromMethod
Returns the helper for method pre- and postconditions.- Returns:
- the helper for method pre- and postconditions
-
getExplicitNewClassClassTypeArgs
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
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
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
CreateQualifierDefaults
which handles checker specified defaults. Sub-classes override this method to provide a differentQualifierDefault
implementation. -
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
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
Adds the standard CLIMB defaults that do not conflict with previously added defaults.- Parameters:
defs
-QualifierDefaults
object to which defaults are added
-
addUncheckedStandardDefaults
Adds standard unchecked defaults that do not conflict with previously added defaults.- Parameters:
defs
-QualifierDefaults
object to which defaults are added
-
checkForDefaultQualifierInHierarchy
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
Creates theQualifierPolymorphism
instance which supports the QualifierPolymorphism mechanism.- Returns:
- the QualifierPolymorphism instance to use
-
getQualifierPolymorphism
Gives the currentQualifierPolymorphism
instance which supports the QualifierPolymorphism mechanism.- Returns:
- the QualifierPolymorphism instance to use
-
postDirectSuperTypes
protected void postDirectSuperTypes(AnnotatedTypeMirror type, 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
-
getAnnotationFromJavaExpressionString
public @Nullable AnnotationMirror getAnnotationFromJavaExpressionString(String expression, Tree tree, TreePath path, Class<? extends 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 AnnotationMirror getAnnotationFromJavaExpression(JavaExpression expr, Tree tree, Class<? extends 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, 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(String expression, 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,String> getExpressionAndOffsetFromJavaExpressionString(String expression, 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 AnnotationMirror getAnnotationMirrorFromJavaExpressionString(String expression, Tree tree, 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
-
isUnreachable
Returns true if theexprTree
is unreachable. This is a conservative estimate and may returnfalse
even though theexprTree
is unreachable.- Parameters:
exprTree
- an expression tree- Returns:
- true if the
exprTree
is unreachable
-
getRegularExitStore
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
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 List<org.plumelib.util.IPair<ReturnNode,TransferResult<Value, getReturnStatementStoresStore>>> (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
Returns the store immediately before a givenTree
.- Returns:
- the store immediately before a given
Tree
-
getStoreBefore
Returns the store immediately before a given Set ofNode
s.- Returns:
- the store immediately before a given Set of
Node
s
-
getStoreBefore
Returns the store immediately before a given node.- Parameters:
node
- a node whose pre-store to return- Returns:
- the store immediately before
node
-
getStoreAfter
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
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
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
-
getFirstNodeOfKindForTree
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. -
getFinalLocalValues
Returns the value of effectively final local variables.- Returns:
- the value of effectively final local variables
-
performFlowAnalysis
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(Queue<org.plumelib.util.IPair<ClassTree, Store>> classQueue, Queue<org.plumelib.util.IPair<LambdaExpressionTree, Store>> lambdaQueue, UnderlyingAST ast, List<CFAbstractAnalysis.FieldInitialValue<Value>> fieldValues, 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:
-
isIgnoredExceptionType
Returns true iftypeMirror
is an exception type that should be ignored.- Parameters:
typeMirror
- an exception type- Returns:
- true if
typeMirror
is an exception type that should be ignored
-
postAnalyze
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
Handle the visualization of the CFG, if necessary.- Parameters:
cfg
- the CFG
-
getAnnotatedTypeLhsNoTypeVarDefault
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)
.InferenceFactory.assignedToVariable(AnnotatedTypeFactory, Tree)
explains why a different type is used.- Parameters:
lhsTree
- left-hand side of an assignment- Returns:
- AnnotatedTypeMirror of
lhsTree
-
getAnnotatedTypeLhs
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
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
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
protected AnnotatedTypeFactory.ParameterizedExecutableType constructorFromUse(NewClassTree tree, boolean inferTypeArgs) Description copied from class:AnnotatedTypeFactory
The implementation ofAnnotatedTypeFactory.constructorFromUse(NewClassTree)
andAnnotatedTypeFactory.constructorFromUseWithoutTypeArgInference(NewClassTree)
.- Overrides:
constructorFromUse
in classAnnotatedTypeFactory
- Parameters:
tree
- the constructor invocation treeinferTypeArgs
- whether the type arguments should be inferred- Returns:
- the annotated type of the invoked constructor (as an executable type) and the type arguments
-
constructorFromUsePreSubstitution
protected void constructorFromUsePreSubstitution(NewClassTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type, boolean resolvePolyQuals) 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 substitutionresolvePolyQuals
- whether to resolve polymorphic qualifiers
-
getMethodReturnType
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
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 type argument of raw types. (SeeAnnotatedTypeMirror.AnnotatedWildcardType.isTypeArgOfRawType()
.)- Overrides:
addDefaultAnnotations
in classAnnotatedTypeFactory
- Parameters:
type
- annotated type to which default annotations are added
-
addComputedTypeAnnotations
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
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
-
getDefaultAnnotationsForWarnRedundant
public AnnotatedTypeMirror getDefaultAnnotationsForWarnRedundant(Tree tree, AnnotatedTypeMirror type) LikegetDefaultAnnotations(Tree, AnnotatedTypeMirror)
.For use ONLY by the
-AwarnRedundantAnnotations
command-line option. May add fewer annotations thangetDefaultAnnotations(Tree, AnnotatedTypeMirror)
.- Parameters:
tree
- tree where the type is usedtype
- type to determine the defaulted version for- Returns:
- the annotated type mirror with default annotations
-
addComputedTypeAnnotations
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
-
addComputedTypeAnnotationsForWarnRedundant
protected void addComputedTypeAnnotationsForWarnRedundant(Tree tree, AnnotatedTypeMirror type, boolean iUseFlow) LikeaddComputedTypeAnnotations(Tree, AnnotatedTypeMirror, boolean)
.For use ONLY by the
-AwarnRedundantAnnotations
command-line option. May add fewer annotations thanaddComputedTypeAnnotations(Tree, AnnotatedTypeMirror, boolean)
.- Parameters:
tree
- an AST nodetype
- the type obtained from treeiUseFlow
- whether to use information from dataflow analysis
-
checkAndPerformFlowAnalysis
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
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
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
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
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
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
protected AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(MethodInvocationTree tree, boolean inferTypeArg) Description copied from class:AnnotatedTypeFactory
The implementation ofAnnotatedTypeFactory.methodFromUse(MethodInvocationTree)
andAnnotatedTypeFactory.methodFromUseWithoutTypeArgInference(MethodInvocationTree)
.- Overrides:
methodFromUse
in classAnnotatedTypeFactory
- Parameters:
tree
- a method invocation treeinferTypeArg
- whether type arguments should be inferred- Returns:
- the type of the invoked method, any explicit type arguments, and if
inferTypeArgs
is true, any inferred type arguments
-
methodFromUsePreSubstitution
public void methodFromUsePreSubstitution(ExpressionTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type, boolean resolvePolyQuals) 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 substitutionresolvePolyQuals
- whether to resolve polymorphic qualifiers
-
typeVariablesFromUse
public List<AnnotatedTypeParameterBounds> typeVariablesFromUse(AnnotatedTypeMirror.AnnotatedDeclaredType type, 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
Returns the empty store.- Returns:
- the empty store
-
getTypeFactoryOfSubchecker
public final <T extends GenericAnnotatedTypeFactory<?,?, T getTypeFactoryOfSubchecker?, ?>> (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
public <T extends GenericAnnotatedTypeFactory<?,?, @Nullable T getTypeFactoryOfSubcheckerOrNull?, ?>> (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:
-
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:
-
createCFGVisualizer
Create a new CFGVisualizer.- Returns:
- a new CFGVisualizer, or null if none will be used on this run
-
getCFGVisualizer
The CFGVisualizer to be used by all CFAbstractAnalysis instances. -
postAsMemberOf
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 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
Returns true if users can write type annotations from this type system directly on the given Java type.For a compound type, returns true only if a programmer may write a type qualifier on the top level of the compound type. That is, this method may return false, when 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
Returns true if users can write type annotations from this type system directly on the given Java type.For a compound type, returns true only if it a programmer may write a type qualifier on the top level of the compound type. That is, this method may return false, when 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
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
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
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
-
getContractAnnotations
public List<AnnotationMirror> getContractAnnotations(org.checkerframework.afu.scenelib.el.AMethod m) Return the contract annotations (that is, pre- and post-conditions) for the given AMethod. Does not modify the AMethod.This overload must only be called when using WholeProgramInferenceScenes.
- Parameters:
m
- the AFU representation of a method- Returns:
- the contract annotations for the method
-
getPreconditionAnnotations
public List<AnnotationMirror> getPreconditionAnnotations(org.checkerframework.afu.scenelib.el.AMethod m) Return the precondition annotations for the given AMethod. Does not modify the AMethod.This overload must only be called when using WholeProgramInferenceScenes.
- Parameters:
m
- the AFU representation of a method- Returns:
- the precondition annotations for the method
-
getPostconditionAnnotations
public List<AnnotationMirror> getPostconditionAnnotations(org.checkerframework.afu.scenelib.el.AMethod m, List<AnnotationMirror> preconds) Return the postcondition annotations for the given AMethod. Does not modify the AMethod.This overload must only be called when using WholeProgramInferenceScenes.
- Parameters:
m
- the AFU representation of a methodpreconds
- the precondition annotations for the method; used to suppress redundant postconditions- Returns:
- the postcondition annotations for the method
-
getContractAnnotations
public List<AnnotationMirror> getContractAnnotations(WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos methodAnnos) Return the contract annotations (that is, pre- and post-conditions) for the given CallableDeclarationAnnos. Does not modify the CallableDeclarationAnnos.This overload must only be called when using WholeProgramInferenceJavaParserStorage.
- Parameters:
methodAnnos
- annotation data for a method- Returns:
- contract annotations for the method
-
getPreconditionAnnotations
public List<AnnotationMirror> getPreconditionAnnotations(WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos methodAnnos) Return the precondition annotations for the given CallableDeclarationAnnos. Does not modify the CallableDeclarationAnnos.This overload must only be called when using WholeProgramInferenceJavaParserStorage.
- Parameters:
methodAnnos
- annotation data for a method- Returns:
- precondition annotations for the method
-
getPostconditionAnnotations
public List<AnnotationMirror> getPostconditionAnnotations(WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos methodAnnos, List<AnnotationMirror> preconds) Return the postcondition annotations for the given CallableDeclarationAnnos. Does not modify the CallableDeclarationAnnos.This overload must only be called when using WholeProgramInferenceJavaParserStorage.
- Parameters:
methodAnnos
- annotation data for a methodpreconds
- the precondition annotations for the method; used to suppress redundant postconditions- Returns:
- postcondition annotations for the method
-
getPreconditionAnnotations
public final List<AnnotationMirror> getPreconditionAnnotations(String expression, AnnotatedTypeMirror inferredType, AnnotatedTypeMirror declaredType) Returns a list of inferred@RequiresQualifier
annotations for the given expression. By default this list does not include any qualifier that has elements/arguments, which@RequiresQualifier
does not support. Subclasses may remove this restriction by overridingcreateRequiresOrEnsuresQualifier(java.lang.String, javax.lang.model.element.AnnotationMirror, org.checkerframework.framework.type.AnnotatedTypeMirror, org.checkerframework.dataflow.analysis.Analysis.BeforeOrAfter, java.util.List<javax.lang.model.element.AnnotationMirror>)
.Each annotation in the list is of the form
@RequiresQualifier(expression="expression", qualifier=MyQual.class)
.expression
must be a valid Java Expression string, in the same format used byRequiresQualifier
.- Parameters:
expression
- an expressioninferredType
- the type of the expression, on method entrydeclaredType
- the declared type of the expression- Returns:
- precondition annotations for the element (possibly an empty list)
-
getPostconditionAnnotations
public final List<AnnotationMirror> getPostconditionAnnotations(String expression, AnnotatedTypeMirror inferredType, AnnotatedTypeMirror declaredType, List<AnnotationMirror> preconds) Returns a list of inferred@EnsuresQualifier
annotations for the given expression. By default this list does not include any qualifier that has elements/arguments, which@EnsuresQualifier
does not support; and, preconditions are not used to suppress redundant postconditions. Subclasses may remove these restrictions by overridingcreateRequiresOrEnsuresQualifier(java.lang.String, javax.lang.model.element.AnnotationMirror, org.checkerframework.framework.type.AnnotatedTypeMirror, org.checkerframework.dataflow.analysis.Analysis.BeforeOrAfter, java.util.List<javax.lang.model.element.AnnotationMirror>)
.Each annotation in the list is of the form
@EnsuresQualifier(expression="expression", qualifier=MyQual.class)
.expression
must be a valid Java Expression string, in the same format used byEnsuresQualifier
.- Parameters:
expression
- an expressioninferredType
- the type of the expression, on method exitdeclaredType
- the declared type of the expressionpreconds
- the precondition annotations for the method; used to suppress redundant postconditions- Returns:
- postcondition annotations for the element (possibly an empty list)
-
getPreOrPostconditionAnnotations
protected List<AnnotationMirror> getPreOrPostconditionAnnotations(String expression, AnnotatedTypeMirror inferredType, AnnotatedTypeMirror declaredType, Analysis.BeforeOrAfter preOrPost, @Nullable List<AnnotationMirror> preconds) Creates pre- and postcondition annotations. Helper method forgetPreconditionAnnotations(org.checkerframework.afu.scenelib.el.AMethod)
andgetPostconditionAnnotations(org.checkerframework.afu.scenelib.el.AMethod, java.util.List<javax.lang.model.element.AnnotationMirror>)
.Returns a
@RequiresQualifier
or@EnsuresQualifier
annotation for the given expression. Returns an empty list if none can be created, because the qualifier has elements/arguments, which@RequiresQualifier
and@EnsuresQualifier
do not support.This implementation makes no assumptions about preconditions suppressing postconditions, but subclasses may do so.
- Parameters:
expression
- an expression whose type annotations to returninferredType
- the type of the expression, on method entry or exit (depending on the value ofpreOrPost
)declaredType
- the declared type of the expression, which is used to determine if the inferred type supplies no additional information beyond the declared typepreOrPost
- whether to return preconditions or postconditionspreconds
- the precondition annotations for the method; used to suppress redundant postconditions; non-null exactly whenpreOrPost
isAFTER
- Returns:
- precondition or postcondition annotations for the element (possibly an empty list)
-
createRequiresOrEnsuresQualifier
protected @Nullable AnnotationMirror createRequiresOrEnsuresQualifier(String expression, AnnotationMirror qualifier, AnnotatedTypeMirror declaredType, Analysis.BeforeOrAfter preOrPost, @Nullable List<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
-
getEnsuresQualifierIfResult
public @Nullable Boolean getEnsuresQualifierIfResult(Contract.Kind kind, 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 List<String> getContractExpressions(Contract.Kind kind, 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
-