public abstract class InitializationAnnotatedTypeFactory<Value extends CFAbstractValue<Value>,Store extends InitializationStore<Value,Store>,Transfer extends InitializationTransfer<Value,Transfer,Store>,Flow extends CFAbstractAnalysis<Value,Store,Transfer>> extends GenericAnnotatedTypeFactory<Value,Store,Transfer,Flow>
NullnessChecker
.Modifier and Type | Class and Description |
---|---|
protected class |
InitializationAnnotatedTypeFactory.CommitmentTreeAnnotator |
protected class |
InitializationAnnotatedTypeFactory.CommitmentTypeAnnotator |
protected class |
InitializationAnnotatedTypeFactory.InitializationQualifierHierarchy
The
QualifierHierarchy for the initialization type system. |
GenericAnnotatedTypeFactory.ScanState
AnnotatedTypeFactory.ParameterizedExecutableType
Modifier and Type | Field and Description |
---|---|
protected AnnotationMirror |
FBCBOTTOM
|
protected Set<String> |
initAnnoNames
String representation of all initialization annotations.
|
protected Set<Class<? extends Annotation>> |
initAnnos
Cache for the initialization annotations.
|
protected AnnotationMirror |
INITIALIZED
|
protected AnnotationMirror |
NOT_ONLY_INITIALIZED
NotOnlyInitialized or null. |
protected AnnotationMirror |
UNDER_INITALIZATION
UnderInitialization or null. |
protected AnnotationMirror |
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
Modifier | Constructor and Description |
---|---|
protected |
InitializationAnnotatedTypeFactory(BaseTypeChecker checker)
Create a new InitializationAnnotatedTypeFactory.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
areAllFieldsInitializedOnly(ClassTree classTree)
Are all fields initialized-only?
|
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 |
createUnderInitializationAnnotation(Class<?> typeFrame)
Creates a
UnderInitialization annotation with the given type frame. |
AnnotationMirror |
createUnderInitializationAnnotation(TypeMirror typeFrame)
Creates a
UnderInitialization annotation with the given type as its type frame
argument. |
AnnotationMirror |
createUnknownInitializationAnnotation(Class<?> typeFrame)
Creates a
UnknownInitialization annotation with a given type frame. |
AnnotationMirror |
createUnknownInitializationAnnotation(TypeMirror typeFrame)
Creates an
UnknownInitialization annotation with a given type frame. |
AnnotatedTypeMirror |
getAnnotatedTypeLhs(Tree lhsTree)
Returns the type of a left-hand side of an assignment.
|
abstract AnnotationMirror |
getFieldInvariantAnnotation()
Returns the annotation that makes up the invariant of this commitment type system, such as
@NonNull . |
Set<Class<? extends Annotation>> |
getInitializationAnnotations() |
List<VariableTree> |
getInitializedInvariantFields(Store store,
TreePath path)
Returns the (non-static) fields that have the invariant annotation and are initialized in a
given store.
|
Set<Class<? extends Annotation>> |
getInvalidConstructorReturnTypeAnnotations()
Returns the list of annotations that is forbidden for the constructor return type.
|
AnnotatedTypeMirror.AnnotatedDeclaredType |
getSelfType(Tree tree)
Returns the type of
this at the location of tree . |
TypeMirror |
getTypeFrameFromAnnotation(AnnotationMirror annotation)
Returns the type frame (that is, the argument) of a given initialization annotation.
|
protected AnnotationMirror |
getUnderInitializationAnnotationOfSuperType(TypeMirror type)
Returns an
UnderInitialization annotation that has the superclass of type as
type frame. |
List<VariableTree> |
getUninitializedInvariantFields(Store 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 abstract boolean |
hasFieldInvariantAnnotation(AnnotatedTypeMirror type,
VariableElement fieldElement)
Returns whether or not
type has the invariant annotation. |
protected boolean |
hasFieldInvariantAnnotation(VariableTree field)
Returns whether or not
field has the invariant annotation. |
boolean |
isFbcBottom(AnnotatedTypeMirror anno)
Does
anno have the bottom annotation? |
boolean |
isFbcBottom(AnnotationMirror anno)
Is
anno the bottom annotation? |
protected boolean |
isInitializationAnnotation(AnnotationMirror anno)
Is the annotation
anno an initialization qualifier? |
boolean |
isInitialized(AnnotatedTypeMirror anno)
Does
anno have the annotation Initialized ? |
boolean |
isInitialized(AnnotationMirror anno)
Is
anno the Initialized annotation? |
boolean |
isInitializedForFrame(AnnotatedTypeMirror type,
TypeMirror frame)
Return true if the type is initialized with respect to the given frame -- that is, all of the
fields of the frame are initialized.
|
boolean |
isUnderInitialization(AnnotatedTypeMirror anno)
Does
anno have the annotation UnderInitialization (with any type frame)? |
boolean |
isUnderInitialization(AnnotationMirror anno)
Is
anno the UnderInitialization annotation (with any type frame)? |
boolean |
isUnknownInitialization(AnnotatedTypeMirror anno)
Does
anno have the annotation UnknownInitialization (with any type frame)? |
boolean |
isUnknownInitialization(AnnotationMirror anno)
Is
anno the UnknownInitialization annotation (with any type frame)? |
void |
postAsMemberOf(AnnotatedTypeMirror type,
AnnotatedTypeMirror owner,
Element element)
A callback method for the AnnotatedTypeFactory subtypes to customize
AnnotatedTypes.asMemberOf().
|
protected void |
setSelfTypeInInitializationCode(Tree tree,
AnnotatedTypeMirror.AnnotatedDeclaredType selfType,
TreePath path)
Side-effects argument
selfType to make it @Initialized or @UnderInitialization,
depending on whether all fields have been set. |
addAnnotationsFromDefaultForType, addCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotations, addDefaultAnnotations, addUncheckedStandardDefaults, analyze, applyInferredAnnotations, applyQualifierParameterDefaults, applyQualifierParameterDefaults, checkAndPerformFlowAnalysis, checkForDefaultQualifierInHierarchy, constructorFromUse, constructorFromUsePreSubstitution, createAndInitQualifierDefaults, createCFGVisualizer, createDefaultForTypeAnnotator, createDefaultForUseTypeAnnotator, createDependentTypesHelper, createFlowAnalysis, createFlowTransferFunction, createQualifierDefaults, createQualifierPolymorphism, fromNewClass, getAnnotatedTypeLhsNoTypeVarDefault, getAnnotatedTypeRhsUnaryAssign, getAnnotatedTypeVarargsArray, getAnnotationFromJavaExpressionString, getAnnotationFromReceiver, getAnnotationMirrorFromJavaExpressionString, getCFGVisualizer, getDependentTypesHelper, getEmptyStore, getExceptionalExitStore, getFinalLocalValues, getFirstNodeOfKindForTree, getInferredValueFor, getMethodReturnType, getMethodReturnType, getNodesForTree, getQualifierPolymorphism, getReceiverAndOffsetFromJavaExpressionString, getReceiverFromJavaExpressionString, getRegularExitStore, getResultingTypeOfConstructorMemberReference, getReturnStatementStores, getShouldDefaultTypeVarLocals, getSortedQualifierNames, getStoreAfter, getStoreAfter, getStoreAfter, getStoreBefore, getStoreBefore, getStoreBefore, getSupportedMonotonicTypeQualifiers, getTypeFactoryOfSubchecker, handleCFGViz, methodFromUse, methodFromUsePreSubstitution, performFlowAnalysis, postAnalyze, postDirectSuperTypes, postInit, preProcessClassTree, setRoot, typeVariablesFromUse
adaptGetClassReturnTypeToReceiver, addAliasedAnnotation, addAliasedAnnotation, addAliasedAnnotation, addAliasedAnnotation, addAliasedDeclAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, applyUnboxing, areSameByClass, binaryTreeArgTypes, canonicalAnnotation, checkInvalidOptionsInferSignatures, containsSameByClass, createAnnotatedTypeFormatter, createAnnotationClassLoader, createAnnotationFormatter, createQualifierHierarchy, createQualifierHierarchyWithMultiGraphFactory, createQualifierUpperBounds, createSupportedTypeQualifiers, 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 UNKNOWN_INITIALIZATION
protected final AnnotationMirror INITIALIZED
protected final AnnotationMirror UNDER_INITALIZATION
UnderInitialization
or null.protected final AnnotationMirror NOT_ONLY_INITIALIZED
NotOnlyInitialized
or null.protected final AnnotationMirror FBCBOTTOM
protected final Set<Class<? extends Annotation>> initAnnos
protected final Set<String> initAnnoNames
UnknownInitialization
UnderInitialization
Initialized
FBCBottom
This is used to quickly check of an AnnotationMirror is one of the initialization annotations without having to repeatedly convert them to strings.
protected InitializationAnnotatedTypeFactory(BaseTypeChecker checker)
checker
- the checker to which the new type factory belongspublic Set<Class<? extends Annotation>> getInitializationAnnotations()
protected boolean isInitializationAnnotation(AnnotationMirror anno)
anno
an initialization qualifier?anno
- the annotation to checkpublic Set<Class<? extends Annotation>> getInvalidConstructorReturnTypeAnnotations()
public abstract AnnotationMirror getFieldInvariantAnnotation()
@NonNull
.protected final boolean hasFieldInvariantAnnotation(VariableTree field)
field
has the invariant annotation.
This method is a convenience method for hasFieldInvariantAnnotation(AnnotatedTypeMirror, VariableElement)
.
If the field
is a type variable, this method returns true if any possible
instantiation of the type parameter could have the invariant annotation. See hasFieldInvariantAnnotation(VariableTree)
for an example.
field
- field that might have invariant annotationprotected abstract 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 hasFieldInvariantAnnotation(VariableTree)
for an example.
type
- of field that might have invariant annotationfieldElement
- the field element, which can be used to check annotations on the
declarationpublic AnnotationMirror createUnderInitializationAnnotation(TypeMirror typeFrame)
UnderInitialization
annotation with the given type as its type frame
argument.typeFrame
- the type down to which some value has been initializedUnderInitialization
annotation with the given argumentpublic AnnotationMirror createUnderInitializationAnnotation(Class<?> typeFrame)
UnderInitialization
annotation with the given type frame.typeFrame
- the type down to which some value has been initializedUnderInitialization
annotation with the given argumentpublic AnnotationMirror createUnknownInitializationAnnotation(Class<?> typeFrame)
UnknownInitialization
annotation with a given type frame.typeFrame
- the type down to which some value has been initializedUnknownInitialization
annotation with the given argumentpublic AnnotationMirror createUnknownInitializationAnnotation(TypeMirror typeFrame)
UnknownInitialization
annotation with a given type frame.typeFrame
- the type down to which some value has been initializedUnknownInitialization
annotation with the given argumentpublic TypeMirror getTypeFrameFromAnnotation(AnnotationMirror annotation)
annotation
- a UnderInitialization
or UnknownInitialization
annotationpublic boolean isUnderInitialization(AnnotationMirror anno)
anno
the UnderInitialization
annotation (with any type frame)?anno
- the annotation to checkanno
is UnderInitialization
public boolean isUnknownInitialization(AnnotationMirror anno)
anno
the UnknownInitialization
annotation (with any type frame)?anno
- the annotation to checkanno
is UnknownInitialization
public boolean isFbcBottom(AnnotationMirror anno)
anno
the bottom annotation?anno
- the annotation to checkanno
is FBCBottom
public boolean isInitialized(AnnotationMirror anno)
anno
the Initialized
annotation?anno
- the annotation to checkanno
is Initialized
public boolean isUnderInitialization(AnnotatedTypeMirror anno)
anno
have the annotation UnderInitialization
(with any type frame)?anno
- the annotation to checkanno
has UnderInitialization
public boolean isUnknownInitialization(AnnotatedTypeMirror anno)
anno
have the annotation UnknownInitialization
(with any type frame)?anno
- the annotation to checkanno
has UnknownInitialization
public boolean isFbcBottom(AnnotatedTypeMirror anno)
anno
have the bottom annotation?anno
- the annotation to checkanno
has FBCBottom
public boolean isInitialized(AnnotatedTypeMirror anno)
anno
have the annotation Initialized
?anno
- the annotation to checkanno
has Initialized
protected boolean areAllFieldsInitializedOnly(ClassTree classTree)
classTree
- the class to querypublic void postAsMemberOf(AnnotatedTypeMirror type, AnnotatedTypeMirror owner, Element element)
In most cases, subclasses want to call this method first because it may clear all annotations and use the hierarchy's root annotations.
postAsMemberOf
in class GenericAnnotatedTypeFactory<Value extends CFAbstractValue<Value>,Store extends InitializationStore<Value,Store>,Transfer extends InitializationTransfer<Value,Transfer,Store>,Flow extends CFAbstractAnalysis<Value,Store,Transfer>>
type
- the annotated type of the elementowner
- the annotated type of the receiver of the accessing treeelement
- the element of the field or methodpublic AnnotatedTypeMirror getAnnotatedTypeLhs(Tree lhsTree)
GenericAnnotatedTypeFactory
The default implementation returns the type without considering dataflow type refinement. Subclass can override this method and add additional logic for computing the type of a LHS.
getAnnotatedTypeLhs
in class GenericAnnotatedTypeFactory<Value extends CFAbstractValue<Value>,Store extends InitializationStore<Value,Store>,Transfer extends InitializationTransfer<Value,Transfer,Store>,Flow extends CFAbstractAnalysis<Value,Store,Transfer>>
lhsTree
- left-hand side of an assignmentlhsTree
public AnnotatedTypeMirror.AnnotatedDeclaredType getSelfType(Tree tree)
AnnotatedTypeFactory
this
at the location of tree
. If tree
is in a
location where this
has no meaning, such as the body of a static method, then null
is returned.
The parameter is an arbitrary tree and does not have to mention "this", neither explicitly nor implicitly. This method can be overridden for type-system specific behavior.
getSelfType
in class AnnotatedTypeFactory
tree
- location used to decide the type of this
this
at the location of tree
protected void setSelfTypeInInitializationCode(Tree tree, AnnotatedTypeMirror.AnnotatedDeclaredType selfType, TreePath path)
selfType
to make it @Initialized or @UnderInitialization,
depending on whether all fields have been set.protected AnnotationMirror getUnderInitializationAnnotationOfSuperType(TypeMirror type)
UnderInitialization
annotation that has the superclass of type
as
type frame.type
- a typeUnderInitialization
for the supertype of type
public List<VariableTree> getUninitializedInvariantFields(Store store, TreePath path, boolean isStatic, List<? extends AnnotationMirror> receiverAnnotations)
public List<VariableTree> getInitializedInvariantFields(Store store, TreePath path)
public boolean isInitializedForFrame(AnnotatedTypeMirror type, TypeMirror frame)
type
- the type whose initialization type qualifiers to checkframe
- a class in type
's class hierarchyprotected 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 GenericAnnotatedTypeFactory<Value extends CFAbstractValue<Value>,Store extends InitializationStore<Value,Store>,Transfer extends InitializationTransfer<Value,Transfer,Store>,Flow extends CFAbstractAnalysis<Value,Store,Transfer>>
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 GenericAnnotatedTypeFactory<Value extends CFAbstractValue<Value>,Store extends InitializationStore<Value,Store>,Transfer extends InitializationTransfer<Value,Transfer,Store>,Flow extends CFAbstractAnalysis<Value,Store,Transfer>>