Class NullnessAnnotatedTypeFactory
- All Implemented Interfaces:
AnnotationProvider
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classNullness doesn't call propagation on binary and unary because the result is always @Initialized (the default qualifier).protected classNullnessQualifierHierarchy.protected classprotected classNested classes/interfaces inherited from class org.checkerframework.checker.initialization.InitializationAnnotatedTypeFactory
InitializationAnnotatedTypeFactory.CommitmentTreeAnnotator, InitializationAnnotatedTypeFactory.CommitmentTypeAnnotator, InitializationAnnotatedTypeFactory.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
FieldsModifier and TypeFieldDescriptionprotected final ExecutableElementThe Class.getCanonicalName() method.protected final CollectionToArrayHeuristicsDetermines the nullness type of calls toCollection.toArray().protected final AnnotationMirrorThe @MonotonicNonNullannotation.protected final AnnotationMirrorThe @NonNullannotation.protected final AnnotationMirrorThe @Nullableannotation.protected final Set<Class<? extends Annotation>> Cache for the nullness annotations.protected final AnnotationMirrorThe @PolyNullannotation.protected final SystemGetPropertyHandlerHandles invocations ofSystem.getProperty(String).Fields inherited from class org.checkerframework.checker.initialization.InitializationAnnotatedTypeFactory
FBCBOTTOM, initAnnoNames, initAnnos, INITIALIZED, NOT_ONLY_INITIALIZED, objectTypeMirror, UNDER_INITALIZATION, 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, 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, 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, typeInformationPresenter, types, typeVarSubstitutor, uid, wpiOutputFormat -
Constructor Summary
ConstructorsConstructorDescriptionCreates a NullnessAnnotatedTypeFactory. -
Method Summary
Modifier and TypeMethodDescriptionvoidadaptGetClassReturnTypeToReceiver(AnnotatedTypeMirror.AnnotatedExecutableType getClassType, AnnotatedTypeMirror receiverType, ExpressionTree tree) Java special-cases the return type ofgetClass().protected voidaddAnnotationsFromDefaultForType(@Nullable Element element, AnnotatedTypeMirror type) Adds default qualifiers based on the underlying type oftypetotype.protected booleancontainsNullnessAnnotation(@Nullable List<? extends AnnotationTree> annoTrees, Tree typeTree) Returns true if some annotation on the given type, or in the given list, is a nullness annotation such as @NonNull, @Nullable, @MonotonicNonNull, etc.protected booleancontainsNullnessAnnotation(List<? extends AnnotationTree> annoTrees) Returns true if some annotation in the given list is a nullness annotation such as @NonNull, @Nullable, @MonotonicNonNull, etc.protected AnnotatedTypeFormatterReturns an AnnotatedTypeFormatter that does not print the qualifiers on null literals.protected DefaultForTypeAnnotatorCreates anDefaultForTypeAnnotator.protected NullnessAnalysisReturns the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis.createFlowTransferFunction(CFAbstractAnalysis<NullnessValue, NullnessStore, NullnessTransfer> analysis) Returns the appropriate transfer function that is used for the given org.checkerframework.dataflow analysis.protected QualifierHierarchyReturns theQualifierHierarchyto be used by this checker.protected @Nullable AnnotationMirrorcreateRequiresOrEnsuresQualifier(String expression, AnnotationMirror qualifier, AnnotatedTypeMirror declaredType, Analysis.BeforeOrAfter preOrPost, @Nullable List<AnnotationMirror> preconds) Creates aRequiresQualifier("...")orEnsuresQualifier("...")annotation for the given expression.protected Set<Class<? extends Annotation>> Returns a mutable set of annotation classes that are supported by a checker.protected TreeAnnotatorReturns aTreeAnnotatorthat adds annotations to a type based on the contents of a tree.protected TypeAnnotatorReturns aDefaultForTypeAnnotatorthat adds annotations to a type based on the content of the type itself.getDefaultValueAnnotatedType(TypeMirror typeMirror) Return the type of the default value of the given type.Returns the annotation that makes up the invariant of this commitment type system, such as@NonNull.Returns the return type of the methodmat the return statementr.Set<Class<? extends Annotation>> Returns the list of annotations of the non-null type system.org.plumelib.util.IPair<List<VariableTree>, List<VariableTree>> getUninitializedFields(NullnessStore store, TreePath path, boolean isStatic, Collection<? extends AnnotationMirror> receiverAnnotations) Returns the fields that are not yet initialized in a given store.protected booleanhasFieldInvariantAnnotation(AnnotatedTypeMirror type, VariableElement fieldElement) Returns whether or nottypehas the invariant annotation.booleanisImmutable(TypeMirror type) A non-null reference to an object stays non-null under mutation.booleanReturns true ifnodeis an invocation of Map.get.protected booleanReturns true if the given annotation is @NonNull or an alias for it.protected booleanReturns true if the given annotation is @Nullable or an alias for it.protected booleanReturns true if the given annotation is a nullness annotation such as @NonNull, @Nullable, @MonotonicNonNull, etc.methodFromUse(MethodInvocationTree tree, boolean inferTypeArgs) protected voidreplacePolyQualifier(AnnotatedTypeMirror lhsType, Tree context) voidwpiAdjustForUpdateField(Tree lhsTree, Element element, String fieldName, AnnotatedTypeMirror rhsATM) Changes the type ofrhsATMwhen being assigned to a field, for use by whole-program inference.voidChanges the type ofrhsATMwhen being assigned to anything other than a field, for use by whole-program inference.booleanReturns whether whole-program inference should infer types for receiver expressions.Methods inherited from class org.checkerframework.checker.initialization.InitializationAnnotatedTypeFactory
areAllFieldsInitializedOnly, createUnderInitializationAnnotation, createUnderInitializationAnnotation, createUnknownInitializationAnnotation, createUnknownInitializationAnnotation, getAnnotatedTypeLhs, getInitializationAnnotations, getInitializedInvariantFields, getInvalidConstructorReturnTypeAnnotations, getSelfType, getTypeFrameFromAnnotation, getUnderInitializationAnnotationOfSuperType, getUninitializedInvariantFields, hasFieldInvariantAnnotation, isFbcBottom, isFbcBottom, isInitializationAnnotation, isInitialized, isInitialized, isInitializedForFrame, isUnderInitialization, isUnderInitialization, isUnknownInitialization, isUnknownInitialization, methodFromUse, postAsMemberOf, setSelfTypeInInitializationCodeMethods inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
addCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotationsForWarnRedundant, addDefaultAnnotations, addSharedCFGForTree, addUncheckedStandardDefaults, analyze, annotationsForIrrelevantJavaType, applyInferredAnnotations, applyQualifierParameterDefaults, applyQualifierParameterDefaults, checkAndPerformFlowAnalysis, checkForDefaultQualifierInHierarchy, constructorFromUse, constructorFromUsePreSubstitution, createAndInitQualifierDefaults, createCFGVisualizer, createContractsFromMethod, createDefaultForUseTypeAnnotator, createDependentTypesHelper, createQualifierDefaults, createQualifierPolymorphism, getAnnotatedTypeLhsNoTypeVarDefault, getAnnotatedTypeRhsUnaryAssign, getAnnotatedTypeVarargsArray, getAnnotationFromJavaExpression, getAnnotationFromJavaExpressionString, getAnnotationMirrorFromJavaExpressionString, getAnnotationsFromJavaExpression, getCFGVisualizer, getContractAnnotations, getContractAnnotations, getContractExpressions, getContractsFromMethod, getDefaultAnnotations, getDefaultAnnotationsForWarnRedundant, getDefaultForTypeAnnotator, 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, methodFromUsePreSubstitution, parseJavaExpressionString, performFlowAnalysis, postAnalyze, postDirectSuperTypes, postInit, preProcessClassTree, setRoot, typeVariablesFromUseMethods inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
addAliasedDeclAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, applyCaptureConversion, applyCaptureConversion, applyUnboxing, areSameByClass, binaryTreeArgTypes, binaryTreeArgTypes, canonicalAnnotation, checkInvalidOptionsInferSignatures, compoundAssignmentTreeArgTypes, constructorFromUse, constructorFromUseWithoutTypeArgInference, containsCapturedTypes, containsSameByClass, createAnnotationClassLoader, createAnnotationFormatter, createQualifierUpperBounds, 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, getNarrowedAnnotations, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getQualifierParameterHierarchies, getQualifierParameterHierarchies, getQualifierUpperBounds, getReceiverType, getResultingTypeOfConstructorMemberReference, getStringType, getSupportedTypeQualifierNames, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeDeclarationBounds, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, getUnboxedType, getVisitorTreePath, getWholeProgramInference, getWidenedAnnotations, getWidenedType, getWidenedType, hasExplicitNoQualifierParameterInHierarchy, hasExplicitQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, initializeAtm, initializeReflectionResolution, isDeterministic, isFromByteCode, isFromStubFile, isSideEffectFree, isSupportedQualifier, isSupportedQualifier, isSupportedQualifier, isTop, isWithinConstructor, logGat, makeConditionConsistentWithOtherMethod, mergeAnnotationFileAnnosIntoType, methodFromUse, methodFromUse, methodFromUseWithoutTypeArgInference, methodFromUseWithoutTypeArgInference, negateConstant, order, parseAnnotationFiles, postProcessClassTree, replaceAnnotations, replaceAnnotations, setEnclosingElementForArtificialTree, setVisitorTreePath, shouldWarnIfStubRedundantWithBytecode, toAnnotatedType, toString, type, wpiPrepareMethodForWriting, wpiPrepareMethodForWriting
-
Field Details
-
NONNULL
The @NonNullannotation. -
NULLABLE
The @Nullableannotation. -
POLYNULL
The @PolyNullannotation. -
MONOTONIC_NONNULL
The @MonotonicNonNullannotation. -
systemGetPropertyHandler
Handles invocations ofSystem.getProperty(String). -
collectionToArrayHeuristics
Determines the nullness type of calls toCollection.toArray(). -
classGetCanonicalName
The Class.getCanonicalName() method. -
nullnessAnnos
Cache for the nullness annotations.
-
-
Constructor Details
-
NullnessAnnotatedTypeFactory
Creates a NullnessAnnotatedTypeFactory.- Parameters:
checker- the associatedNullnessChecker
-
-
Method Details
-
createSupportedTypeQualifiers
Description copied from class:AnnotatedTypeFactoryReturns 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 otherElementTypevalues) are automatically considered as supported annotations.To support a different set of annotations than those in the qual subdirectory, or that have other
ElementTypevalues, 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:
The set of qualifiers returned by@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:
createSupportedTypeQualifiersin classAnnotatedTypeFactory- Returns:
- the type qualifiers supported this processor, or an empty set if none
- Only support annotations located in a checker's qual directory:
-
replacePolyQualifier
For types of left-hand side of an assignment, this method replacesPolyNullwithNullable(or withNonNullif the org.checkerframework.dataflow analysis has determined that this is allowed soundly. For example:@PolyNull String foo(@PolyNull String param) { if (param == null) { // @PolyNull is really @Nullable, so change // the type of param to @Nullable. param = null; } return param; }- Parameters:
lhsType- type to replace whose polymorphic qualifier will be replacedcontext- tree used to get dataflow value
-
getUninitializedFields
public org.plumelib.util.IPair<List<VariableTree>,List<VariableTree>> getUninitializedFields(NullnessStore store, TreePath path, boolean isStatic, Collection<? extends AnnotationMirror> receiverAnnotations) Description copied from class:InitializationAnnotatedTypeFactoryReturns the fields that are not yet initialized in a given store. The result is a pair of lists:- fields that are not yet initialized and have the invariant annotation
- fields that are not yet initialized and do not have the invariant annotation
- Overrides:
getUninitializedFieldsin classInitializationAnnotatedTypeFactory<NullnessValue,NullnessStore, NullnessTransfer, NullnessAnalysis> - Parameters:
store- a storepath- the current path, used to determine the current classisStatic- whether to report static fields or instance fieldsreceiverAnnotations- the annotations on the receiver- Returns:
- the fields that are not yet initialized in a given store (a pair of lists)
-
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<NullnessValue,NullnessStore, NullnessTransfer, NullnessAnalysis> - Returns:
- the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis
-
createFlowTransferFunction
public NullnessTransfer createFlowTransferFunction(CFAbstractAnalysis<NullnessValue, NullnessStore, NullnessTransfer> analysis) Description copied from class:GenericAnnotatedTypeFactoryReturns the appropriate transfer function that is used for the given org.checkerframework.dataflow analysis.This implementation uses the checker naming convention to create the appropriate transfer function. If no transfer function is found, it returns an instance of
CFTransfer.Subclasses have to override this method to create the appropriate transfer function if they do not follow the checker naming convention.
- Overrides:
createFlowTransferFunctionin classGenericAnnotatedTypeFactory<NullnessValue,NullnessStore, NullnessTransfer, NullnessAnalysis> - Parameters:
analysis- a dataflow analysis- Returns:
- a new transfer function
-
createAnnotatedTypeFormatter
Returns an AnnotatedTypeFormatter that does not print the qualifiers on null literals.- Overrides:
createAnnotatedTypeFormatterin classAnnotatedTypeFactory- Returns:
- an AnnotatedTypeFormatter that does not print the qualifiers on null literals
-
methodFromUse
protected AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(MethodInvocationTree tree, boolean inferTypeArgs) Description copied from class:AnnotatedTypeFactoryThe implementation ofAnnotatedTypeFactory.methodFromUse(MethodInvocationTree)andAnnotatedTypeFactory.methodFromUseWithoutTypeArgInference(MethodInvocationTree).- Overrides:
methodFromUsein classGenericAnnotatedTypeFactory<NullnessValue,NullnessStore, NullnessTransfer, NullnessAnalysis> - Parameters:
tree- a method invocation treeinferTypeArgs- whether type arguments should be inferred- Returns:
- the type of the invoked method, any explicit type arguments, and if
inferTypeArgsis true, any inferred type arguments
-
adaptGetClassReturnTypeToReceiver
public void adaptGetClassReturnTypeToReceiver(AnnotatedTypeMirror.AnnotatedExecutableType getClassType, AnnotatedTypeMirror receiverType, ExpressionTree tree) Description copied from class:AnnotatedTypeFactoryJava special-cases the return type ofgetClass(). Though the method has a return type ofClass<?>, the compiler special cases this return-type and changes the bound of the type argument to the erasure of the receiver type. For example:x.getClass()has the typeClass< ? extends erasure_of_x >someInteger.getClass()has the typeClass< ? extends Integer >
- Overrides:
adaptGetClassReturnTypeToReceiverin classAnnotatedTypeFactory- Parameters:
getClassType- this must be a type representing a call to Object.getClass otherwise a runtime exception will be thrown. It is modified by side effect.receiverType- the receiver type of the method invocation (not the declared receiver type)tree- getClass method invocation tree
-
getMethodReturnType
Description copied from class:AnnotatedTypeFactoryReturns the return type of the methodmat the return statementr. This implementation just callsAnnotatedTypeFactory.getMethodReturnType(MethodTree), but subclasses may override this method to change the type based on the return statement.- Overrides:
getMethodReturnTypein classAnnotatedTypeFactory- Parameters:
m- tree of a method declarationr- a return statement within methodm- Returns:
- the return type of the method
mat the return statementr
-
createDefaultForTypeAnnotator
Description copied from class:GenericAnnotatedTypeFactoryCreates anDefaultForTypeAnnotator.- Overrides:
createDefaultForTypeAnnotatorin classGenericAnnotatedTypeFactory<NullnessValue,NullnessStore, NullnessTransfer, NullnessAnalysis> - Returns:
- a new
DefaultForTypeAnnotator
-
addAnnotationsFromDefaultForType
protected void addAnnotationsFromDefaultForType(@Nullable Element element, AnnotatedTypeMirror type) Description copied from class:GenericAnnotatedTypeFactoryAdds default qualifiers based on the underlying type oftypetotype. Ifelementis a local variable, or if the type already has an annotation from the relevant type hierarchy, then the defaults are not added.(This uses both the
DefaultQualifierForUseTypeAnnotatorandDefaultForTypeAnnotator.)- Overrides:
addAnnotationsFromDefaultForTypein classGenericAnnotatedTypeFactory<NullnessValue,NullnessStore, NullnessTransfer, NullnessAnalysis> - Parameters:
element- possibly null element whose type istypetype- the type to which defaults are added
-
createTypeAnnotator
Description copied from class:GenericAnnotatedTypeFactoryReturns aDefaultForTypeAnnotatorthat adds annotations to a type based on the content of the type itself.Subclass may override this method. The default type annotator is a
ListTypeAnnotatorof the following:IrrelevantTypeAnnotator: Adds top to types not listed in the@RelevantJavaTypesannotation on the checker.PropagationTypeAnnotator: Propagates annotation onto wildcards.
- Overrides:
createTypeAnnotatorin classInitializationAnnotatedTypeFactory<NullnessValue,NullnessStore, NullnessTransfer, NullnessAnalysis> - Returns:
- a type annotator
-
createTreeAnnotator
Description copied from class:GenericAnnotatedTypeFactoryReturns aTreeAnnotatorthat adds annotations to a type based on the contents of a tree.The default tree annotator is a
ListTreeAnnotatorof the following:PropagationTreeAnnotator: Propagates annotations from subtreesLiteralTreeAnnotator: Adds annotations based onQualifierForLiteralsmeta-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:
createTreeAnnotatorin classInitializationAnnotatedTypeFactory<NullnessValue,NullnessStore, NullnessTransfer, NullnessAnalysis> - Returns:
- a tree annotator
-
getNullnessAnnotations
Returns the list of annotations of the non-null type system.- Returns:
- the list of annotations of the non-null type system
-
getFieldInvariantAnnotation
Description copied from class:InitializationAnnotatedTypeFactoryReturns the annotation that makes up the invariant of this commitment type system, such as@NonNull.- Specified by:
getFieldInvariantAnnotationin classInitializationAnnotatedTypeFactory<NullnessValue,NullnessStore, NullnessTransfer, NullnessAnalysis> - Returns:
- the invariant annotation for this type system
-
hasFieldInvariantAnnotation
protected boolean hasFieldInvariantAnnotation(AnnotatedTypeMirror type, VariableElement fieldElement) Returns whether or nottypehas the invariant annotation.If the
typeis a type variable, this method returns true if any possible instantiation of the type parameter could have the invariant annotation. SeeInitializationAnnotatedTypeFactory.hasFieldInvariantAnnotation(VariableTree)for an example.In other words, is the lower bound @NonNull?
- Specified by:
hasFieldInvariantAnnotationin classInitializationAnnotatedTypeFactory<NullnessValue,NullnessStore, NullnessTransfer, NullnessAnalysis> - Parameters:
type- of field that might have invariant annotationfieldElement- the field element, which can be used to check annotations on the declaration- Returns:
- whether or not type has the invariant annotation
-
createQualifierHierarchy
Description copied from class:AnnotatedTypeFactoryReturns theQualifierHierarchyto be used by this checker.The implementation builds the type qualifier hierarchy for the
AnnotatedTypeFactory.getSupportedTypeQualifiers()using the meta-annotations found in them. The current implementation returns an instance ofNoElementQualifierHierarchy.Subclasses must override this method if their qualifiers have elements; the method must return an implementation of
QualifierHierarchy, such asElementQualifierHierarchy.- Overrides:
createQualifierHierarchyin classAnnotatedTypeFactory- Returns:
- a QualifierHierarchy for this type system
-
containsNullnessAnnotation
protected boolean containsNullnessAnnotation(@Nullable List<? extends AnnotationTree> annoTrees, Tree typeTree) Returns true if some annotation on the given type, or in the given list, is a nullness annotation such as @NonNull, @Nullable, @MonotonicNonNull, etc.This method ignores aliases of nullness annotations that are declaration annotations, because they may apply to inner types.
- Parameters:
annoTrees- a list of annotations that the Java parser attached to the variable/method declaration; null if this type is not from such a location. This is a list of extra annotations to check, in addition to those on the type.typeTree- the type whose annotations to test- Returns:
- true if some annotation is a nullness annotation
-
containsNullnessAnnotation
Returns true if some annotation in the given list is a nullness annotation such as @NonNull, @Nullable, @MonotonicNonNull, etc.This method ignores aliases of nullness annotations that are declaration annotations, because they may apply to inner types.
Clients that are processing a field or variable definition, or a method return type, should call
containsNullnessAnnotation(List, Tree)instead.- Parameters:
annoTrees- a list of annotations to check- Returns:
- true if some annotation is a nullness annotation
- See Also:
-
isNullnessAnnotation
Returns true if the given annotation is a nullness annotation such as @NonNull, @Nullable, @MonotonicNonNull, etc.- Parameters:
am- an annotation- Returns:
- true if the given annotation is a nullness annotation
-
isNonNullOrAlias
Returns true if the given annotation is @NonNull or an alias for it.- Parameters:
am- an annotation- Returns:
- true if the given annotation is @NonNull or an alias for it
-
isNullableOrAlias
Returns true if the given annotation is @Nullable or an alias for it.- Parameters:
am- an annotation- Returns:
- true if the given annotation is @Nullable or an alias for it
-
getDefaultValueAnnotatedType
Description copied from class:GenericAnnotatedTypeFactoryReturn the type of the default value of the given type. The default value is 0, false, or null.- Overrides:
getDefaultValueAnnotatedTypein classGenericAnnotatedTypeFactory<NullnessValue,NullnessStore, NullnessTransfer, NullnessAnalysis> - Parameters:
typeMirror- a type- Returns:
- the annotated type of
type's default value
-
isImmutable
A non-null reference to an object stays non-null under mutation.- Overrides:
isImmutablein classAnnotatedTypeFactory- Parameters:
type- type to test- Returns:
- true if the type is immutable
-
wpiAdjustForUpdateField
public void wpiAdjustForUpdateField(Tree lhsTree, Element element, String fieldName, AnnotatedTypeMirror rhsATM) Description copied from class:AnnotatedTypeFactoryChanges the type ofrhsATMwhen being assigned to a field, for use by whole-program inference. The default implementation does nothing.- Overrides:
wpiAdjustForUpdateFieldin classAnnotatedTypeFactory- Parameters:
lhsTree- the tree for the field whose type will be changedelement- the element for the field whose type will be changedfieldName- the name of the field whose type will be changedrhsATM- the type of the expression being assigned to the field, which is side-effected by this method
-
wpiAdjustForUpdateNonField
Description copied from class:AnnotatedTypeFactoryChanges the type ofrhsATMwhen being assigned to anything other than a field, for use by whole-program inference. The default implementation does nothing.- Overrides:
wpiAdjustForUpdateNonFieldin classAnnotatedTypeFactory- Parameters:
rhsATM- the type of the rhs of the pseudo-assignment, which is side-effected by this method
-
wpiShouldInferTypesForReceivers
public boolean wpiShouldInferTypesForReceivers()Description copied from class:AnnotatedTypeFactoryReturns whether whole-program inference should infer types for receiver expressions. For some type systems, such as nullness, it doesn't make sense for WPI to do inference on receivers.- Overrides:
wpiShouldInferTypesForReceiversin classAnnotatedTypeFactory- Returns:
- true if WPI should infer types for method receiver parameters, false otherwise
-
createRequiresOrEnsuresQualifier
protected @Nullable AnnotationMirror createRequiresOrEnsuresQualifier(String expression, AnnotationMirror qualifier, AnnotatedTypeMirror declaredType, Analysis.BeforeOrAfter preOrPost, @Nullable List<AnnotationMirror> preconds) Description copied from class:GenericAnnotatedTypeFactoryCreates aRequiresQualifier("...")orEnsuresQualifier("...")annotation for the given expression.This is of the form
@RequiresQualifier(expression="expression", qualifier=MyQual.class)or@EnsuresQualifier(expression="expression", qualifier=MyQual.class), where "expression" is exactly the stringexpressionand MyQual is the annotation represented byqualifier.Returns null if the expression is invalid when combined with the kind of annotation: for example, precondition annotations on "this" and parameters ("#1", etc.) are not supported, because receiver/parameter annotations should be inferred instead.
This implementation returns null if no annotation can be created, because the qualifier has elements/arguments, which
@RequiresQualifierand@EnsuresQualifierdo not support. Subclasses may override this method to return qualifiers that do have arguments instead of returning null.- Overrides:
createRequiresOrEnsuresQualifierin classGenericAnnotatedTypeFactory<NullnessValue,NullnessStore, NullnessTransfer, NullnessAnalysis> - Parameters:
expression- the expression to which the qualifier appliesqualifier- the qualifier that must be presentdeclaredType- the declared type of the expression, which is used to avoid inferring redundant pre- or postcondition annotationspreOrPost- whether to return a precondition or postcondition annotationpreconds- the list of precondition annotations; used to suppress redundant postconditions; non-null exactly whenpreOrPostisBeforeOrAfter.BEFORE- Returns:
- a
RequiresQualifier("...")orEnsuresQualifier("...")annotation for the given expression, or null
-
isMapGet
Returns true ifnodeis an invocation of Map.get.- Parameters:
node- a CFG node- Returns:
- true if
nodeis an invocation of Map.get
-