public class NullnessAnnotatedTypeFactory extends InitializationAnnotatedTypeFactory<NullnessValue,NullnessStore,NullnessTransfer,NullnessAnalysis>
Modifier and Type | Class and Description |
---|---|
protected static class |
NullnessAnnotatedTypeFactory.NullnessPropagationTreeAnnotator
Nullness doesn't call propagation on binary and unary because the result is
always @Initialized (the default qualifier).
|
protected class |
NullnessAnnotatedTypeFactory.NullnessQualifierHierarchy
NullnessQualifierHierarchy
|
protected class |
NullnessAnnotatedTypeFactory.NullnessTreeAnnotator |
protected class |
NullnessAnnotatedTypeFactory.NullnessTypeAnnotator |
InitializationAnnotatedTypeFactory.CommitmentTreeAnnotator, InitializationAnnotatedTypeFactory.CommitmentTypeAnnotator, InitializationAnnotatedTypeFactory.InitializationQualifierHierarchy
GenericAnnotatedTypeFactory.ScanState
AnnotatedTypeFactory.ParameterizedExecutableType
Modifier and Type | Field and Description |
---|---|
protected ExecutableElement |
classGetCanonicalName
The Class.getCanonicalName() method.
|
protected CollectionToArrayHeuristics |
collectionToArrayHeuristics
Determines the nullness type of calls to
Collection.toArray() . |
protected AnnotationMirror |
MONOTONIC_NONNULL
The @
MonotonicNonNull annotation. |
protected AnnotationMirror |
NONNULL
The @
NonNull annotation. |
protected AnnotationMirror |
NULLABLE
The @
Nullable annotation. |
protected Set<Class<? extends Annotation>> |
nullnessAnnos
Cache for the nullness annotations.
|
protected AnnotationMirror |
POLYNULL
The @
PolyNull annotation. |
protected SystemGetPropertyHandler |
systemGetPropertyHandler
Handles invocations of
System.getProperty(String) . |
FBCBOTTOM, initAnnoNames, initAnnos, INITIALIZED, NOT_ONLY_INITIALIZED, UNDER_INITALIZATION, UNKNOWN_INITIALIZATION
analysis, cfgVisualizer, defaults, dependentTypesHelper, emptyStore, exceptionalExitStores, flowByDefault, flowResult, flowResultAnalysisCaches, initializationStaticStore, initializationStore, methodInvocationStores, poly, regularExitStores, returnStatementStores, scannedClasses, transfer, treeAnnotator, typeAnnotator
artificialTreeToEnclosingElementMap, checker, elements, fromExpressionTreeCache, fromMemberTreeCache, fromTypeTreeCache, ignoreUninferredTypeArguments, loader, objectGetClass, processingEnv, qualHierarchy, qualifierUpperBounds, reflectionResolver, root, shouldCache, stubTypes, trees, typeArgumentInference, typeFormatter, typeHierarchy, types, typeVarSubstitutor, uid, visitorState
Constructor and Description |
---|
NullnessAnnotatedTypeFactory(BaseTypeChecker checker)
Creates a NullnessAnnotatedTypeFactory.
|
Modifier and Type | Method and Description |
---|---|
void |
adaptGetClassReturnTypeToReceiver(AnnotatedTypeMirror.AnnotatedExecutableType getClassType,
AnnotatedTypeMirror receiverType)
Java special-cases the return type of
getClass() . |
protected void |
addAnnotationsFromDefaultForType(@Nullable Element element,
AnnotatedTypeMirror type)
Adds default qualifiers bases on the underlying type of
type to type . |
protected AnnotatedTypeFormatter |
createAnnotatedTypeFormatter()
Creates the AnnotatedTypeFormatter used by this type factory and all AnnotatedTypeMirrors it
creates.
|
protected DefaultForTypeAnnotator |
createDefaultForTypeAnnotator()
Creates an
DefaultForTypeAnnotator . |
protected NullnessAnalysis |
createFlowAnalysis(List<Pair<VariableElement,NullnessValue>> fieldValues)
Returns the appropriate flow analysis class that is used for the
org.checkerframework.dataflow analysis.
|
NullnessTransfer |
createFlowTransferFunction(CFAbstractAnalysis<NullnessValue,NullnessStore,NullnessTransfer> analysis)
Returns the appropriate transfer function that is used for the org.checkerframework.dataflow
analysis.
|
QualifierHierarchy |
createQualifierHierarchy()
Returns the
QualifierHierarchy to be used by this checker. |
protected Set<Class<? extends Annotation>> |
createSupportedTypeQualifiers()
Returns a mutable set of annotation classes that are supported by a checker.
|
protected TreeAnnotator |
createTreeAnnotator()
Returns a
TreeAnnotator that adds annotations to a type based on the contents of a
tree. |
protected TypeAnnotator |
createTypeAnnotator()
Returns a
DefaultForTypeAnnotator that adds annotations to a type based on the
content of the type itself. |
AnnotationMirror |
getFieldInvariantAnnotation()
Returns the annotation that makes up the invariant of this commitment type system, such as
@NonNull . |
Set<Class<? extends Annotation>> |
getInvalidConstructorReturnTypeAnnotations()
Returns the list of annotations that is forbidden for the constructor return type.
|
AnnotatedTypeMirror |
getMethodReturnType(MethodTree m,
ReturnTree r)
Returns the return type of the method
m at the return statement r . |
Set<Class<? extends Annotation>> |
getNullnessAnnotations()
Returns the list of annotations of the non-null type system.
|
List<VariableTree> |
getUninitializedInvariantFields(NullnessStore store,
TreePath path,
boolean isStatic,
List<? extends AnnotationMirror> receiverAnnotations)
Returns the (non-static) fields that have the invariant annotation and are not yet
initialized in a given store.
|
protected boolean |
hasFieldInvariantAnnotation(AnnotatedTypeMirror type,
VariableElement fieldElement)
Returns whether or not
type has the invariant annotation. |
AnnotatedTypeFactory.ParameterizedExecutableType |
methodFromUse(MethodInvocationTree tree)
Determines the type of the invoked method based on the passed method invocation tree.
|
protected void |
replacePolyQualifier(AnnotatedTypeMirror lhsType,
Tree context)
|
areAllFieldsInitializedOnly, createUnderInitializationAnnotation, createUnderInitializationAnnotation, createUnknownInitializationAnnotation, createUnknownInitializationAnnotation, getAnnotatedTypeLhs, getInitializationAnnotations, getInitializedInvariantFields, getSelfType, getTypeFrameFromAnnotation, getUnderInitializationAnnotationOfSuperType, hasFieldInvariantAnnotation, isFbcBottom, isFbcBottom, isInitializationAnnotation, isInitialized, isInitialized, isInitializedForFrame, isUnderInitialization, isUnderInitialization, isUnknownInitialization, isUnknownInitialization, postAsMemberOf, setSelfTypeInInitializationCode
addCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotations, addDefaultAnnotations, addUncheckedStandardDefaults, analyze, applyInferredAnnotations, applyQualifierParameterDefaults, applyQualifierParameterDefaults, checkAndPerformFlowAnalysis, checkForDefaultQualifierInHierarchy, constructorFromUse, constructorFromUsePreSubstitution, createAndInitQualifierDefaults, createCFGVisualizer, createDefaultForUseTypeAnnotator, createDependentTypesHelper, createQualifierDefaults, createQualifierPolymorphism, fromNewClass, getAnnotatedTypeLhsNoTypeVarDefault, getAnnotatedTypeRhsUnaryAssign, getAnnotatedTypeVarargsArray, getAnnotationFromJavaExpressionString, getAnnotationFromReceiver, getAnnotationMirrorFromJavaExpressionString, getCFGVisualizer, getDependentTypesHelper, getEmptyStore, getExceptionalExitStore, getFinalLocalValues, getFirstNodeOfKindForTree, getInferredValueFor, getMethodReturnType, getNodesForTree, getQualifierPolymorphism, getReceiverAndOffsetFromJavaExpressionString, getReceiverFromJavaExpressionString, getRegularExitStore, getResultingTypeOfConstructorMemberReference, getReturnStatementStores, getShouldDefaultTypeVarLocals, getSortedQualifierNames, getStoreAfter, getStoreAfter, getStoreAfter, getStoreBefore, getStoreBefore, getStoreBefore, getSupportedMonotonicTypeQualifiers, getTypeFactoryOfSubchecker, handleCFGViz, methodFromUsePreSubstitution, performFlowAnalysis, postAnalyze, postDirectSuperTypes, postInit, preProcessClassTree, setRoot, typeVariablesFromUse
addAliasedAnnotation, addAliasedAnnotation, addAliasedAnnotation, addAliasedAnnotation, addAliasedDeclAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, applyUnboxing, areSameByClass, binaryTreeArgTypes, canonicalAnnotation, checkInvalidOptionsInferSignatures, containsSameByClass, createAnnotationClassLoader, createAnnotationFormatter, createQualifierHierarchyWithMultiGraphFactory, createQualifierUpperBounds, createTypeArgumentInference, createTypeHierarchy, createTypeVariableSubstitutor, declarationFromElement, fromElement, fromElement, fromElement, getAnnotatedNullType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFormatter, getAnnotatedTypeFromTypeTree, getAnnotationByClass, getAnnotationFormatter, getAnnotationMirror, getAnnotationWithMetaAnnotation, getBoxedType, getBundledTypeQualifiers, getCacheSize, getContext, getCurrentClassTree, getCurrentClassType, getCurrentMethodReceiver, getDeclAnnotation, getDeclAnnotationNoAliases, getDeclAnnotations, getDeclAnnotationWithMetaAnnotation, getDefaultTypeDeclarationBounds, getDummyAssignedTo, getElementUtils, getEnclosingClassOrMethod, getEnclosingElementForArtificialTree, getEnclosingType, getExpressionAndOffset, getFieldInvariantAnnotationTree, getFieldInvariantDeclarationAnnotations, getFieldInvariants, getFnInterfaceFromTree, getFunctionTypeFromTree, getFunctionTypeFromTree, getImplicitReceiverType, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getQualifierParameterHierarchies, getQualifierParameterHierarchies, getQualifierUpperBounds, getReceiverType, getStringType, getSupportedTypeQualifierNames, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeDeclarationBounds, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, getUnboxedType, getUninferredWildcardType, getVisitorState, getWholeProgramInference, getWidenedAnnotations, getWidenedType, hasExplicitNoQualifierParameterInHierarchy, hasExplicitQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, initializeReflectionResolution, isFromByteCode, isFromStubFile, isSupportedQualifier, isSupportedQualifier, isSupportedQualifier, isWithinConstructor, mergeStubsIntoType, methodFromUse, negateConstant, parseStubFiles, postProcessClassTree, postTypeVarSubstitution, setEnclosingElementForArtificialTree, shouldWarnIfStubRedundantWithBytecode, toAnnotatedType, toString, type, widenToUpperBound
protected final AnnotationMirror NONNULL
NonNull
annotation.protected final AnnotationMirror NULLABLE
Nullable
annotation.protected final AnnotationMirror POLYNULL
PolyNull
annotation.protected final AnnotationMirror MONOTONIC_NONNULL
MonotonicNonNull
annotation.protected final SystemGetPropertyHandler systemGetPropertyHandler
System.getProperty(String)
.protected final CollectionToArrayHeuristics collectionToArrayHeuristics
Collection.toArray()
.protected final ExecutableElement classGetCanonicalName
protected final Set<Class<? extends Annotation>> nullnessAnnos
public NullnessAnnotatedTypeFactory(BaseTypeChecker checker)
checker
- the associated NullnessChecker
protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers()
AnnotatedTypeFactory
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 of ElementType.TYPE_PARAMETER
, but no other ElementType
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:
This is the default behavior. Simply place those annotations within the qual directory.
Place those annotations within the qual directory, and override AnnotatedTypeFactory.createSupportedTypeQualifiers()
by calling AnnotatedTypeFactory.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);
}
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));
}
The set of qualifiers returned by AnnotatedTypeFactory.createSupportedTypeQualifiers()
must be a
fresh, mutable set. The methods AnnotatedTypeFactory.getBundledTypeQualifiers(Class...)
must return
a fresh, mutable set
createSupportedTypeQualifiers
in class AnnotatedTypeFactory
protected void replacePolyQualifier(AnnotatedTypeMirror lhsType, Tree context)
PolyNull
with
Nullable
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; }
lhsType
- type to replace whose polymorphic qualifier will be replacedcontext
- tree used to get dataflow valuepublic List<VariableTree> getUninitializedInvariantFields(NullnessStore store, TreePath path, boolean isStatic, List<? extends AnnotationMirror> receiverAnnotations)
InitializationAnnotatedTypeFactory
protected NullnessAnalysis createFlowAnalysis(List<Pair<VariableElement,NullnessValue>> fieldValues)
GenericAnnotatedTypeFactory
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.
createFlowAnalysis
in class GenericAnnotatedTypeFactory<NullnessValue,NullnessStore,NullnessTransfer,NullnessAnalysis>
public NullnessTransfer createFlowTransferFunction(CFAbstractAnalysis<NullnessValue,NullnessStore,NullnessTransfer> analysis)
GenericAnnotatedTypeFactory
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.
protected AnnotatedTypeFormatter createAnnotatedTypeFormatter()
AnnotatedTypeFactory
createAnnotatedTypeFormatter
in class AnnotatedTypeFactory
public AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(MethodInvocationTree tree)
AnnotatedTypeFactory
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>, javax.lang.model.element.Name, 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.
methodFromUse
in class GenericAnnotatedTypeFactory<NullnessValue,NullnessStore,NullnessTransfer,NullnessAnalysis>
tree
- the method invocation treepublic void adaptGetClassReturnTypeToReceiver(AnnotatedTypeMirror.AnnotatedExecutableType getClassType, AnnotatedTypeMirror receiverType)
AnnotatedTypeFactory
getClass()
. Though
the method has a return type of Class<?>
, 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 type Class< ? extends erasure_of_x >
someInteger.getClass()
has the type Class< ? extends Integer >
adaptGetClassReturnTypeToReceiver
in class AnnotatedTypeFactory
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)public AnnotatedTypeMirror getMethodReturnType(MethodTree m, ReturnTree r)
AnnotatedTypeFactory
m
at the return statement r
.getMethodReturnType
in class GenericAnnotatedTypeFactory<NullnessValue,NullnessStore,NullnessTransfer,NullnessAnalysis>
protected DefaultForTypeAnnotator createDefaultForTypeAnnotator()
GenericAnnotatedTypeFactory
DefaultForTypeAnnotator
.createDefaultForTypeAnnotator
in class GenericAnnotatedTypeFactory<NullnessValue,NullnessStore,NullnessTransfer,NullnessAnalysis>
DefaultForTypeAnnotator
protected void addAnnotationsFromDefaultForType(@Nullable Element element, AnnotatedTypeMirror type)
GenericAnnotatedTypeFactory
type
to type
. If
element
is a local variable, then the defaults are not added.
(This uses both the DefaultQualifierForUseTypeAnnotator
and DefaultForTypeAnnotator
.)
addAnnotationsFromDefaultForType
in class GenericAnnotatedTypeFactory<NullnessValue,NullnessStore,NullnessTransfer,NullnessAnalysis>
element
- possibly null element whose type is type
type
- the type to which defaults are addedprotected TypeAnnotator createTypeAnnotator()
GenericAnnotatedTypeFactory
DefaultForTypeAnnotator
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.
createTypeAnnotator
in class InitializationAnnotatedTypeFactory<NullnessValue,NullnessStore,NullnessTransfer,NullnessAnalysis>
protected TreeAnnotator createTreeAnnotator()
GenericAnnotatedTypeFactory
TreeAnnotator
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 subtrees
LiteralTreeAnnotator
: Adds annotations based on QualifierForLiterals
meta-annotations
DependentTypesTreeAnnotator
: 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));
createTreeAnnotator
in class InitializationAnnotatedTypeFactory<NullnessValue,NullnessStore,NullnessTransfer,NullnessAnalysis>
public Set<Class<? extends Annotation>> getNullnessAnnotations()
public Set<Class<? extends Annotation>> getInvalidConstructorReturnTypeAnnotations()
InitializationAnnotatedTypeFactory
getInvalidConstructorReturnTypeAnnotations
in class InitializationAnnotatedTypeFactory<NullnessValue,NullnessStore,NullnessTransfer,NullnessAnalysis>
public AnnotationMirror getFieldInvariantAnnotation()
InitializationAnnotatedTypeFactory
@NonNull
.getFieldInvariantAnnotation
in class InitializationAnnotatedTypeFactory<NullnessValue,NullnessStore,NullnessTransfer,NullnessAnalysis>
protected boolean hasFieldInvariantAnnotation(AnnotatedTypeMirror type, VariableElement fieldElement)
type
has the invariant annotation.
If the type
is a type variable, this method returns true if any possible
instantiation of the type parameter could have the invariant annotation. See InitializationAnnotatedTypeFactory.hasFieldInvariantAnnotation(VariableTree)
for an example.
In other words, is the lower bound @NonNull?
hasFieldInvariantAnnotation
in class InitializationAnnotatedTypeFactory<NullnessValue,NullnessStore,NullnessTransfer,NullnessAnalysis>
type
- of field that might have invariant annotationfieldElement
- the field element, which can be used to check annotations on the
declarationpublic QualifierHierarchy createQualifierHierarchy()
AnnotatedTypeFactory
QualifierHierarchy
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 of NoElementQualifierHierarchy
.
Subclasses must override this method if their qualifiers have elements; the method must
return an implementation of QualifierHierarchy
, such as ElementQualifierHierarchy
.
createQualifierHierarchy
in class AnnotatedTypeFactory