Class InitializationAnnotatedTypeFactory
- All Implemented Interfaces:
AnnotationProvider
InitializationChecker for further information.-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.checker.initialization.InitializationParentAnnotatedTypeFactory
InitializationParentAnnotatedTypeFactory.CommitmentTreeAnnotator, InitializationParentAnnotatedTypeFactory.CommitmentTypeAnnotator, InitializationParentAnnotatedTypeFactory.InitializationQualifierHierarchyNested classes/interfaces inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
GenericAnnotatedTypeFactory.ScanStateNested classes/interfaces inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
AnnotatedTypeFactory.CapturedTypeVarSubstitutor, AnnotatedTypeFactory.ParameterizedExecutableType -
Field Summary
Fields inherited from class org.checkerframework.checker.initialization.InitializationParentAnnotatedTypeFactory
assumeInitialized, FBCBOTTOM, INITIALIZED, NOT_ONLY_INITIALIZED, objectTypeMirror, POLY_INITIALIZED, UNDER_INITALIZATION, underInitializationObjectAnnotation, underInitializationValueElement, UNKNOWN_INITIALIZATION, unknownInitializationValueElement, unusedWhenElementFields inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
analysis, arraysAreRelevant, cfgVisualizer, contractsUtils, defaults, dependentTypesHelper, emptyStore, exceptionalExitStores, flowByDefault, flowResult, flowResultAnalysisCaches, formalParameterPattern, hasOrIsSubchecker, initializationStaticStore, initializationStore, parsePhasePrimaryDefaultsCache, poly, regularExitStores, relevantJavaTypes, returnStatementStores, scannedClasses, shouldClearSubcheckerSharedCFGs, sideEffectsUnrefineAliases, subcheckerSharedCFG, transfer, treeAnnotator, typeAnnotatorFields inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
ajavaTypes, annotatedForApplyToSubpackagesElement, annotatedForListValueElement, annotatedForValueElement, capturedTypeVarSubstitutor, checker, currentFileAjavaTypes, defaultQualifierListValueElement, elements, ensuresQualifierExpressionElement, ensuresQualifierIfExpressionElement, ensuresQualifierIfListTM, ensuresQualifierIfListValueElement, ensuresQualifierIfResultElement, ensuresQualifierIfTM, ensuresQualifierListTM, ensuresQualifierListValueElement, ensuresQualifierTM, fieldInvariantFieldElement, fieldInvariantQualifierElement, fromExpressionTreeCache, fromMemberTreeCache, fromTypeTreeCache, hasQualifierParameterApplyToSubpackagesElement, hasQualifierParameterValueElement, ignoreRawTypeArguments, inferenceResultCache, loader, methodValClassNameElement, methodValMethodNameElement, methodValParamsElement, nodeValueInferenceResultCache, noQualifierParameterValueElement, objectGetClass, processingEnv, qualHierarchy, qualifierUpperBounds, reflectionResolver, requiresQualifierExpressionElement, requiresQualifierListTM, requiresQualifierListValueElement, requiresQualifierTM, shouldCache, stubTypes, trees, typeArgumentInference, typeFormatter, typeHierarchy, typeInformationPresenter, types, typeVarSubstitutor, uid, UNANNOTATED_FOR_NAME, unannotatedForApplyToSubpackagesElement, unannotatedForListValueElement, unannotatedForValueElement, viewpointAdapter -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new InitializationAnnotatedTypeFactory. -
Method Summary
Modifier and TypeMethodDescriptionprotected InitializationAnalysisReturns the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis.Returns the checker associated with this factory.getExceptionalExitStore(Tree tree) Returns the exceptional exit store for a method or another code block (such as static initializers).Gets the factory of theInitializationFieldAccessSubchecker, whose flow-analysis results we reuse to avoid performing the same flow analysis twice.getRegularExitStore(Tree tree) Returns the regular exit store for a method or another code block (such as static initializers).getReturnStatementStores(MethodTree methodTree) Returns a list of all return statements ofmethodpaired with their correspondingTransferResult.getUninitializedFields(InitializationStore initStore, CFAbstractStore<?, ?> targetStore, TreePath path, boolean isStatic, Collection<? extends AnnotationMirror> receiverAnnotations) Returns the fields that are not yet initialized in a given store, taking into account the target checker.booleanisAnonymousDiamondSupertypeFinal(NewClassTree creation) Returns true if the supertype inferred for the anonymous class created bycreation, a diamond such asnew C<>(args) {...}, can no longer change.protected booleanisFieldInitialized(InitializationStore store, @Nullable CFAbstractStore<?, ?> targetStore, VariableTree field, VariableElement elem) Determines whetherfieldis initialized according tostoreandtargetStore.static booleanisInitialized(GenericAnnotatedTypeFactory<?, ?, ?, ?> factory, CFAbstractValue<?> value, VariableElement var) Determines whether the specified variable's current value is initialized.protected voidperformFlowAnalysisForClassImpl(ClassTree classTree) Runs no analysis of its own: the flow result is the one of theInitializationFieldAccessAnnotatedTypeFactory, which analyzes the class before this factory is queried for it.protected voidsetSelfTypeInInitializationCode(Tree tree, AnnotatedTypeMirror.AnnotatedDeclaredType selfType, TreePath path) Side-effects argumentselfTypeto make it @Initialized or @UnderInitialization, depending on whether all fields have been set.Methods inherited from class org.checkerframework.checker.initialization.InitializationParentAnnotatedTypeFactory
areAllFieldsInitializedOnly, createFlowTransferFunction, createQualifierHierarchy, createSupportedTypeQualifiers, createTreeAnnotator, createTypeAnnotator, createUnderInitializationAnnotation, createUnknownInitializationAnnotation, createUnknownInitializationAnnotation, getAnnotatedTypeLhs, getInitializedFields, getSelfType, getTypeFrameFromAnnotation, getUnderInitializationAnnotationOfSuperType, getUninitializedFields, isFbcBottom, isFbcBottom, isImmutable, isInitialized, isInitialized, isInitializedForFrame, isNotFullyInitializedReceiver, isUnderInitialization, isUnderInitialization, isUnknownInitialization, isUnknownInitialization, isUnused, methodFromUse, postAsMemberOf, setRoot, shouldWarnIfStubRedundantWithBytecodeMethods inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
addAnnotationsFromDefaultForType, addCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotationsWithoutFlow, addDefaultAnnotations, addSharedCFGForTree, addUncheckedStandardDefaults, analyze, annotationsForIrrelevantJavaType, applyInferredAnnotations, applyQualifierParameterDefaults, applyQualifierParameterDefaults, canCacheFlowDependentType, canUseCachedFlowDependentType, checkForDefaultQualifierInHierarchy, clearParsePhaseCache, constructorFromUse, constructorFromUsePreSubstitution, createAndInitQualifierDefaults, createCFGVisualizer, createContractsFromMethod, createDefaultForTypeAnnotator, createDefaultForUseTypeAnnotator, createDependentTypesHelper, createQualifierDefaults, createQualifierPolymorphism, createRequiresOrEnsuresQualifier, getAnnotatedTypeBefore, getAnnotatedTypeLhsNoTypeVarDefault, getAnnotatedTypeRhsUnaryAssign, getAnnotatedTypeVarargsArray, getAnnotationFromJavaExpression, getAnnotationFromJavaExpressionString, getAnnotationMirrorFromJavaExpressionString, getAnnotationsFromJavaExpression, getCFGVisualizer, getContractExpressions, getContractsFromMethod, getDefaultAnnosForUses, getDefaultAnnotations, getDefaultForTypeAnnotator, getDefaultValueAnnotatedType, getDependentTypesHelper, getEmptyStore, getEnsuresQualifierIfResult, getExplicitNewClassAnnos, getExplicitNewClassClassTypeArgs, getExpressionAndOffsetFromJavaExpressionString, getFinalLocalValues, getFinalLocalValues, getFirstNodeOfKindForTree, getInferredValueFor, getMethodReturnType, getNodesForTree, getQualifierDefaults, getQualifierPolymorphism, getSharedCFGForTree, getShouldDefaultTypeVarLocals, getSortedQualifierNames, getStandaloneTypeForNodeValue, getStoreAfter, getStoreAfter, getStoreBefore, getStoreBefore, getSupportedMonotonicTypeQualifiers, getTypeFactoryOfSubchecker, getTypeFactoryOfSubcheckerOrNull, getUseFlow, handleCFGViz, irrelevantExtraMessage, isComputingAnnotatedTypeMirrorOfLhs, isComputingNodeValue, isIgnoredExceptionType, isRelevant, isRelevant, isRelevantImpl, isUnreachable, methodFromUse, methodFromUsePreSubstitution, parseJavaExpressionString, performFlowAnalysisForClass, performFlowAnalysisForClassOnce, postAnalyze, postInit, preProcessClassTree, runWithBodyVisitorPath, typeVariablesFromUseMethods inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
adaptGetClassReturnTypeToReceiver, addAliasedDeclAnnotation, addAliasedDeclAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, annotatedForPrecedesUnannotatedFor, applyCaptureConversion, applyCaptureConversion, applyUnboxing, areSameByClass, asSupportedQualifier, binaryTreeArgTypes, binaryTreeArgTypes, canonicalAnnotation, clearNodeValueInferenceResults, combineIntersectionBoundAnnotationsInHierarchy, compoundAssignmentTreeArgTypes, constructorFromUse, constructorFromUseWithoutTypeArgInference, containsCapturedTypes, containsSameByClass, containsSameOrAlias, createAnnotatedTypeFormatter, createAnnotationClassLoader, createAnnotationFormatter, createQualifierUpperBounds, createTypeArgumentInference, createTypeHierarchy, createTypeInformationPresenter, createTypeVariableSubstitutor, createViewpointAdapter, declarationFromElement, doesAnnotatedForApplyToSubpackages, doesAnnotatedForApplyToThisChecker, doesUnannotatedForApplyToSubpackages, doesUnannotatedForApplyToThisChecker, fromElement, fromElement, fromElement, getAnnotatedForAnnotations, getAnnotatedNullType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFormatter, getAnnotatedTypeFromTypeTree, getAnnotationByClass, getAnnotationFormatter, getAnnotationMirror, getAnnotationOrTypeDeclarationBound, getAnnotationWithMetaAnnotation, getAnonymousDiamondCreation, getAnonymousDiamondSuperConstructor, getAnonymousDiamondSupertype, getBoxedType, getBundledTypeQualifiers, getCacheSize, getCheckerNames, getConstructorReceiverType, getContractExpressions, getContractListValues, getDeclAnnotation, getDeclAnnotationNoAliases, getDeclAnnotations, getDeclAnnotationWithMetaAnnotation, getDefaultQualifierAnnotations, getDefaultTypeDeclarationBounds, getDirectSupertypes, getDummyAssignedTo, getElementAnnotations, getElementUtils, getEnclosingClassOrMethod, getEnclosingSubType, getEnclosingType, getEnumConstructorQualifiers, getExpressionAndOffset, getFieldInvariantAnnotationTree, getFieldInvariantDeclarationAnnotations, getFieldInvariants, getFnInterfaceFromTree, getFunctionTypeFromTree, getFunctionTypeFromTree, getImplicitReceiverType, getInferenceWorkBudget, getInitializerTargetType, getIterableElementType, getIterableElementType, getMethodReceiverType, getMethodReturnType, getNarrowedAnnotations, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getQualifierParameterHierarchies, getQualifierParameterHierarchies, getQualifierUpperBounds, getReceiverType, getResultingTypeOfConstructorMemberReference, getRoot, getSelfType, getStringType, getSupportedTypeQualifierNames, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeDeclarationBounds, getTypeDeclarationBoundsFromUse, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, getUnannotatedForAnnotations, getUnboxedType, getViewpointAdaptedTypeDeclarationBounds, getVisitorTreePath, getWidenedAnnotations, getWidenedType, getWidenedType, hasExplicitNoQualifierParameterInHierarchy, hasExplicitQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, inferTypeArguments, initializeAtm, initializeReflectionResolution, isAliasedTypeAnnotation, isComputingInitializerTargetType, isDeterministic, isFromByteCode, isFromStubFile, isInferringStandalone, isParsingAnnotationFile, isSideEffectFree, isSupportedQualifier, isSupportedQualifier, isSupportedQualifier, isSupportedQualifierOrAlias, isWithinConstructor, mergeAnnotationFileAnnosIntoType, methodFromUse, methodFromUse, methodFromUseWithoutTypeArgInference, methodFromUseWithoutTypeArgInference, negateConstant, order, overriddenMethodType, parseAnnotationFiles, permissiveOverriddenType, postDirectSuperTypes, postProcessClassTree, replaceAnnotations, replaceAnnotations, setPathForArtificialTree, setVisitorTreePath, shouldCacheElementType, shouldCacheMethodAsMemberOf, shouldStoreInBytecode, toAnnotatedType, toString, type
-
Constructor Details
-
InitializationAnnotatedTypeFactory
Create a new InitializationAnnotatedTypeFactory.- Parameters:
checker- the checker to which the new type factory belongs
-
-
Method Details
-
getChecker
Description copied from class:AnnotatedTypeFactoryReturns the checker associated with this factory.- Overrides:
getCheckerin classAnnotatedTypeFactory- Returns:
- the checker associated with this factory
-
getFieldAccessFactory
Gets the factory of theInitializationFieldAccessSubchecker, whose flow-analysis results we reuse to avoid performing the same flow analysis twice.If type checking has not yet started, the subcheckers are uninitialized, and this returns
null. More concretely, this method only returns a non-null value afterSourceChecker.initChecker()has been called on all subcheckers. Since the flow analysis is initialized inAnnotatedTypeFactory.postInit(), and the type factory is created after all subcheckers have been initialized, this method will always return a non-null value unless a subclass attempts to use it for some purpose other than accessing the flow analysis.- Returns:
- the factory of the
InitializationFieldAccessSubchecker, ornullif not yet initialized - See Also:
-
createFlowAnalysis
Description copied from class:GenericAnnotatedTypeFactoryReturns 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:
createFlowAnalysisin classGenericAnnotatedTypeFactory<CFValue,InitializationStore, InitializationTransfer, InitializationAnalysis> - Returns:
- the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis
-
performFlowAnalysisForClassImpl
Runs no analysis of its own: the flow result is the one of theInitializationFieldAccessAnnotatedTypeFactory, which analyzes the class before this factory is queried for it. This overrides the implementation method and notGenericAnnotatedTypeFactory.performFlowAnalysisForClass(ClassTree), which does the bookkeeping that every factory needs and is final.- Overrides:
performFlowAnalysisForClassImplin classGenericAnnotatedTypeFactory<CFValue,InitializationStore, InitializationTransfer, InitializationAnalysis> - Parameters:
classTree- the class to analyze
-
isAnonymousDiamondSupertypeFinal
Description copied from class:AnnotatedTypeFactoryReturns true if the supertype inferred for the anonymous class created bycreation, a diamond such asnew C<>(args) {...}, can no longer change. It is inferred from the types of the arguments and of the context, which change during dataflow analysis of the enclosing method.This implementation, which performs no dataflow analysis, returns true, like
AnnotatedTypeFactory.canUseCachedFlowDependentType(ExpressionTree).GenericAnnotatedTypeFactoryreturns true once dataflow analysis of the anonymous class has started, which is after that of the enclosing method. A factory that does not keep track of the analyzed classes itself must forward to the factory that does.- Overrides:
isAnonymousDiamondSupertypeFinalin classGenericAnnotatedTypeFactory<CFValue,InitializationStore, InitializationTransfer, InitializationAnalysis> - Parameters:
creation- an anonymous class creation with a diamond- Returns:
- true if the inferred supertype of the anonymous class can no longer change
-
getRegularExitStore
Description copied from class:GenericAnnotatedTypeFactoryReturns 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.- Overrides:
getRegularExitStorein classGenericAnnotatedTypeFactory<CFValue,InitializationStore, InitializationTransfer, InitializationAnalysis> - Parameters:
tree- a MethodTree or other code block, such as a static initializer- Returns:
- the regular exit store, or
null
-
getExceptionalExitStore
Description copied from class:GenericAnnotatedTypeFactoryReturns the exceptional exit store for a method or another code block (such as static initializers).- Overrides:
getExceptionalExitStorein classGenericAnnotatedTypeFactory<CFValue,InitializationStore, InitializationTransfer, InitializationAnalysis> - 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<Pair<ReturnNode,TransferResult<CFValue, getReturnStatementStoresInitializationStore>>> (MethodTree methodTree) Description copied from class:GenericAnnotatedTypeFactoryReturns a list of all return statements ofmethodpaired with their correspondingTransferResult. Ifmethodhas no return statement, then the empty list is returned.- Overrides:
getReturnStatementStoresin classGenericAnnotatedTypeFactory<CFValue,InitializationStore, InitializationTransfer, InitializationAnalysis> - 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
-
setSelfTypeInInitializationCode
protected void setSelfTypeInInitializationCode(Tree tree, AnnotatedTypeMirror.AnnotatedDeclaredType selfType, TreePath path) Side-effects argumentselfTypeto make it @Initialized or @UnderInitialization, depending on whether all fields have been set.This implementation also takes the target checker into account.
- Overrides:
setSelfTypeInInitializationCodein classInitializationParentAnnotatedTypeFactory- Parameters:
tree- a treeselfType- the type to side-effectpath- a path- See Also:
-
getUninitializedFields
public List<VariableTree> getUninitializedFields(InitializationStore initStore, CFAbstractStore<?, ?> targetStore, TreePath path, boolean isStatic, Collection<? extends AnnotationMirror> receiverAnnotations) Returns the fields that are not yet initialized in a given store, taking into account the target checker.A field f is initialized if
- f is initialized in the initialization store, i.e., it has been assigned;
- the value of f in the target store has a non-top qualifier that does not have the
meta-annotation
HoldsForDefaultValue; or - the declared qualifier of f in the target hierarchy either has the meta-annotation
HoldsForDefaultValueor is a top qualifier.
See
InitializationParentAnnotatedTypeFactory.getUninitializedFields(InitializationStore, TreePath, boolean, Collection)for a method that does not require the target checker.- Parameters:
initStore- a store for the initialization checkertargetStore- a store for the target checker corresponding to initStorepath- the current path, used to determine the current classisStatic- if true, report static fields; if false, report instance fieldsreceiverAnnotations- the annotations on the receiver- Returns:
- the fields that are not yet initialized in a given store
-
isFieldInitialized
protected boolean isFieldInitialized(InitializationStore store, @Nullable CFAbstractStore<?, ?> targetStore, VariableTree field, VariableElement elem) Description copied from class:InitializationParentAnnotatedTypeFactoryDetermines whetherfieldis initialized according tostoreandtargetStore. The default implementation checksstore.isFieldInitialized(elem). Subclasses may override this to take a target checker into account.- Overrides:
isFieldInitializedin classInitializationParentAnnotatedTypeFactory- Parameters:
store- a store for the initialization checkertargetStore- optional store for the target checkerfield- the field declarationelem- element forfield- Returns:
- true if
fieldis initialized
-
isInitialized
public static boolean isInitialized(GenericAnnotatedTypeFactory<?, ?, ?, ?> factory, CFAbstractValue<?> value, VariableElement var) Determines whether the specified variable's current value is initialized.Returns
trueiff the variable's current value is initialized. This holds for variables whose value has a non-top qualifier that does not have the meta-annotationHoldsForDefaultValue(e.g., variables with aNonNullvalue), as well as variables whose declaration has a qualifier that has the meta-annotationHoldsForDefaultValue(e.g., variables whose declared type isNullable).- Parameters:
factory- the parent checker's factoryvalue- the variable's current valuevar- the variable to check- Returns:
- whether the specified variable is yet to be initialized
-