Class ResourceLeakAnnotatedTypeFactory
- java.lang.Object
-
- org.checkerframework.framework.type.AnnotatedTypeFactory
-
- org.checkerframework.framework.type.GenericAnnotatedTypeFactory<AccumulationValue,AccumulationStore,AccumulationTransfer,AccumulationAnalysis>
-
- org.checkerframework.common.accumulation.AccumulationAnnotatedTypeFactory
-
- org.checkerframework.checker.calledmethods.CalledMethodsAnnotatedTypeFactory
-
- org.checkerframework.checker.resourceleak.ResourceLeakAnnotatedTypeFactory
-
- All Implemented Interfaces:
CreatesMustCallForElementSupplier
,AnnotationProvider
public class ResourceLeakAnnotatedTypeFactory extends CalledMethodsAnnotatedTypeFactory implements CreatesMustCallForElementSupplier
The type factory for the Resource Leak Checker. The main difference between this and the Called Methods type factory from which it is derived is that this version'spostAnalyze(ControlFlowGraph)
method checks that must-call obligations are fulfilled.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.checkerframework.common.accumulation.AccumulationAnnotatedTypeFactory
AccumulationAnnotatedTypeFactory.AccumulationQualifierHierarchy, AccumulationAnnotatedTypeFactory.AccumulationTreeAnnotator
-
Nested classes/interfaces inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
GenericAnnotatedTypeFactory.ScanState
-
Nested classes/interfaces inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
AnnotatedTypeFactory.ParameterizedExecutableType
-
-
Field Summary
Fields Modifier and Type Field Description boolean
noLightweightOwnership
True if -AnoLightweightOwnership was passed on the command line.-
Fields inherited from class org.checkerframework.common.accumulation.AccumulationAnnotatedTypeFactory
accumulationChecker, bottom, top
-
Fields inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
analysis, arraysAreRelevant, cfgVisualizer, contractsUtils, defaults, dependentTypesHelper, emptyStore, exceptionalExitStores, flowByDefault, flowResult, flowResultAnalysisCaches, formalParameterPattern, hasOrIsSubchecker, initializationStaticStore, initializationStore, poly, regularExitStores, relevantJavaTypes, returnStatementStores, scannedClasses, shouldClearSubcheckerSharedCFGs, sideEffectsUnrefineAliases, subcheckerSharedCFG, transfer, treeAnnotator, typeAnnotator
-
Fields inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
ajavaTypes, annotatedForValueElement, checker, currentFileAjavaTypes, elements, ensuresQualifierExpressionElement, ensuresQualifierIfExpressionElement, ensuresQualifierIfListTM, ensuresQualifierIfListValueElement, ensuresQualifierIfResultElement, ensuresQualifierIfTM, ensuresQualifierListTM, ensuresQualifierListValueElement, ensuresQualifierTM, fieldInvariantFieldElement, fieldInvariantQualifierElement, fromExpressionTreeCache, fromMemberTreeCache, fromTypeTreeCache, hasQualifierParameterValueElement, ignoreUninferredTypeArguments, loader, methodValClassNameElement, methodValMethodNameElement, methodValParamsElement, noQualifierParameterValueElement, objectGetClass, processingEnv, qualHierarchy, qualifierUpperBounds, reflectionResolver, requiresQualifierExpressionElement, requiresQualifierListTM, requiresQualifierListValueElement, requiresQualifierTM, root, shouldCache, stubTypes, trees, typeArgumentInference, typeFormatter, typeHierarchy, types, typeVarSubstitutor, uid, viewpointAdapter
-
-
Constructor Summary
Constructors Constructor Description ResourceLeakAnnotatedTypeFactory(BaseTypeChecker checker)
Creates a new ResourceLeakAnnotatedTypeFactory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canCreateObligations()
Does this type factory supportCreatesMustCallFor
?javax.lang.model.element.AnnotationMirror
createCalledMethods(java.lang.String... val)
Creates a @CalledMethods annotation whose values are the given strings.protected ResourceLeakAnalysis
createFlowAnalysis()
Returns the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis.protected java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>>
createSupportedTypeQualifiers()
Returns a mutable set of annotation classes that are supported by a checker.javax.lang.model.element.ExecutableElement
getCreatesMustCallForListValueElement()
Returns theCreatesMustCallFor.List.value()
element.javax.lang.model.element.ExecutableElement
getCreatesMustCallForValueElement()
Returns theCreatesMustCallFor.value()
element.javax.lang.model.element.ExecutableElement
getEnsuresCalledMethodsListValueElement()
Returns theEnsuresCalledMethods.List.value()
element.<T extends GenericAnnotatedTypeFactory<?,?,?,?>>
@Nullable TgetTypeFactoryOfSubcheckerOrNull(java.lang.Class<? extends BaseTypeChecker> subCheckerClass)
Returns the type factory used by a subchecker.boolean
hasCreatesMustCallFor(MethodInvocationNode node)
Returns true if the declaration of the method being invoked has one or moreCreatesMustCallFor
annotations.boolean
hasNotOwning(javax.lang.model.element.Element elt)
Does the given element have an@NotOwning
annotation (including in stub files)?boolean
hasOwning(javax.lang.model.element.Element elt)
Does the given element have an@Owning
annotation (including in stub files)?void
postAnalyze(ControlFlowGraph cfg)
Perform any additional operations on a CFG.-
Methods inherited from class org.checkerframework.checker.calledmethods.CalledMethodsAnnotatedTypeFactory
adjustMethodNameUsingValueChecker, createRequiresOrEnsuresQualifier, createTreeAnnotator, createTypeAnnotator, getDummyAssignedTo, returnsThis
-
Methods inherited from class org.checkerframework.common.accumulation.AccumulationAnnotatedTypeFactory
convertToPredicate, createAccumulatorAnnotation, createAccumulatorAnnotation, createPredicateAnnotation, createQualifierHierarchy, evaluatePredicate, evaluatePredicate, getAccumulatedValues, getAccumulatedValues, isAccumulatorAnnotation, isPredicate, isPredicateSubtype
-
Methods inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
addAnnotationsFromDefaultForType, addCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotations, addDefaultAnnotations, addSharedCFGForTree, addUncheckedStandardDefaults, analyze, annotationsForIrrelevantJavaType, applyInferredAnnotations, applyQualifierParameterDefaults, applyQualifierParameterDefaults, checkAndPerformFlowAnalysis, checkForDefaultQualifierInHierarchy, constructorFromUse, constructorFromUsePreSubstitution, createAndInitQualifierDefaults, createCFGVisualizer, createContractsFromMethod, createDefaultForTypeAnnotator, createDefaultForUseTypeAnnotator, createDependentTypesHelper, createFlowTransferFunction, createQualifierDefaults, createQualifierPolymorphism, getAnnotatedTypeBefore, getAnnotatedTypeLhs, getAnnotatedTypeLhsNoTypeVarDefault, getAnnotatedTypeRhsUnaryAssign, getAnnotatedTypeVarargsArray, getAnnotationFromJavaExpression, getAnnotationFromJavaExpressionString, getAnnotationMirrorFromJavaExpressionString, getAnnotationsFromJavaExpression, getCFGVisualizer, getContractExpressions, getContractsFromMethod, getDefaultAnnotations, getDefaultForTypeAnnotator, getDefaultValueAnnotatedType, getDependentTypesHelper, getEmptyStore, getEnsuresQualifierIfResult, getExceptionalExitStore, getExplicitNewClassAnnos, getExplicitNewClassClassTypeArgs, getExpressionAndOffsetFromJavaExpressionString, getFinalLocalValues, getFirstNodeOfKindForTree, getInferredValueFor, getMethodReturnType, getNodesForTree, getQualifierPolymorphism, getRegularExitStore, getResultingTypeOfConstructorMemberReference, getReturnStatementStores, getSharedCFGForTree, getShouldDefaultTypeVarLocals, getSortedQualifierNames, getStoreAfter, getStoreAfter, getStoreAfter, getStoreBefore, getStoreBefore, getStoreBefore, getSupportedMonotonicTypeQualifiers, getTypeFactoryOfSubchecker, handleCFGViz, irrelevantExtraMessage, isComputingAnnotatedTypeMirrorOfLhs, isNotFullyInitializedReceiver, isRelevant, isRelevant, isRelevantImpl, methodFromUse, methodFromUsePreSubstitution, parseJavaExpressionString, performFlowAnalysis, postAsMemberOf, postDirectSuperTypes, postInit, preProcessClassTree, setRoot, typeVariablesFromUse
-
Methods inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
adaptGetClassReturnTypeToReceiver, addAliasedDeclAnnotation, addAliasedDeclAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, applyCaptureConversion, applyCaptureConversion, applyUnboxing, areSameByClass, binaryTreeArgTypes, binaryTreeArgTypes, binaryTreeArgTypes, canonicalAnnotation, compoundAssignmentTreeArgTypes, containsSameByClass, containsUninferredTypeArguments, createAnnotatedTypeFormatter, createAnnotationClassLoader, createAnnotationFormatter, createQualifierUpperBounds, createTypeArgumentInference, createTypeHierarchy, createTypeVariableSubstitutor, createViewpointAdapter, declarationFromElement, doesAnnotatedForApplyToThisChecker, fromElement, fromElement, fromElement, fromNewClass, getAnnotatedNullType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFormatter, getAnnotatedTypeFromTypeTree, getAnnotationByClass, getAnnotationFormatter, getAnnotationMirror, getAnnotationOrTypeDeclarationBound, getAnnotationWithMetaAnnotation, getBoxedType, getBundledTypeQualifiers, getCacheSize, getChecker, getCheckerNames, getContractExpressions, getContractListValues, getCurrentClassTree, getCurrentMethodReceiver, getDeclAnnotation, getDeclAnnotationNoAliases, getDeclAnnotations, getDeclAnnotationWithMetaAnnotation, getDefaultTypeDeclarationBounds, getElementUtils, getEnclosingClassOrMethod, getEnclosingSubType, getEnclosingType, getEnumConstructorQualifiers, getExpressionAndOffset, getFieldInvariantAnnotationTree, getFieldInvariantDeclarationAnnotations, getFieldInvariants, getFnInterfaceFromTree, getFunctionTypeFromTree, getFunctionTypeFromTree, getImplicitReceiverType, getIterableElementType, getIterableElementType, getMethodReturnType, getNarrowedAnnotations, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getQualifierParameterHierarchies, getQualifierParameterHierarchies, getQualifierUpperBounds, getReceiverType, getSelfType, getStringType, getSupportedTypeQualifierNames, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeDeclarationBounds, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, getUnboxedType, getUninferredWildcardType, getVisitorTreePath, getWidenedAnnotations, getWidenedType, getWidenedType, hasExplicitNoQualifierParameterInHierarchy, hasExplicitQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, initializeReflectionResolution, isFromByteCode, isFromStubFile, isImmutable, isSideEffectFree, isSupportedQualifier, isSupportedQualifier, isSupportedQualifier, isWithinConstructor, mergeAnnotationFileAnnosIntoType, methodFromUse, negateConstant, order, parseAnnotationFiles, postProcessClassTree, replaceAnnotations, replaceAnnotations, setPathForArtificialTree, setVisitorTreePath, shouldWarnIfStubRedundantWithBytecode, toAnnotatedType, toString, type
-
-
-
-
Constructor Detail
-
ResourceLeakAnnotatedTypeFactory
public ResourceLeakAnnotatedTypeFactory(BaseTypeChecker checker)
Creates a new ResourceLeakAnnotatedTypeFactory.- Parameters:
checker
- the checker associated with this type factory
-
-
Method Detail
-
createSupportedTypeQualifiers
protected java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> createSupportedTypeQualifiers()
Description copied from class:AnnotatedTypeFactory
Returns a mutable set of annotation classes that are supported by a checker.Subclasses may override this method to return a mutable set of their supported type qualifiers through one of the 5 approaches shown below.
Subclasses should not call this method; they should call
AnnotatedTypeFactory.getSupportedTypeQualifiers()
instead.By default, a checker supports all annotations located in a subdirectory called qual that's located in the same directory as the checker. Note that only annotations defined with the
@Target({ElementType.TYPE_USE})
meta-annotation (and optionally with the additional value ofElementType.TYPE_PARAMETER
, but no otherElementType
values) are automatically considered as supported annotations.To support a different set of annotations than those in the qual subdirectory, or that have other
ElementType
values, see examples below.In total, there are 5 ways to indicate annotations that are supported by a checker:
- Only support annotations located in a checker's qual directory:
This is the default behavior. Simply place those annotations within the qual directory.
- Support annotations located in a checker's qual directory and a list of
other annotations:
Place those annotations within the qual directory, and override
AnnotatedTypeFactory.createSupportedTypeQualifiers()
by callingAnnotatedTypeFactory.getBundledTypeQualifiers(Class...)
with a varargs parameter list of the other annotations. Code example:@Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() { return getBundledTypeQualifiers(Regex.class, PartialRegex.class, RegexBottom.class, UnknownRegex.class); }
- Supporting only annotations that are explicitly listed: Override
AnnotatedTypeFactory.createSupportedTypeQualifiers()
and return a mutable set of the supported annotations. Code example:@Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() { return new HashSet<Class<? extends Annotation>>( Arrays.asList(A.class, B.class)); }
AnnotatedTypeFactory.createSupportedTypeQualifiers()
must be a fresh, mutable set. The methodsAnnotatedTypeFactory.getBundledTypeQualifiers(Class...)
must return a fresh, mutable set
- Overrides:
createSupportedTypeQualifiers
in classAnnotatedTypeFactory
- Returns:
- the type qualifiers supported this processor, or an empty set if none
- Only support annotations located in a checker's qual directory:
-
createCalledMethods
public javax.lang.model.element.AnnotationMirror createCalledMethods(java.lang.String... val)
Creates a @CalledMethods annotation whose values are the given strings.- Parameters:
val
- the methods that have been called- Returns:
- an annotation indicating that the given methods have been called
-
postAnalyze
public void postAnalyze(ControlFlowGraph cfg)
Description copied from class:GenericAnnotatedTypeFactory
Perform any additional operations on a CFG. Called once per CFG, after the CFG has been analyzed byGenericAnnotatedTypeFactory.analyze(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.- Overrides:
postAnalyze
in classGenericAnnotatedTypeFactory<AccumulationValue,AccumulationStore,AccumulationTransfer,AccumulationAnalysis>
- Parameters:
cfg
- the CFG- See Also:
GenericAnnotatedTypeFactory.analyze(java.util.Queue, java.util.Queue, org.checkerframework.dataflow.cfg.UnderlyingAST, java.util.List, com.sun.source.tree.ClassTree, boolean, boolean, boolean, org.checkerframework.framework.flow.CFAbstractStore)
-
createFlowAnalysis
protected ResourceLeakAnalysis createFlowAnalysis()
Description copied from class:GenericAnnotatedTypeFactory
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.
- Overrides:
createFlowAnalysis
in classCalledMethodsAnnotatedTypeFactory
- Returns:
- the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis
-
hasCreatesMustCallFor
public boolean hasCreatesMustCallFor(MethodInvocationNode node)
Returns true if the declaration of the method being invoked has one or moreCreatesMustCallFor
annotations.- Parameters:
node
- a method invocation node- Returns:
- true iff there is one or more @CreatesMustCallFor annotations on the declaration of the invoked method
-
canCreateObligations
public boolean canCreateObligations()
Does this type factory supportCreatesMustCallFor
?- Returns:
- true iff the -AnoCreatesMustCallFor command-line argument was not supplied to the checker
-
getTypeFactoryOfSubcheckerOrNull
public <T extends GenericAnnotatedTypeFactory<?,?,?,?>> @Nullable T getTypeFactoryOfSubcheckerOrNull(java.lang.Class<? extends BaseTypeChecker> subCheckerClass)
Description copied from class:GenericAnnotatedTypeFactory
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.
- Overrides:
getTypeFactoryOfSubcheckerOrNull
in classGenericAnnotatedTypeFactory<AccumulationValue,AccumulationStore,AccumulationTransfer,AccumulationAnalysis>
- 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:
GenericAnnotatedTypeFactory.getTypeFactoryOfSubchecker(java.lang.Class<? extends org.checkerframework.common.basetype.BaseTypeChecker>)
-
getEnsuresCalledMethodsListValueElement
public javax.lang.model.element.ExecutableElement getEnsuresCalledMethodsListValueElement()
Returns theEnsuresCalledMethods.List.value()
element.- Returns:
- the
EnsuresCalledMethods.List.value()
element
-
getCreatesMustCallForValueElement
public javax.lang.model.element.ExecutableElement getCreatesMustCallForValueElement()
Returns theCreatesMustCallFor.value()
element.- Specified by:
getCreatesMustCallForValueElement
in interfaceCreatesMustCallForElementSupplier
- Returns:
- the
CreatesMustCallFor.value()
element
-
getCreatesMustCallForListValueElement
public javax.lang.model.element.ExecutableElement getCreatesMustCallForListValueElement()
Returns theCreatesMustCallFor.List.value()
element.- Specified by:
getCreatesMustCallForListValueElement
in interfaceCreatesMustCallForElementSupplier
- Returns:
- the
CreatesMustCallFor.List.value()
element
-
hasNotOwning
public boolean hasNotOwning(javax.lang.model.element.Element elt)
Does the given element have an@NotOwning
annotation (including in stub files)?Prefer this method to calling
AnnotatedTypeFactory.getDeclAnnotation(Element, Class)
on the type factory directly, which won't find this annotation in stub files (it only considers stub files loaded by this checker, not subcheckers).- Parameters:
elt
- an element- Returns:
- whether there is a NotOwning annotation on the given element
-
hasOwning
public boolean hasOwning(javax.lang.model.element.Element elt)
Does the given element have an@Owning
annotation (including in stub files)?Prefer this method to calling
AnnotatedTypeFactory.getDeclAnnotation(Element, Class)
on the type factory directly, which won't find this annotation in stub files (it only considers stub files loaded by this checker, not subcheckers).- Parameters:
elt
- an element- Returns:
- whether there is an Owning annotation on the given element
-
-