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
Nested ClassesModifier and TypeClassDescriptionprotected static enumTrack 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
FieldsModifier and TypeFieldDescriptionprotected FlowAnalysisanalysis.getResult()is the result of the most recent analysis.protected final booleanWhether users may write type annotations on arrays.protected final CFGVisualizer<Value, Store, TransferFunction> The CFGVisualizer to be used by all CFAbstractAnalysis instances.protected final ContractsFromMethodTo handle method pre- and postconditions.protected QualifierDefaultsto handle defaults specified by the userprotected DependentTypesHelperTo handle dependent type annotations and contract expressions.protected StoreAn empty store.protected final IdentityHashMap<Tree, Store> A mapping from methods (or other code blocks) to their exceptional exit store.protected static booleanShould flow be used by default?protected @MonotonicNonNull AnalysisResult<Value, Store> The merged result of all the analyses performed in the current compilation unit.protected final Map<TransferInput<Value, Store>, IdentityHashMap<Node, TransferResult<Value, Store>>> protected static final PatternMatches parameter expressions as they appear inEnsuresQualifierandRequiresQualifierannotations, e.g.final booleanTrue if this checker either has one or more subcheckers, or if this checker is a subchecker.protected Storeprotected Storeprotected IdentityHashMap<MethodInvocationTree, Store> A mapping from methods to their a list with all return statements and the corresponding store.protected QualifierPolymorphismto 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 booleanIf true,setRoot(CompilationUnitTree)should clear thesubcheckerSharedCFGmap, freeing memory.booleanShould 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 TransferFunctionprotected TreeAnnotatorto annotate types based on the given un-annotated typesprotected TypeAnnotatorto 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, typeInformationPresenter, types, typeVarSubstitutor, uid, wpiOutputFormat -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a type factory.protectedGenericAnnotatedTypeFactory(BaseTypeChecker checker, boolean useFlow) Creates a type factory. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAnnotationsFromDefaultForType(@Nullable Element element, AnnotatedTypeMirror type) Adds default qualifiers based on the underlying type oftypetotype.protected voidAdds default qualifiers for type-checked code by readingDefaultForandDefaultQualifierInHierarchymeta-annotations.protected voidAdds the standard CLIMB defaults that do not conflict with previously added defaults.protected final voidaddComputedTypeAnnotations(Tree tree, AnnotatedTypeMirror type) This method is final; overrideaddComputedTypeAnnotations(Tree, AnnotatedTypeMirror, boolean)instead.protected voidaddComputedTypeAnnotations(Tree tree, AnnotatedTypeMirror type, boolean iUseFlow) voidaddComputedTypeAnnotations(Element elt, AnnotatedTypeMirror type) To add annotations to the type of method or constructor parameters, add aTypeAnnotatorusingcreateTypeAnnotator()and see the comment inTypeAnnotator.visitExecutable(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType, Void).protected voidaddComputedTypeAnnotationsForWarnRedundant(Tree tree, AnnotatedTypeMirror type, boolean iUseFlow) voidAdds default annotations totype.booleanaddSharedCFGForTree(Tree tree, ControlFlowGraph cfg) Add a new entry to the shared CFG.protected voidAdds standard unchecked defaults that do not conflict with previously added defaults.protected voidanalyze(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 ASTastand store the result.Returns the annotations that should appear on the given irrelevant Java type.protected voidapplyInferredAnnotations(AnnotatedTypeMirror type, Value inferred) Applies the annotations inferred by the org.checkerframework.dataflow analysis to the typetype.protected voidapplyQualifierParameterDefaults(Tree tree, AnnotatedTypeMirror type) Applies defaults for types in a class with an qualifier parameter.protected voidApplies defaults for types in a class with an qualifier parameter.protected voidFlow analysis will be performed if all of the following are true.protected voidCheck that a default qualifier (in at least one hierarchy) has been set and issue an error if not.constructorFromUse(NewClassTree tree, boolean inferTypeArgs) protected voidconstructorFromUsePreSubstitution(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 QualifierDefaultsCreateQualifierDefaultswhich handles checker specified defaults, and initialize the createdQualifierDefaults.protected @Nullable CFGVisualizer<Value, Store, TransferFunction> Create a new CFGVisualizer.protected ContractsFromMethodCreates anContractsFromMethodand returns it.protected DefaultForTypeAnnotatorCreates anDefaultForTypeAnnotator.protected DefaultQualifierForUseTypeAnnotatorCreates anDefaultQualifierForUseTypeAnnotator.protected DependentTypesHelperCreates aDependentTypesHelperand returns it.protected FlowAnalysisReturns 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 QualifierDefaultsCreateQualifierDefaultswhich handles checker specified defaults.protected QualifierPolymorphismCreates theQualifierPolymorphisminstance which supports the QualifierPolymorphism mechanism.protected @Nullable AnnotationMirrorcreateRequiresOrEnsuresQualifier(String expression, AnnotationMirror qualifier, AnnotatedTypeMirror declaredType, Analysis.BeforeOrAfter preOrPost, @Nullable List<AnnotationMirror> preconds) Creates aRequiresQualifier("...")orEnsuresQualifier("...")annotation for the given expression.protected TreeAnnotatorReturns aTreeAnnotatorthat adds annotations to a type based on the contents of a tree.protected TypeAnnotatorReturns aDefaultForTypeAnnotatorthat 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 + 1orv - 1wherevis 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 withclazzonexpr's type, at a particular location.getAnnotationFromJavaExpressionString(String expression, Tree tree, TreePath path, Class<? extends Annotation> clazz) Returns the primary annotation withclazzonexpression's type, at a particular location.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) IfcontractAnnotationis a framework annotation, return itsexpressionelement.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@EnsuresQualifierannotations 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@RequiresQualifierannotations 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 currentQualifierPolymorphisminstance 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 ofmethodpaired with their correspondingTransferResult.getSharedCFGForTree(Tree tree) Get the shared control flow graph used fortreeby this checker's topmost superchecker.booleanShould the local variable default annotation be applied to type variables?protected final StringCreates 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 ofNodes.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 SourceChecker> subCheckerClass) Returns the type factory used by a subchecker.<T extends GenericAnnotatedTypeFactory<?,?, ?, ?>>
@Nullable TgetTypeFactoryOfSubcheckerOrNull(Class<? extends SourceChecker> subCheckerClass) Returns the type factory used by a subchecker.protected voidHandle 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.booleanisIgnoredExceptionType(TypeMirror typeMirror) Returns true iftypeMirroris an exception type that should be ignored.final booleanisRelevant(TypeMirror tm) Returns true if users can write type annotations from this type system directly on the given Java type.final booleanReturns true if users can write type annotations from this type system directly on the given Java type.protected booleanReturns true if users can write type annotations from this type system on the given Java type.booleanisUnreachable(ExpressionTree exprTree) Returns true if theexprTreeis unreachable.methodFromUse(MethodInvocationTree tree, boolean inferTypeArg) voidmethodFromUsePreSubstitution(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 ifexpressionwere written atcurrentPath.protected voidperformFlowAnalysis(ClassTree classTree) Perform a org.checkerframework.dataflow analysis over a single class tree and its nested classes.protected voidPerform any additional operations on a CFG.voidpostAsMemberOf(AnnotatedTypeMirror type, AnnotatedTypeMirror owner, Element element) A callback method for the AnnotatedTypeFactory subtypes to customize AnnotatedTypes.asMemberOf().protected voidpostDirectSuperTypes(AnnotatedTypeMirror type, List<? extends AnnotatedTypeMirror> supertypes) A callback method for the AnnotatedTypeFactory subtypes to customize directSupertypes().protected voidpostInit()Actions that logically belong in the constructor, but need to run after the subclass constructor has completed.voidpreProcessClassTree(ClassTree classTree) Performs flow-sensitive type refinement onclassTreeif this type factory is configured to do so.voidSet 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, createTypeInformationPresenter, 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 unlessrelevantJavaTypesis 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
analysis.getResult()is the result of the most recent analysis. Compare toflowResult. -
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.shouldCacheis true. The cache size is derived fromAnnotatedTypeFactory.getCacheSize().- See Also:
-
scannedClasses
Map from ClassTree to their dataflow analysis state. -
flowResult
protected @MonotonicNonNull AnalysisResult<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value, flowResultStore>> The merged result of all the analyses performed in the current compilation unit. 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 inEnsuresQualifierandRequiresQualifierannotations, 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:AnnotatedTypeFactoryActions 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:
postInitin classAnnotatedTypeFactory
-
preProcessClassTree
Performs flow-sensitive type refinement onclassTreeif this type factory is configured to do so.- Overrides:
preProcessClassTreein classAnnotatedTypeFactory- Parameters:
classTree- tree on which to perform flow-sensitive type refinement
-
setRoot
Description copied from class:AnnotatedTypeFactorySet the CompilationUnitTree that should be used.- Overrides:
setRootin 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 aTreeAnnotatorthat adds annotations to a type based on the contents of a tree.The default tree annotator is a
ListTreeAnnotatorof the following:PropagationTreeAnnotator: Propagates annotations from subtreesLiteralTreeAnnotator: Adds annotations based onQualifierForLiteralsmeta-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 aDefaultForTypeAnnotatorthat adds annotations to a type based on the content of the type itself.Subclass may override this method. The default type annotator is a
ListTypeAnnotatorof the following:IrrelevantTypeAnnotator: Adds top to types not listed in the@RelevantJavaTypesannotation 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 aDependentTypesHelperand returns it. UsegetDependentTypesHelper()to access the value.- Returns:
- a new
DependentTypesHelper
-
getDependentTypesHelper
Returns the DependentTypesHelper.- Returns:
- the DependentTypesHelper
-
createContractsFromMethod
Creates anContractsFromMethodand 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:AnnotatedTypeFactoryReturns the partially-annotated explicit class type arguments of the new class tree. TheAnnotatedTypeMirroronly include the annotations explicitly written on the explict type arguments. (IfnewClassuse 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:
getExplicitNewClassClassTypeArgsin classAnnotatedTypeFactory- Parameters:
newClassTree- a new class tree- Returns:
- the partially annotated
AnnotatedTypeMirrors for the (explicit) class type arguments of the new class tree
-
getExplicitNewClassAnnos
Description copied from class:AnnotatedTypeFactoryReturns the annotations explicitly written on a NewClassTree.new @HERE Class()- Overrides:
getExplicitNewClassAnnosin classAnnotatedTypeFactory- Parameters:
newClassTree- a constructor invocation- Returns:
- the annotations explicitly written on a NewClassTree
-
createAndInitQualifierDefaults
CreateQualifierDefaultswhich 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
CreateQualifierDefaultswhich handles checker specified defaults. Sub-classes override this method to provide a differentQualifierDefaultimplementation. -
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 readingDefaultForandDefaultQualifierInHierarchymeta-annotations. Subclasses may override this method to add defaults that cannot be specified with aDefaultFororDefaultQualifierInHierarchymeta-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-QualifierDefaultsobject to which defaults are added
-
addUncheckedStandardDefaults
Adds standard unchecked defaults that do not conflict with previously added defaults.- Parameters:
defs-QualifierDefaultsobject 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-QualifierDefaultsobject to which defaults are added
-
createQualifierPolymorphism
Creates theQualifierPolymorphisminstance which supports the QualifierPolymorphism mechanism.- Returns:
- the QualifierPolymorphism instance to use
-
getQualifierPolymorphism
Gives the currentQualifierPolymorphisminstance 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:AnnotatedTypeFactoryA 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
typeannotations tosupertypes. This allows thetypeand its supertypes to have the qualifiers.- Overrides:
postDirectSuperTypesin 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 withclazzonexpression's type, at a particular location. The returned annotation may be null even if the expression should have a primary annotation ofclazz. This is becauseJavaExpressions do not always have enough information to get an annotated type.This method should only be used if a tree, element, or node is not available for
expression. UseAnnotatedTypeFactory.getAnnotatedType(Tree)orAnnotatedTypeFactory.getAnnotatedType(Element)instead.- Parameters:
expression- the expression for which the annotation is returnedtree- current treepath- location at which expression is evaluatedclazz- the annotation class for which to look- Returns:
- the annotation of
clazzonexpression's type, or null if one does not exist or ifexpressiondoes not have enough information to get the annotated type - 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 withclazzonexpr's type, at a particular location. The returned annotation may be null even if the expression should have a primary annotation ofclazz. This is becauseJavaExpressions do not always have enough information to get an annotated type.This method should only be used if a tree, element, or node is not available for
expr. UseAnnotatedTypeFactory.getAnnotatedType(Tree)orAnnotatedTypeFactory.getAnnotatedType(Element)instead.- Parameters:
expr- the expression for which the annotation is returnedtree- current treeclazz- the annotation class for which to look- Returns:
- the annotation of
clazzonexpr's type, or null if one does not exist or ifexprdoes not have enough information to get the annotated type
-
getAnnotationsFromJavaExpression
Returns the primary annotations on an expression, at a particular location. The returned set of annotations may be empty even if the expression should have primary annotations. This is becauseJavaExpressiondo not always have enough information to get an annotated type.This method should only be used if a tree, element, or node is not available for
expr. UseAnnotatedTypeFactory.getAnnotatedType(Tree)orAnnotatedTypeFactory.getAnnotatedType(Element)instead.- Parameters:
expr- the expression for which the annotation is returnedtree- current tree- Returns:
- the annotations on the expression. May be empty if
exprdoes not have enough information to get the annotated type.
-
parseJavaExpressionString
public JavaExpression parseJavaExpressionString(String expression, TreePath currentPath) throws JavaExpressionParseUtil.JavaExpressionParseException Produces the JavaExpression as ifexpressionwere 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 theexprTreeis unreachable. This is a conservative estimate and may returnfalseeven though theexprTreeis unreachable.- Parameters:
exprTree- an expression tree- Returns:
- true if the
exprTreeis unreachable
-
getRegularExitStore
Returns the regular exit store for a method or another code block (such as static initializers). Returnsnullif 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 ofmethodpaired with their correspondingTransferResult. Ifmethodhas 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
methodpaired with their correspondingTransferResultor an empty list ifmethodhas 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 ofNodes.- Returns:
- the store immediately before a given Set of
Nodes
-
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
returnstatement.- 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 firstNodefor a givenTreethat 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 aNodein a rather unusual way. Callers should probably be rewritten to not use aNodeat 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 ASTastand 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 iftypeMirroris an exception type that should be ignored.- Parameters:
typeMirror- an exception type- Returns:
- true if
typeMirroris 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.- Parameters:
cfg- the CFG- See Also:
-
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 fielduseFlowis 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 fielduseFlowis false
-
getAnnotatedTypeRhsUnaryAssign
Returns the type ofv + 1orv - 1wherevis 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:AnnotatedTypeFactoryThe implementation ofAnnotatedTypeFactory.constructorFromUse(NewClassTree)andAnnotatedTypeFactory.constructorFromUseWithoutTypeArgInference(NewClassTree).- Overrides:
constructorFromUsein 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:AnnotatedTypeFactoryA callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared constructor type before type variable substitution.- Overrides:
constructorFromUsePreSubstitutionin 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:AnnotatedTypeFactoryReturns the return type of the methodm.- Overrides:
getMethodReturnTypein classAnnotatedTypeFactory- Parameters:
m- tree of a method declaration- Returns:
- the return type of the method
-
addDefaultAnnotations
Description copied from class:AnnotatedTypeFactoryAdds 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:
addDefaultAnnotationsin 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:
addComputedTypeAnnotationsin 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
-AwarnRedundantAnnotationscommand-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
-AwarnRedundantAnnotationscommand-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.treeis 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 istypetype- 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 istypetype- where the defaults are applied
-
addComputedTypeAnnotations
To add annotations to the type of method or constructor parameters, add aTypeAnnotatorusingcreateTypeAnnotator()and see the comment inTypeAnnotator.visitExecutable(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType, Void).- Overrides:
addComputedTypeAnnotationsin classAnnotatedTypeFactory- Parameters:
elt- an elementtype- the type obtained fromelt
-
methodFromUse
protected AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(MethodInvocationTree tree, boolean inferTypeArg) Description copied from class:AnnotatedTypeFactoryThe implementation ofAnnotatedTypeFactory.methodFromUse(MethodInvocationTree)andAnnotatedTypeFactory.methodFromUseWithoutTypeArgInference(MethodInvocationTree).- Overrides:
methodFromUsein 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
inferTypeArgsis true, any inferred type arguments
-
methodFromUsePreSubstitution
public void methodFromUsePreSubstitution(ExpressionTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type, boolean resolvePolyQuals) Description copied from class:AnnotatedTypeFactoryA callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared method type before type variable substitution.- Overrides:
methodFromUsePreSubstitutionin 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:AnnotatedTypeFactoryAdapt 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:
typeVariablesFromUsein 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 SourceChecker> 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 SourceChecker> 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:AnnotatedTypeFactoryA 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:
postAsMemberOfin 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 oftypetotype. Ifelementis 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
DefaultQualifierForUseTypeAnnotatorandDefaultForTypeAnnotator.)- Parameters:
element- possibly null element whose type istypetype- 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
#isRelevantImplinstead 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
#isRelevantImplinstead 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@RequiresQualifierannotations for the given expression. By default this list does not include any qualifier that has elements/arguments, which@RequiresQualifierdoes 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).expressionmust 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@EnsuresQualifierannotations for the given expression. By default this list does not include any qualifier that has elements/arguments, which@EnsuresQualifierdoes 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).expressionmust 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
@RequiresQualifieror@EnsuresQualifierannotation for the given expression. Returns an empty list if none can be created, because the qualifier has elements/arguments, which@RequiresQualifierand@EnsuresQualifierdo 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 whenpreOrPostisAFTER- 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 stringexpressionand 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
@RequiresQualifierand@EnsuresQualifierdo 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 whenpreOrPostisBeforeOrAfter.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 ofcontractAnnotationcontractAnnotation- aRequiresQualifier,EnsuresQualifier, orEnsuresQualifierIf- Returns:
- the
resultelement ofcontractAnnotation, or null if it doesn't have aresultelement
-
getContractExpressions
public @Nullable List<String> getContractExpressions(Contract.Kind kind, AnnotationMirror contractAnnotation) IfcontractAnnotationis a framework annotation, return itsexpressionelement. Otherwise,contractAnnotationis defined in a checker. If kind = CONDITIONALPOSTCONDITION, return itsexpressionelement, else return itsvalueelement.- Parameters:
kind- the kind ofcontractAnnotationcontractAnnotation- aRequiresQualifier,EnsuresQualifier, orEnsuresQualifierIf- Returns:
- the
resultelement ofcontractAnnotation, or null if it doesn't have aresultelement
-