Class InterningAnnotatedTypeFactory
- All Implemented Interfaces:
AnnotationProvider
AnnotatedTypeFactory
that accounts for the properties of the Interned type system.
This type factory will add the Interned
annotation to a type if the input:
- is a String literal
- is a class literal
- has an enum type
- has a primitive type
- has the type java.lang.Class
- is a use of a class declared to be @Interned
InternedDistinct
to formal parameters that have a @
FindDistinct
declaration annotation. (TODO: That isn't a good implementation, because it is not
accurate: the value might be equals() to some other Java value. More seriously, it permits too
much. Writing @FindDistinct
should permit equality tests on the given formal parameter,
but should not (for example) permit the formal parameter to be assigned into an
@InternedDistinct
location.)
This factory extends BaseAnnotatedTypeFactory
and inherits its functionality,
including: flow-sensitive qualifier inference, qualifier polymorphism (of PolyInterned
),
implicit annotations via DefaultFor
on Interned
(to handle cases 1, 2, 4), and user-specified defaults via DefaultQualifier
.
Case 5 is handled by the stub library.
-
Nested Class Summary
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.CapturedTypeVarSubstitutor, AnnotatedTypeFactory.ParameterizedExecutableType
-
Field Summary
Fields inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
analysis, arraysAreRelevant, cfgVisualizer, contractsUtils, defaults, dependentTypesHelper, emptyStore, exceptionalExitStores, flowByDefault, flowResult, flowResultAnalysisCaches, formalParameterPattern, hasOrIsSubchecker, initializationStaticStore, initializationStore, methodInvocationStores, poly, regularExitStores, relevantJavaTypes, returnStatementStores, scannedClasses, shouldClearSubcheckerSharedCFGs, sideEffectsUnrefineAliases, subcheckerSharedCFG, transfer, treeAnnotator, typeAnnotator
Fields inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
ajavaTypes, annotatedForValueElement, artificialTreeToEnclosingElementMap, capturedTypeVarSubstitutor, checker, currentFileAjavaTypes, elements, ensuresQualifierExpressionElement, ensuresQualifierIfExpressionElement, ensuresQualifierIfListTM, ensuresQualifierIfListValueElement, ensuresQualifierIfResultElement, ensuresQualifierIfTM, ensuresQualifierListTM, ensuresQualifierListValueElement, ensuresQualifierTM, fieldInvariantFieldElement, fieldInvariantQualifierElement, fromExpressionTreeCache, fromMemberTreeCache, fromTypeTreeCache, hasQualifierParameterValueElement, ignoreRawTypeArguments, loader, methodValClassNameElement, methodValMethodNameElement, methodValParamsElement, noQualifierParameterValueElement, objectGetClass, processingEnv, qualHierarchy, qualifierUpperBounds, reflectionResolver, requiresQualifierExpressionElement, requiresQualifierListTM, requiresQualifierListValueElement, requiresQualifierTM, root, shouldCache, stubTypes, trees, typeArgumentInference, typeFormatter, typeHierarchy, types, typeVarSubstitutor, uid, wpiOutputFormat
-
Constructor Summary
ConstructorDescriptionCreates a newInterningAnnotatedTypeFactory
that operates on a particular AST. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addComputedTypeAnnotations
(Tree tree, AnnotatedTypeMirror type, boolean useFlow) void
addComputedTypeAnnotations
(Element element, AnnotatedTypeMirror type) To add annotations to the type of method or constructor parameters, add aTypeAnnotator
usingGenericAnnotatedTypeFactory.createTypeAnnotator()
and see the comment inTypeAnnotator.visitExecutable(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType, Void)
.void
addComputedTypeAnnotationsForWarnRedundant
(Tree tree, AnnotatedTypeMirror type, boolean useFlow) protected DefaultQualifierForUseTypeAnnotator
Creates anDefaultQualifierForUseTypeAnnotator
.protected TreeAnnotator
Returns aTreeAnnotator
that adds annotations to a type based on the contents of a tree.protected TypeAnnotator
Returns aDefaultForTypeAnnotator
that adds annotations to a type based on the content of the type itself.getTypeDeclarationBounds
(TypeMirror typeMirror) Returns the set of qualifiers that are the upper bounds for a use of the type.Unbox type and replace any interning type annotations with @Interned since all primitives can safely use ==.Methods inherited from class org.checkerframework.common.basetype.BaseAnnotatedTypeFactory
createFlowAnalysis
Methods inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
addAnnotationsFromDefaultForType, addCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addDefaultAnnotations, addSharedCFGForTree, addUncheckedStandardDefaults, analyze, annotationsForIrrelevantJavaType, applyInferredAnnotations, applyQualifierParameterDefaults, applyQualifierParameterDefaults, checkAndPerformFlowAnalysis, checkForDefaultQualifierInHierarchy, constructorFromUse, constructorFromUsePreSubstitution, createAndInitQualifierDefaults, createCFGVisualizer, createContractsFromMethod, createDefaultForTypeAnnotator, createDependentTypesHelper, createFlowTransferFunction, createQualifierDefaults, createQualifierPolymorphism, createRequiresOrEnsuresQualifier, getAnnotatedTypeLhs, getAnnotatedTypeLhsNoTypeVarDefault, getAnnotatedTypeRhsUnaryAssign, getAnnotatedTypeVarargsArray, getAnnotationFromJavaExpression, getAnnotationFromJavaExpressionString, getAnnotationMirrorFromJavaExpressionString, getAnnotationsFromJavaExpression, getCFGVisualizer, getContractAnnotations, getContractAnnotations, getContractExpressions, getContractsFromMethod, getDefaultAnnotations, getDefaultAnnotationsForWarnRedundant, getDefaultForTypeAnnotator, getDefaultValueAnnotatedType, getDependentTypesHelper, getEmptyStore, getEnsuresQualifierIfResult, getExceptionalExitStore, getExplicitNewClassAnnos, getExplicitNewClassClassTypeArgs, getExpressionAndOffsetFromJavaExpressionString, getFinalLocalValues, getFirstNodeOfKindForTree, getInferredValueFor, getMethodReturnType, getNodesForTree, getPostconditionAnnotations, getPostconditionAnnotations, getPostconditionAnnotations, getPreconditionAnnotations, getPreconditionAnnotations, getPreconditionAnnotations, getPreOrPostconditionAnnotations, getQualifierPolymorphism, getRegularExitStore, getReturnStatementStores, getSharedCFGForTree, getShouldDefaultTypeVarLocals, getSortedQualifierNames, getStoreAfter, getStoreAfter, getStoreAfter, getStoreBefore, getStoreBefore, getStoreBefore, getSupportedMonotonicTypeQualifiers, getTypeFactoryOfSubchecker, getTypeFactoryOfSubcheckerOrNull, handleCFGViz, irrelevantExtraMessage, isIgnoredExceptionType, isRelevant, isRelevant, isRelevantImpl, isUnreachable, methodFromUse, methodFromUsePreSubstitution, parseJavaExpressionString, performFlowAnalysis, postAnalyze, postAsMemberOf, postDirectSuperTypes, postInit, preProcessClassTree, setRoot, typeVariablesFromUse
Methods inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
adaptGetClassReturnTypeToReceiver, addAliasedDeclAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, applyCaptureConversion, applyCaptureConversion, applyUnboxing, areSameByClass, binaryTreeArgTypes, binaryTreeArgTypes, canonicalAnnotation, checkInvalidOptionsInferSignatures, compoundAssignmentTreeArgTypes, constructorFromUse, constructorFromUseWithoutTypeArgInference, containsCapturedTypes, containsSameByClass, createAnnotatedTypeFormatter, createAnnotationClassLoader, createAnnotationFormatter, createQualifierHierarchy, createQualifierUpperBounds, createSupportedTypeQualifiers, createTypeArgumentInference, createTypeHierarchy, createTypeVariableSubstitutor, declarationFromElement, doesAnnotatedForApplyToThisChecker, fromElement, fromElement, fromElement, getAnnotatedNullType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFormatter, getAnnotatedTypeFromTypeTree, getAnnotationByClass, getAnnotationFormatter, getAnnotationMirror, getAnnotationWithMetaAnnotation, getBoxedType, getBundledTypeQualifiers, getCacheSize, getChecker, getCheckerNames, getContractExpressions, getContractListValues, getDeclAnnotation, getDeclAnnotationNoAliases, getDeclAnnotations, getDeclAnnotationWithMetaAnnotation, getDefaultTypeDeclarationBounds, getDummyAssignedTo, getElementUtils, getEnclosingClassOrMethod, getEnclosingElementForArtificialTree, getEnclosingSubType, getEnclosingType, getEnumConstructorQualifiers, getExpressionAndOffset, getFieldInvariantAnnotationTree, getFieldInvariantDeclarationAnnotations, getFieldInvariants, getFnInterfaceFromTree, getFunctionTypeFromTree, getFunctionTypeFromTree, getImplicitReceiverType, getIterableElementType, getIterableElementType, getMethodReturnType, getNarrowedAnnotations, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getQualifierParameterHierarchies, getQualifierParameterHierarchies, getQualifierUpperBounds, getReceiverType, getResultingTypeOfConstructorMemberReference, getSelfType, getStringType, getSupportedTypeQualifierNames, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, 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
-
Constructor Details
-
InterningAnnotatedTypeFactory
Creates a newInterningAnnotatedTypeFactory
that operates on a particular AST.- Parameters:
checker
- the checker to use
-
-
Method Details
-
createDefaultForUseTypeAnnotator
Description copied from class:GenericAnnotatedTypeFactory
Creates anDefaultQualifierForUseTypeAnnotator
.- Overrides:
createDefaultForUseTypeAnnotator
in classGenericAnnotatedTypeFactory<CFValue,
CFStore, CFTransfer, CFAnalysis> - Returns:
- a new
DefaultQualifierForUseTypeAnnotator
-
getTypeDeclarationBounds
Description copied from class:AnnotatedTypeFactory
Returns the set of qualifiers that are the upper bounds for a use of the type.- Overrides:
getTypeDeclarationBounds
in classAnnotatedTypeFactory
- Parameters:
typeMirror
- a type whose upper bounds to obtain- Returns:
- the set of qualifiers that are the upper bounds for a use of the type
-
createTreeAnnotator
Description copied from class:GenericAnnotatedTypeFactory
Returns aTreeAnnotator
that adds annotations to a type based on the contents of a tree.The default tree annotator is a
ListTreeAnnotator
of the following:PropagationTreeAnnotator
: Propagates annotations from subtreesLiteralTreeAnnotator
: Adds annotations based onQualifierForLiterals
meta-annotationsDependentTypesTreeAnnotator
: Adapts dependent annotations based on context
Subclasses may override this method to specify additional tree annotators, for example:
new ListTreeAnnotator(super.createTreeAnnotator(), new KeyLookupTreeAnnotator(this));
- Overrides:
createTreeAnnotator
in classGenericAnnotatedTypeFactory<CFValue,
CFStore, CFTransfer, CFAnalysis> - Returns:
- a tree annotator
-
createTypeAnnotator
Description copied from class:GenericAnnotatedTypeFactory
Returns aDefaultForTypeAnnotator
that adds annotations to a type based on the content of the type itself.Subclass may override this method. The default type annotator is a
ListTypeAnnotator
of the following:IrrelevantTypeAnnotator
: Adds top to types not listed in the@
RelevantJavaTypes
annotation on the checker.PropagationTypeAnnotator
: Propagates annotation onto wildcards.
- Overrides:
createTypeAnnotator
in classGenericAnnotatedTypeFactory<CFValue,
CFStore, CFTransfer, CFAnalysis> - Returns:
- a type annotator
-
addComputedTypeAnnotations
Description copied from class:GenericAnnotatedTypeFactory
LikeGenericAnnotatedTypeFactory.addComputedTypeAnnotations(Tree, AnnotatedTypeMirror)
. Overriding implementations typically simply pass the boolean to calls to super.- Overrides:
addComputedTypeAnnotations
in classGenericAnnotatedTypeFactory<CFValue,
CFStore, CFTransfer, CFAnalysis> - Parameters:
tree
- an AST nodetype
- the type obtained from treeuseFlow
- whether to use information from dataflow analysis
-
addComputedTypeAnnotationsForWarnRedundant
public void addComputedTypeAnnotationsForWarnRedundant(Tree tree, AnnotatedTypeMirror type, boolean useFlow) Description copied from class:GenericAnnotatedTypeFactory
LikeGenericAnnotatedTypeFactory.addComputedTypeAnnotations(Tree, AnnotatedTypeMirror, boolean)
.For use ONLY by the
-AwarnRedundantAnnotations
command-line option. May add fewer annotations thanGenericAnnotatedTypeFactory.addComputedTypeAnnotations(Tree, AnnotatedTypeMirror, boolean)
.- Overrides:
addComputedTypeAnnotationsForWarnRedundant
in classGenericAnnotatedTypeFactory<CFValue,
CFStore, CFTransfer, CFAnalysis> - Parameters:
tree
- an AST nodetype
- the type obtained from treeuseFlow
- whether to use information from dataflow analysis
-
addComputedTypeAnnotations
Description copied from class:GenericAnnotatedTypeFactory
To add annotations to the type of method or constructor parameters, add aTypeAnnotator
usingGenericAnnotatedTypeFactory.createTypeAnnotator()
and see the comment inTypeAnnotator.visitExecutable(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType, Void)
.- Overrides:
addComputedTypeAnnotations
in classGenericAnnotatedTypeFactory<CFValue,
CFStore, CFTransfer, CFAnalysis> - Parameters:
element
- an elementtype
- the type obtained fromelt
-
getUnboxedType
public AnnotatedTypeMirror.AnnotatedPrimitiveType getUnboxedType(AnnotatedTypeMirror.AnnotatedDeclaredType type) Unbox type and replace any interning type annotations with @Interned since all primitives can safely use ==. See case 4 in the class comments.- Overrides:
getUnboxedType
in classAnnotatedTypeFactory
- Parameters:
type
- the declared type- Returns:
- the unboxed primitive type
-