Class InterningAnnotatedTypeFactory
- java.lang.Object
-
- org.checkerframework.framework.type.AnnotatedTypeFactory
-
- org.checkerframework.framework.type.GenericAnnotatedTypeFactory<CFValue,CFStore,CFTransfer,CFAnalysis>
-
- org.checkerframework.common.basetype.BaseAnnotatedTypeFactory
-
- org.checkerframework.checker.interning.InterningAnnotatedTypeFactory
-
- All Implemented Interfaces:
AnnotationProvider
public class InterningAnnotatedTypeFactory extends BaseAnnotatedTypeFactory
AnAnnotatedTypeFactory
that accounts for the properties of the Interned type system. This type factory will add theInterned
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 (ofPolyInterned
), implicit annotations viaDefaultFor
onInterned
(to handle cases 1, 2, 4), and user-specified defaults viaDefaultQualifier
. 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.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, 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 InterningAnnotatedTypeFactory(BaseTypeChecker checker)
Creates a newInterningAnnotatedTypeFactory
that operates on a particular AST.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addComputedTypeAnnotations(javax.lang.model.element.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)
.protected DefaultQualifierForUseTypeAnnotator
createDefaultForUseTypeAnnotator()
Creates anDefaultQualifierForUseTypeAnnotator
.protected TreeAnnotator
createTreeAnnotator()
Returns aTreeAnnotator
that adds annotations to a type based on the contents of a tree.protected TypeAnnotator
createTypeAnnotator()
Returns aDefaultForTypeAnnotator
that adds annotations to a type based on the content of the type itself.AnnotationMirrorSet
getTypeDeclarationBounds(javax.lang.model.type.TypeMirror typeMirror)
Returns the set of qualifiers that are the upper bounds for a use of the type.AnnotatedTypeMirror.AnnotatedPrimitiveType
getUnboxedType(AnnotatedTypeMirror.AnnotatedDeclaredType 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, addComputedTypeAnnotations, addDefaultAnnotations, addSharedCFGForTree, addUncheckedStandardDefaults, analyze, annotationsForIrrelevantJavaType, applyInferredAnnotations, applyQualifierParameterDefaults, applyQualifierParameterDefaults, checkAndPerformFlowAnalysis, checkForDefaultQualifierInHierarchy, constructorFromUse, constructorFromUsePreSubstitution, createAndInitQualifierDefaults, createCFGVisualizer, createContractsFromMethod, createDefaultForTypeAnnotator, createDependentTypesHelper, createFlowTransferFunction, createQualifierDefaults, createQualifierPolymorphism, createRequiresOrEnsuresQualifier, 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, getTypeFactoryOfSubcheckerOrNull, handleCFGViz, irrelevantExtraMessage, isComputingAnnotatedTypeMirrorOfLhs, isNotFullyInitializedReceiver, isRelevant, isRelevant, isRelevantImpl, methodFromUse, methodFromUsePreSubstitution, parseJavaExpressionString, performFlowAnalysis, postAnalyze, 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, createQualifierHierarchy, createQualifierUpperBounds, createSupportedTypeQualifiers, 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, getDummyAssignedTo, 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, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, 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
-
InterningAnnotatedTypeFactory
public InterningAnnotatedTypeFactory(BaseTypeChecker checker)
Creates a newInterningAnnotatedTypeFactory
that operates on a particular AST.- Parameters:
checker
- the checker to use
-
-
Method Detail
-
createDefaultForUseTypeAnnotator
protected DefaultQualifierForUseTypeAnnotator createDefaultForUseTypeAnnotator()
Description copied from class:GenericAnnotatedTypeFactory
Creates anDefaultQualifierForUseTypeAnnotator
.- Overrides:
createDefaultForUseTypeAnnotator
in classGenericAnnotatedTypeFactory<CFValue,CFStore,CFTransfer,CFAnalysis>
- Returns:
- a new
DefaultQualifierForUseTypeAnnotator
-
getTypeDeclarationBounds
public AnnotationMirrorSet getTypeDeclarationBounds(javax.lang.model.type.TypeMirror typeMirror)
Description copied from class:AnnotatedTypeFactory
Returns the set of qualifiers that are the upper bounds for a use of the type.For a specific type system, the type declaration bound is retrieved in the following precedence: (1) the annotation on the type declaration bound (2) if an annotation with
@UpperBoundFor
mentions the type or the type kind, use that annotation (3) the top annotation- 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
protected TreeAnnotator 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
protected TypeAnnotator 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
public void addComputedTypeAnnotations(javax.lang.model.element.Element element, AnnotatedTypeMirror type)
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
-
-