Class NullnessNoInitAnnotatedTypeFactory
- java.lang.Object
-
- org.checkerframework.framework.type.AnnotatedTypeFactory
-
- org.checkerframework.framework.type.GenericAnnotatedTypeFactory<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer,NullnessNoInitAnalysis>
-
- org.checkerframework.checker.nullness.NullnessNoInitAnnotatedTypeFactory
-
- All Implemented Interfaces:
AnnotationProvider
public class NullnessNoInitAnnotatedTypeFactory extends GenericAnnotatedTypeFactory<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer,NullnessNoInitAnalysis>
The annotated type factory for the nullness type-system.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
NullnessNoInitAnnotatedTypeFactory.NullnessPropagationTreeAnnotator
Adds nullness-specific propagation rules-
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 Modifier and Type Field Description protected javax.lang.model.element.ExecutableElement
classGetCanonicalName
The Class.getCanonicalName() method.protected CollectionToArrayHeuristics
collectionToArrayHeuristics
Determines the nullness type of calls toCollection.toArray()
.protected javax.lang.model.element.AnnotationMirror
MONOTONIC_NONNULL
The @MonotonicNonNull
annotation.protected javax.lang.model.element.AnnotationMirror
NONNULL
The @NonNull
annotation.protected javax.lang.model.element.AnnotationMirror
NULLABLE
The @Nullable
annotation.protected java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>>
nullnessAnnos
Cache for the nullness annotations.protected javax.lang.model.element.AnnotationMirror
POLYNULL
The @PolyNull
annotation.protected SystemGetPropertyHandler
systemGetPropertyHandler
Handles invocations ofSystem.getProperty(String)
.-
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 NullnessNoInitAnnotatedTypeFactory(BaseTypeChecker checker)
Creates a NullnessAnnotatedTypeFactory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
adaptGetClassReturnTypeToReceiver(AnnotatedTypeMirror.AnnotatedExecutableType getClassType, AnnotatedTypeMirror receiverType, com.sun.source.tree.ExpressionTree tree)
Java special-cases the return type ofgetClass()
.protected void
addAnnotationsFromDefaultForType(@Nullable javax.lang.model.element.Element element, AnnotatedTypeMirror type)
Adds default qualifiers based on the underlying type oftype
totype
.protected boolean
containsNullnessAnnotation(@Nullable java.util.List<? extends com.sun.source.tree.AnnotationTree> annoTrees, com.sun.source.tree.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 boolean
containsNullnessAnnotation(java.util.List<? extends com.sun.source.tree.AnnotationTree> annoTrees)
Returns true if some annotation in the given list is a nullness annotation such as @NonNull, @Nullable, @MonotonicNonNull, etc.protected AnnotatedTypeFormatter
createAnnotatedTypeFormatter()
Returns an AnnotatedTypeFormatter that does not print the qualifiers on null literals.protected DefaultForTypeAnnotator
createDefaultForTypeAnnotator()
Creates anDefaultForTypeAnnotator
.protected NullnessNoInitAnalysis
createFlowAnalysis()
Returns the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis.NullnessNoInitTransfer
createFlowTransferFunction(CFAbstractAnalysis<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer> analysis)
Returns the appropriate transfer function that is used for the given org.checkerframework.dataflow analysis.protected QualifierHierarchy
createQualifierHierarchy()
Returns theQualifierHierarchy
to be used by this checker.protected java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>>
createSupportedTypeQualifiers()
Returns a mutable set of annotation classes that are supported by a checker.protected TreeAnnotator
createTreeAnnotator()
Returns aTreeAnnotator
that adds annotations to a type based on the contents of a tree.AnnotatedTypeMirror
getAnnotatedTypeBefore(JavaExpression expr, com.sun.source.tree.ExpressionTree tree)
Returns the type of a JavaExpressionexpr
if it were evaluated before a treetree
.NullnessNoInitSubchecker
getChecker()
Returns the checker associated with this factory.AnnotatedTypeMirror
getDefaultValueAnnotatedType(javax.lang.model.type.TypeMirror typeMirror)
Return the type of the default value of the given type.AnnotatedTypeMirror
getMethodReturnType(com.sun.source.tree.MethodTree m, com.sun.source.tree.ReturnTree r)
Returns the return type of the methodm
at the return statementr
.java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>>
getNullnessAnnotations()
Returns the list of annotations of the non-null type system.boolean
isImmutable(javax.lang.model.type.TypeMirror type)
A non-null reference to an object stays non-null under mutation.boolean
isMapGet(Node node)
Returns true ifnode
is an invocation of Map.get.protected boolean
isNonNullOrAlias(javax.lang.model.element.AnnotationMirror am)
Returns true if the given annotation is@NonNull
or an alias for it.boolean
isNotFullyInitializedReceiver(com.sun.source.tree.MethodTree methodDeclTree)
Returns true if the receiver of a method or constructor might not be fully initialized.protected boolean
isNullableOrAlias(javax.lang.model.element.AnnotationMirror am)
Returns true if the given annotation is@Nullable
or an alias for it.protected boolean
isNullnessAnnotation(javax.lang.model.element.AnnotationMirror am)
Returns true if the given annotation is a nullness annotation such as@NonNull
,@Nullable
,@MonotonicNonNull
,@PolyNull
, or an alias thereof.protected boolean
isPolyNullOrAlias(javax.lang.model.element.AnnotationMirror am)
Returns true if the given annotation is@PolyNull
or an alias for it.AnnotatedTypeFactory.ParameterizedExecutableType
methodFromUse(com.sun.source.tree.MethodInvocationTree tree)
Determines the type of the invoked method based on the passed method invocation tree.protected void
replacePolyQualifier(AnnotatedTypeMirror lhsType, com.sun.source.tree.Tree context)
-
Methods inherited from class org.checkerframework.framework.type.GenericAnnotatedTypeFactory
addCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotations, addDefaultAnnotations, addSharedCFGForTree, addUncheckedStandardDefaults, analyze, annotationsForIrrelevantJavaType, applyInferredAnnotations, applyQualifierParameterDefaults, applyQualifierParameterDefaults, checkAndPerformFlowAnalysis, checkForDefaultQualifierInHierarchy, constructorFromUse, constructorFromUsePreSubstitution, createAndInitQualifierDefaults, createCFGVisualizer, createContractsFromMethod, createDefaultForUseTypeAnnotator, createDependentTypesHelper, createQualifierDefaults, createQualifierPolymorphism, createRequiresOrEnsuresQualifier, createTypeAnnotator, getAnnotatedTypeLhs, getAnnotatedTypeLhsNoTypeVarDefault, getAnnotatedTypeRhsUnaryAssign, getAnnotatedTypeVarargsArray, getAnnotationFromJavaExpression, getAnnotationFromJavaExpressionString, getAnnotationMirrorFromJavaExpressionString, getAnnotationsFromJavaExpression, getCFGVisualizer, getContractExpressions, getContractsFromMethod, getDefaultAnnotations, getDefaultForTypeAnnotator, 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, isRelevant, isRelevant, isRelevantImpl, methodFromUsePreSubstitution, parseJavaExpressionString, performFlowAnalysis, postAnalyze, postAsMemberOf, postDirectSuperTypes, postInit, preProcessClassTree, setRoot, typeVariablesFromUse
-
Methods inherited from class org.checkerframework.framework.type.AnnotatedTypeFactory
addAliasedDeclAnnotation, addAliasedDeclAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, applyCaptureConversion, applyCaptureConversion, applyUnboxing, areSameByClass, binaryTreeArgTypes, binaryTreeArgTypes, binaryTreeArgTypes, canonicalAnnotation, compoundAssignmentTreeArgTypes, containsSameByClass, containsUninferredTypeArguments, createAnnotationClassLoader, createAnnotationFormatter, createQualifierUpperBounds, 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, 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, getNarrowedAnnotations, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getQualifierParameterHierarchies, getQualifierParameterHierarchies, getQualifierUpperBounds, getReceiverType, getSelfType, getStringType, getSupportedTypeQualifierNames, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeDeclarationBounds, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, getUnboxedType, getUninferredWildcardType, getVisitorTreePath, getWidenedAnnotations, getWidenedType, getWidenedType, hasExplicitNoQualifierParameterInHierarchy, hasExplicitQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, initializeReflectionResolution, isFromByteCode, isFromStubFile, isSideEffectFree, isSupportedQualifier, isSupportedQualifier, isSupportedQualifier, isWithinConstructor, mergeAnnotationFileAnnosIntoType, methodFromUse, negateConstant, order, parseAnnotationFiles, postProcessClassTree, replaceAnnotations, replaceAnnotations, setPathForArtificialTree, setVisitorTreePath, shouldWarnIfStubRedundantWithBytecode, toAnnotatedType, toString, type
-
-
-
-
Field Detail
-
NONNULL
protected final javax.lang.model.element.AnnotationMirror NONNULL
The @NonNull
annotation.
-
NULLABLE
protected final javax.lang.model.element.AnnotationMirror NULLABLE
The @Nullable
annotation.
-
POLYNULL
protected final javax.lang.model.element.AnnotationMirror POLYNULL
The @PolyNull
annotation.
-
MONOTONIC_NONNULL
protected final javax.lang.model.element.AnnotationMirror MONOTONIC_NONNULL
The @MonotonicNonNull
annotation.
-
systemGetPropertyHandler
protected final SystemGetPropertyHandler systemGetPropertyHandler
Handles invocations ofSystem.getProperty(String)
.
-
collectionToArrayHeuristics
protected final CollectionToArrayHeuristics collectionToArrayHeuristics
Determines the nullness type of calls toCollection.toArray()
.
-
classGetCanonicalName
protected final javax.lang.model.element.ExecutableElement classGetCanonicalName
The Class.getCanonicalName() method.
-
nullnessAnnos
protected final java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> nullnessAnnos
Cache for the nullness annotations.
-
-
Constructor Detail
-
NullnessNoInitAnnotatedTypeFactory
public NullnessNoInitAnnotatedTypeFactory(BaseTypeChecker checker)
Creates a NullnessAnnotatedTypeFactory.- Parameters:
checker
- the associatedNullnessNoInitSubchecker
-
-
Method Detail
-
getChecker
public NullnessNoInitSubchecker getChecker()
Description copied from class:AnnotatedTypeFactory
Returns the checker associated with this factory.- Overrides:
getChecker
in classAnnotatedTypeFactory
- Returns:
- the checker associated with this factory
-
createSupportedTypeQualifiers
protected java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> createSupportedTypeQualifiers()
Description copied from class:AnnotatedTypeFactory
Returns 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 otherElementType
values) are automatically considered as supported annotations.To support a different set of annotations than those in the qual subdirectory, or that have other
ElementType
values, 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:@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:
createSupportedTypeQualifiers
in 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
protected void replacePolyQualifier(AnnotatedTypeMirror lhsType, com.sun.source.tree.Tree context)
For types of left-hand side of an assignment, this method replacesPolyNull
withNullable
(or withNonNull
if 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
-
createFlowAnalysis
protected NullnessNoInitAnalysis createFlowAnalysis()
Description copied from class:GenericAnnotatedTypeFactory
Returns 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:
createFlowAnalysis
in classGenericAnnotatedTypeFactory<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer,NullnessNoInitAnalysis>
- Returns:
- the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis
-
createFlowTransferFunction
public NullnessNoInitTransfer createFlowTransferFunction(CFAbstractAnalysis<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer> analysis)
Description copied from class:GenericAnnotatedTypeFactory
Returns 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:
createFlowTransferFunction
in classGenericAnnotatedTypeFactory<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer,NullnessNoInitAnalysis>
- Parameters:
analysis
- a dataflow analysis- Returns:
- a new transfer function
-
createAnnotatedTypeFormatter
protected AnnotatedTypeFormatter createAnnotatedTypeFormatter()
Returns an AnnotatedTypeFormatter that does not print the qualifiers on null literals.- Overrides:
createAnnotatedTypeFormatter
in classAnnotatedTypeFactory
- Returns:
- an AnnotatedTypeFormatter that does not print the qualifiers on null literals
-
methodFromUse
public AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(com.sun.source.tree.MethodInvocationTree tree)
Description copied from class:AnnotatedTypeFactory
Determines the type of the invoked method based on the passed method invocation tree.The returned method type has all type variables resolved, whether based on receiver type, passed type parameters if any, and method invocation parameter.
Subclasses may override this method to customize inference of types or qualifiers based on method invocation parameters.
As an implementation detail, this method depends on
AnnotatedTypes.asMemberOf(Types, AnnotatedTypeFactory, AnnotatedTypeMirror, Element)
, and customization based on receiver type should be in accordance to its specification.The return type is a pair of the type of the invoked method and the (inferred) type arguments. Note that neither the explicitly passed nor the inferred type arguments are guaranteed to be subtypes of the corresponding upper bounds. See method
BaseTypeVisitor.checkTypeArguments(com.sun.source.tree.Tree, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeParameterBounds>, java.util.List<? extends org.checkerframework.framework.type.AnnotatedTypeMirror>, java.util.List<? extends com.sun.source.tree.Tree>, java.lang.CharSequence, java.util.List<?>)
for the checks of type argument well-formedness.Note that "this" and "super" constructor invocations are also handled by this method (explicit or implicit ones, at the beginning of a constructor). Method
AnnotatedTypeFactory.constructorFromUse(NewClassTree)
is only used for a constructor invocation in a "new" expression.- Overrides:
methodFromUse
in classGenericAnnotatedTypeFactory<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer,NullnessNoInitAnalysis>
- Parameters:
tree
- the method invocation tree- Returns:
- the method type being invoked with tree and the (inferred) type arguments
-
adaptGetClassReturnTypeToReceiver
public void adaptGetClassReturnTypeToReceiver(AnnotatedTypeMirror.AnnotatedExecutableType getClassType, AnnotatedTypeMirror receiverType, com.sun.source.tree.ExpressionTree tree)
Description copied from class:AnnotatedTypeFactory
Java 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:
adaptGetClassReturnTypeToReceiver
in 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
public AnnotatedTypeMirror getMethodReturnType(com.sun.source.tree.MethodTree m, com.sun.source.tree.ReturnTree r)
Description copied from class:AnnotatedTypeFactory
Returns the return type of the methodm
at 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:
getMethodReturnType
in classAnnotatedTypeFactory
- Parameters:
m
- tree of a method declarationr
- a return statement within methodm
- Returns:
- the return type of the method
m
at the return statementr
-
isNotFullyInitializedReceiver
public boolean isNotFullyInitializedReceiver(com.sun.source.tree.MethodTree methodDeclTree)
Description copied from class:GenericAnnotatedTypeFactory
Returns true if the receiver of a method or constructor might not be fully initialized.- Overrides:
isNotFullyInitializedReceiver
in classGenericAnnotatedTypeFactory<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer,NullnessNoInitAnalysis>
- Parameters:
methodDeclTree
- the declaration of the method or constructor- Returns:
- true if the receiver of a method or constructor might not be fully initialized
-
getAnnotatedTypeBefore
public AnnotatedTypeMirror getAnnotatedTypeBefore(JavaExpression expr, com.sun.source.tree.ExpressionTree tree)
Description copied from class:GenericAnnotatedTypeFactory
Returns the type of a JavaExpressionexpr
if it were evaluated before a treetree
.This is used by
BaseTypeVisitor.visitMethodInvocation(MethodInvocationTree, Void)
to check the preconditions of method calls.- Overrides:
getAnnotatedTypeBefore
in classGenericAnnotatedTypeFactory<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer,NullnessNoInitAnalysis>
- Parameters:
expr
- the expression to typetree
- a tree- Returns:
- the type of
expr
if it were evaluated before treetree
-
createDefaultForTypeAnnotator
protected DefaultForTypeAnnotator createDefaultForTypeAnnotator()
Description copied from class:GenericAnnotatedTypeFactory
Creates anDefaultForTypeAnnotator
.- Overrides:
createDefaultForTypeAnnotator
in classGenericAnnotatedTypeFactory<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer,NullnessNoInitAnalysis>
- Returns:
- a new
DefaultForTypeAnnotator
-
addAnnotationsFromDefaultForType
protected void addAnnotationsFromDefaultForType(@Nullable javax.lang.model.element.Element element, AnnotatedTypeMirror type)
Description copied from class:GenericAnnotatedTypeFactory
Adds default qualifiers based on the underlying type oftype
totype
. Ifelement
is 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
DefaultQualifierForUseTypeAnnotator
andDefaultForTypeAnnotator
.)- Overrides:
addAnnotationsFromDefaultForType
in classGenericAnnotatedTypeFactory<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer,NullnessNoInitAnalysis>
- Parameters:
element
- possibly null element whose type istype
type
- the type to which defaults are added
-
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<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer,NullnessNoInitAnalysis>
- Returns:
- a tree annotator
-
getNullnessAnnotations
public java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> getNullnessAnnotations()
Returns the list of annotations of the non-null type system.- Returns:
- the list of annotations of the non-null type system
-
createQualifierHierarchy
protected QualifierHierarchy createQualifierHierarchy()
Description copied from class:AnnotatedTypeFactory
Returns theQualifierHierarchy
to 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:
createQualifierHierarchy
in classAnnotatedTypeFactory
- Returns:
- a QualifierHierarchy for this type system
-
containsNullnessAnnotation
protected boolean containsNullnessAnnotation(@Nullable java.util.List<? extends com.sun.source.tree.AnnotationTree> annoTrees, com.sun.source.tree.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
protected boolean containsNullnessAnnotation(java.util.List<? extends com.sun.source.tree.AnnotationTree> annoTrees)
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:
containsNullnessAnnotation(List, Tree)
-
isNullnessAnnotation
protected boolean isNullnessAnnotation(javax.lang.model.element.AnnotationMirror am)
Returns true if the given annotation is a nullness annotation such as@NonNull
,@Nullable
,@MonotonicNonNull
,@PolyNull
, or an alias thereof.- Parameters:
am
- an annotation- Returns:
- true if the given annotation is a nullness annotation
-
isNonNullOrAlias
protected boolean isNonNullOrAlias(javax.lang.model.element.AnnotationMirror am)
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
protected boolean isNullableOrAlias(javax.lang.model.element.AnnotationMirror am)
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
-
isPolyNullOrAlias
protected boolean isPolyNullOrAlias(javax.lang.model.element.AnnotationMirror am)
Returns true if the given annotation is@PolyNull
or an alias for it.- Parameters:
am
- an annotation- Returns:
- true if the given annotation is
@PolyNull
or an alias for it
-
getDefaultValueAnnotatedType
public AnnotatedTypeMirror getDefaultValueAnnotatedType(javax.lang.model.type.TypeMirror typeMirror)
Description copied from class:GenericAnnotatedTypeFactory
Return the type of the default value of the given type. The default value is 0, false, or null.- Overrides:
getDefaultValueAnnotatedType
in classGenericAnnotatedTypeFactory<NullnessNoInitValue,NullnessNoInitStore,NullnessNoInitTransfer,NullnessNoInitAnalysis>
- Parameters:
typeMirror
- a type- Returns:
- the annotated type of
type
's default value
-
isImmutable
public boolean isImmutable(javax.lang.model.type.TypeMirror type)
A non-null reference to an object stays non-null under mutation.- Overrides:
isImmutable
in classAnnotatedTypeFactory
- Parameters:
type
- type to test- Returns:
- true if the type is immutable
-
isMapGet
public boolean isMapGet(Node node)
Returns true ifnode
is an invocation of Map.get.- Parameters:
node
- a CFG node- Returns:
- true if
node
is an invocation of Map.get
-
-