Class ModifiabilityBaseAnnotatedTypeFactory
- All Implemented Interfaces:
AnnotationProvider
- Direct Known Subclasses:
GrowAnnotatedTypeFactory,IteratorAnnotatedTypeFactory,ReplaceAnnotatedTypeFactory,SeqGrowAnnotatedTypeFactory,ShrinkAnnotatedTypeFactory
-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
GenericAnnotatedTypeFactory.ClassAndStore<S>, GenericAnnotatedTypeFactory.JavaExpressionAndOffset, GenericAnnotatedTypeFactory.LambdaAndStore<S>, GenericAnnotatedTypeFactory.ScanStateNested classes/interfaces inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
AnnotatedTypeFactory.AnnotationWithMetaAnnotation, AnnotatedTypeFactory.BinaryArgTypes, AnnotatedTypeFactory.CapturedTypeVarSubstitutor, AnnotatedTypeFactory.ExpressionAndOffset, AnnotatedTypeFactory.FnInterfaceAndType, AnnotatedTypeFactory.ParameterizedExecutableType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final TypeMirrorThe erasedjava.util.Collectiontype.protected final AnnotationMirrorThe@IteratorPolyModqualifier.protected final TypeMirrorThe erasedjava.util.Iteratortype.protected final TypeMirrorThe erasedjava.util.ListIteratortype.protected final TypeMirrorThe erasedjava.util.Map.Entrytype.protected final TypeMirrorThe erasedjava.util.Maptype.Fields inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
analysis, arrayTypesAreRelevant, cfgVisualizer, contractsUtils, defaults, dependentTypesHelper, emptyStore, exceptionalExitStores, flowByDefault, flowResult, flowResultAnalysisCaches, formalParameterPattern, hasOrIsSubchecker, initializationStaticStore, initializationStore, methodInvocationStores, poly, regularExitStores, relevantJavaTypes, returnStatementStores, scannedClasses, shouldClearSubcheckerSharedCFGs, sideEffectsUnrefineAliases, subcheckerSharedCFG, transfer, treeAnnotator, typeAnnotatorFields inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
ajavaTypes, annotatedForValueElement, artificialTreeToEnclosingElementMap, capturedTypeVarSubstitutor, checker, currentFileAjavaTypes, debugGat, doesNotUnrefineReceiverValueElement, 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, sideEffectsOnlyValueElement, stubTypes, trees, typeArgumentInference, typeFormatter, typeHierarchy, typeInformationPresenter, types, typeVarSubstitutor, uid, wpiOutputFormat -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a ModifiabilityBaseAnnotatedTypeFactory. -
Method Summary
Modifier and TypeMethodDescriptioncanonicalAnnotation(AnnotationMirror annotation) Returns the canonical annotation for the passed annotation.canonicalAnnotation(AnnotationMirror annotation, @Nullable TypeMirror tm) Expands the whole-modifiability aliases into this hierarchy, with structural weakening only for aliases whose meaning depends on the annotated type.protected final TypeMirrorerasureOf(@FullyQualifiedName String canonicalName) Returns the erasure of the named type.protected booleanReturns true if this checker's hierarchy is one of the capabilities that the whole-modifiability aliases (@Modifiable,@Unmodifiable,@MaybeModifiable,@UnmodifiableParam, and@PolyModifiable) expand into.protected booleanReturns true if this checker's hierarchy contains a negative qualifier, such as@Ungrowable.methodFromUse(MethodInvocationTree tree, boolean inferTypeArgs) protected abstract AnnotationMirrorReturns the negative capability qualifier, such as@Ungrowable.protected abstract AnnotationMirrorReturns the polymorphic capability qualifier, such as@PolyGrowable.protected booleanReturns true if@PolyModifiableweakens to the top qualifier ontype, rather than to this checker's polymorphic qualifier.protected abstract AnnotationMirrorReturns the positive capability qualifier, such as@Growable.protected @Nullable TypeMirrorReturns the erased type that the result of an iterator method must be a subtype of for this checker to refine the result, or null if this checker does not refine iterator results.protected voidrefineIteratorReturnType(MethodInvocationTree tree, AnnotatedTypeMirror.AnnotatedExecutableType methodType) Refines the result ofiterator()andlistIterator()based on@IteratorPolyMod.protected voidrefineReturnTypeForPreservesModifiability(MethodInvocationTree tree, AnnotatedTypeMirror.AnnotatedExecutableType methodType) Refines the return type of a@PreservesModifiabilitymethod.protected abstract AnnotationMirrorReturns the top qualifier of this checker's hierarchy, such as@MaybeGrowable.protected booleanReturns true iftypestructurally cannot support this checker's capability, so that@Modifiableand@Unmodifiableweaken to the top qualifier ontype.protected abstract List<TypeMirror> Returns erased types whose every subtype has this checker's capability, unlesstypeLacksCapability(javax.lang.model.type.TypeMirror)holds of the subtype.Methods inherited from class org.checkerframework.common.basetype.BaseAnnotatedTypeFactory
createFlowAnalysisMethods inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
addAnnotationsFromDefaultForType, addCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotationsForWarnRedundant, addDefaultAnnotations, addSharedCFGForTree, addUncheckedStandardDefaults, analyze, annotationsForIrrelevantJavaType, applyInferredAnnotations, applyQualifierParameterDefaults, applyQualifierParameterDefaults, arrayTypesAreRelevant, artificialTreeMap, checkForDefaultQualifierInHierarchy, constructorFromUse, constructorFromUsePreSubstitution, createAndInitQualifierDefaults, createCFGVisualizer, createContractsFromMethod, createDefaultForTypeAnnotator, createDefaultForUseTypeAnnotator, createDependentTypesHelper, createFlowTransferFunction, createQualifierDefaults, createQualifierPolymorphism, createRequiresOrEnsuresQualifier, createTreeAnnotator, createTypeAnnotator, 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, getStoreBefore, getStoreBefore, getSupportedMonotonicTypeQualifiers, getTypeFactoryOfSubchecker, getTypeFactoryOfSubcheckerOrNull, handleCFGViz, irrelevantExtraMessage, isIgnoredExceptionType, isRelevant, isRelevant, isRelevantImpl, isUnreachable, methodFromUsePreSubstitution, parseJavaExpressionString, performFlowAnalysisForClass, performFlowAnalysisForClassOnce, postAnalyze, postAsMemberOf, postDirectSuperTypes, postInit, preProcessClassTree, setRoot, typeVariablesFromUseMethods inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
adaptGetClassReturnTypeToReceiver, addAliasedDeclAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, applyCaptureConversion, applyCaptureConversion, applyUnboxing, areSameByClass, binaryTreeArgTypes, binaryTreeArgTypes, 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, getRecordedLambdaParameterType, getResultingTypeOfConstructorMemberReference, getSelfType, getSideEffectsOnlyExpressionMap, getSideEffectsOnlyExpressions, getStringType, getSupportedTypeQualifierNames, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeDeclarationBounds, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, getUnboxedType, getVisitorTreePath, getWholeProgramInference, getWidenedAnnotations, getWidenedType, getWidenedType, hasDoesNotUnrefineReceiver, hasExplicitNoQualifierParameterInHierarchy, hasExplicitQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, initializeAtm, initializeReflectionResolution, isAliasedTypeAnnotation, isDeclAnnotationWrittenOn, isDeterministic, isFromByteCode, isFromStubFile, isImmutable, isParsingAnnotationFiles, isSideEffectFree, isSupportedQualifier, isSupportedQualifier, isSupportedQualifier, isTop, isWithinConstructor, logGat, makeConditionConsistentWithOtherMethod, mergeAnnotationFileAnnosIntoType, methodFromUse, methodFromUse, methodFromUse, methodFromUseWithoutTypeArgInference, methodFromUseWithoutTypeArgInference, negateConstant, order, parseAnnotationFiles, postProcessClassTree, recordLambdaParameterType, replaceAnnotations, replaceAnnotations, setEnclosingElementForArtificialTree, setVisitorTreePath, shouldWarnIfStubRedundantWithBytecode, toAnnotatedType, toString, type, wpiAdjustForUpdateField, wpiAdjustForUpdateNonField, wpiPrepareMethodForWriting, wpiPrepareMethodForWriting, wpiShouldInferFromNullAssignments, wpiShouldInferTypesForReceivers
-
Field Details
-
ITERATOR_POLY_MOD
The@IteratorPolyModqualifier. -
collectionErasure
The erasedjava.util.Collectiontype. -
mapErasure
The erasedjava.util.Maptype. -
mapEntryErasure
The erasedjava.util.Map.Entrytype. -
iteratorErasure
The erasedjava.util.Iteratortype. -
listIteratorErasure
The erasedjava.util.ListIteratortype.
-
-
Constructor Details
-
ModifiabilityBaseAnnotatedTypeFactory
Creates a ModifiabilityBaseAnnotatedTypeFactory.- Parameters:
checker- the associated type-checker
-
-
Method Details
-
erasureOf
protected final TypeMirror erasureOf(@UnderInitialization(BaseAnnotatedTypeFactory.class) ModifiabilityBaseAnnotatedTypeFactory this, @FullyQualifiedName String canonicalName) Returns the erasure of the named type.The parameter is
@FullyQualifiedNamerather than@CanonicalName, which is whatElements.getTypeElement(java.lang.CharSequence)really requires, because the Signature Checker cannot prove that a string literal such as"java.util.Map.Entry"is a canonical name.- Parameters:
canonicalName- the canonical name of a type that is always present- Returns:
- the erasure of the named type
-
topAnnotation
Returns the top qualifier of this checker's hierarchy, such as@MaybeGrowable.- Returns:
- the top qualifier of this checker's hierarchy
-
positiveCapability
Returns the positive capability qualifier, such as@Growable.- Returns:
- the positive capability qualifier
-
negativeCapability
Returns the negative capability qualifier, such as@Ungrowable. Only call this method ifhasNegativeCapability()returns true.- Returns:
- the negative capability qualifier
-
polyCapability
Returns the polymorphic capability qualifier, such as@PolyGrowable.- Returns:
- the polymorphic capability qualifier
-
hasNegativeCapability
protected boolean hasNegativeCapability()Returns true if this checker's hierarchy contains a negative qualifier, such as@Ungrowable. The Iterator hierarchy does not.- Returns:
- true if this checker's hierarchy contains a negative qualifier
-
typeLacksCapability
Returns true iftypestructurally cannot support this checker's capability, so that@Modifiableand@Unmodifiableweaken to the top qualifier ontype. For example,Map.Entrycannot grow.- Parameters:
type- the type on which an alias was written; it is an upper bound, so it is never a type variable or a wildcard, andlacksCapability(javax.lang.model.type.TypeMirror, java.util.function.Predicate<javax.lang.model.type.TypeMirror>)has already decomposed intersection types, so it is never an intersection type either- Returns:
- true if
typestructurally cannot support this checker's capability
-
typesWithCapability
Returns erased types whose every subtype has this checker's capability, unlesstypeLacksCapability(javax.lang.model.type.TypeMirror)holds of the subtype. For example, the Replace Checker's result includesList.A type variable or wildcard may be instantiated by any subtype of its upper bound, including a subtype that also implements an unrelated interface. For example, a type variable whose upper bound is
AbstractCollectionorSerializablemay be instantiated byHashSet, which cannot be replaced into. So an alias written on a type variable claims this checker's capability only if the upper bound is a subtype of one of these types.- Returns:
- erased types whose subtypes have this checker's capability
-
polyLacksCapability
Returns true if@PolyModifiableweakens to the top qualifier ontype, rather than to this checker's polymorphic qualifier. This differs fromtypeLacksCapability(javax.lang.model.type.TypeMirror)because a polymorphic qualifier may usefully carry a capability that the type itself cannot exercise; for example,Map.Entrycarries the replace capability of its map.- Parameters:
type- the type on which@PolyModifiablewas written; it is an upper bound, so it is never a type variable or a wildcard, andlacksCapability(javax.lang.model.type.TypeMirror, java.util.function.Predicate<javax.lang.model.type.TypeMirror>)has already decomposed intersection types, so it is never an intersection type either- Returns:
- true if
@PolyModifiableweakens to the top qualifier ontype
-
expandsModifiabilityAliases
protected boolean expandsModifiabilityAliases()Returns true if this checker's hierarchy is one of the capabilities that the whole-modifiability aliases (@Modifiable,@Unmodifiable,@MaybeModifiable,@UnmodifiableParam, and@PolyModifiable) expand into. The Iterator hierarchy is not: it states what a collection's iterator preserves rather than whether a mutating method throwsUnsupportedOperationException.- Returns:
- true if the whole-modifiability aliases expand into this checker's hierarchy
-
canonicalAnnotation
Expands the whole-modifiability aliases into this hierarchy, with structural weakening only for aliases whose meaning depends on the annotated type.@Modifiableand@Unmodifiableclaim every component capability, so on a type that structurally cannot exercise this checker's capability, they weaken to the top qualifier; seetypeLacksCapability(javax.lang.model.type.TypeMirror).@PolyModifiableweakens under the different condition ofpolyLacksCapability(javax.lang.model.type.TypeMirror).When
tmis null, as for an alias written in@DefaultQualifier, no structural weakening is applied.A type variable or wildcard is classified by its upper bound, so that, for example,
<T extends Deque<String>>has the same capabilities asDeque. In addition, on a type variable or wildcard,@Modifiableand@Unmodifiableweaken to the top qualifier unless the upper bound is a subtype of a type that has this checker's capability; seetypesWithCapability(). For example,@Modifiable Tfor an unboundedTis@MaybeReplaceable, becauseTmay beSet.- Overrides:
canonicalAnnotationin classAnnotatedTypeFactory- Parameters:
annotation- the qualifier to canonicalizetm- the type the qualifier is applied to, or null- Returns:
- the canonical annotation, which may be the given annotation
-
canonicalAnnotation
Description copied from class:AnnotatedTypeFactoryReturns the canonical annotation for the passed annotation. May return its argument.This method
canonicalAnnotationis called byAnnotatedTypeMirror.addAnnotation(javax.lang.model.element.AnnotationMirror), so it is called for every annotation added to a type.This implementation handles when the passed annotation is an alias of another annotation. Subclasses can do additional work.
- Overrides:
canonicalAnnotationin classAnnotatedTypeFactory- Parameters:
annotation- the qualifier to canonicalize- Returns:
- the canonical annotation, which may be the given annotation
-
refinedIteratorResultBound
Returns the erased type that the result of an iterator method must be a subtype of for this checker to refine the result, or null if this checker does not refine iterator results. The Shrink Checker refines the result ofiterator()andlistIterator(); the Grow and Replace Checkers refine only the result oflistIterator(), because a plainIteratorcan neither grow nor replace.- Returns:
- the erased upper bound of the iterator results this checker refines, or null
-
methodFromUse
protected AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(MethodInvocationTree tree, boolean inferTypeArgs) Description copied from class:AnnotatedTypeFactoryThe implementation ofAnnotatedTypeFactory.methodFromUse(MethodInvocationTree)andAnnotatedTypeFactory.methodFromUseWithoutTypeArgInference(MethodInvocationTree).- Overrides:
methodFromUsein classGenericAnnotatedTypeFactory<CFValue,CFStore, CFTransfer, CFAnalysis> - Parameters:
tree- a method invocation treeinferTypeArgs- true if type arguments should be inferred- Returns:
- the type of the invoked method, any explicit type arguments, and if
inferTypeArgsis true, any inferred type arguments
-
refineReturnTypeForPreservesModifiability
protected void refineReturnTypeForPreservesModifiability(MethodInvocationTree tree, AnnotatedTypeMirror.AnnotatedExecutableType methodType) Refines the return type of a@PreservesModifiabilitymethod.If the method does not have exactly one formal parameter, which is not a varargs parameter, and a non-void result, then the annotation has no effect.
Otherwise, if the declared return type has a qualifier other than the top qualifier, that declared qualifier is used. If the first argument has this checker's positive qualifier (for example,
@Shrinkable), then so does the return type. For every other first argument, the return type is the top qualifier.Such a method cannot be annotated as
@Poly*, because a negative (for example,@Unshrinkable) input could yield either a positive or a negative result. It would be imprecise to always use the top qualifier, because passing a positive argument guarantees a positive return type.This method is called by all five sub-checkers.
- Parameters:
tree- an invocation of a@PreservesModifiabilitymethodmethodType- the annotated executable type of the invoked method
-
refineIteratorReturnType
protected void refineIteratorReturnType(MethodInvocationTree tree, AnnotatedTypeMirror.AnnotatedExecutableType methodType) Refines the result ofiterator()andlistIterator()based on@IteratorPolyMod.iterator()andlistIterator()cannot be annotated as@PolyModifiablebecause not all collections preserve the modifiability of their iterators. (For example,CopyOnWriteArrayListhas unmodifiable iterators even though the list is modifiable.) Thus, special treatment is needed for iterator methods.A declared negative result keeps its declared qualifier, since such an iterator never has the capability. A declared polymorphic result keeps the qualifier that polymorphic resolution gives it. Otherwise, the result qualifier is computed from the receiver: the iterator of a receiver with this checker's negative qualifier also has that negative qualifier, and the iterator of a receiver that has both this checker's positive qualifier and
@IteratorPolyModhas the positive qualifier. In every other case the result is the top qualifier.A declared positive result is not kept, because it holds only when the receiver has the capability and preserves it. For example,
ArrayListdeclares@Growable ListIterator<E> listIterator(), but an@Ungrowable ArrayListhas an@Ungrowablelist iterator and a@MaybeGrowable ArrayListhas a@MaybeGrowableone.This method is called by the Grow, Shrink, and Replace Checkers; see
refinedIteratorResultBound().- Parameters:
tree- the iterator method invocationmethodType- the annotated executable type of the invoked method
-