public class ValueAnnotatedTypeFactory extends BaseAnnotatedTypeFactory
Modifier and Type | Class and Description |
---|---|
protected class |
ValueAnnotatedTypeFactory.ValueTreeAnnotator
The TreeAnnotator for this AnnotatedTypeFactory.
|
GenericAnnotatedTypeFactory.ScanState
AnnotatedTypeFactory.InheritedFromClassAnnotator
Modifier and Type | Field and Description |
---|---|
protected AnnotationMirror |
BOTTOMVAL
The bottom type for this hierarchy.
|
protected static Set<String> |
coveredClassStrings
The domain of the Constant Value Checker: the types for which it estimates possible values.
|
protected static int |
MAX_VALUES
The maximum number of values allowed in an annotation's array
|
AnnotationMirror |
POLY
The canonical @
PolyValue annotation. |
protected AnnotationMirror |
UNKNOWNVAL
The top type for this hierarchy.
|
analyses, cfgVisualizer, defaults, dependentTypesHelper, FLOW_BY_DEFAULT, flowResult, initializationStaticStore, initializationStore, methodInvocationStores, poly, regularExitStores, returnStatementStores, scannedClasses, treeAnnotator, typeAnnotator
checker, elements, fromTreeCache, ignoreUninferredTypeArguments, loader, processingEnv, qualHierarchy, reflectionResolver, root, shouldCache, trees, typeArgumentInference, typeFormatter, typeHierarchy, types, typeVarSubstitutor, uid, visitorState
Constructor and Description |
---|
ValueAnnotatedTypeFactory(BaseTypeChecker checker) |
Modifier and Type | Method and Description |
---|---|
AnnotationMirror |
aliasedAnnotation(AnnotationMirror anno)
Returns the canonical annotation for the passed annotation if it is an alias of a canonical
one in the framework.
|
AnnotationMirror |
convertArrayLenToArrayLenRange(AnnotationMirror arrayLenAnno)
Converts an
@ArrayLen annotation to an @ArrayLenRange annotation. |
AnnotationMirror |
convertIntRangeToIntVal(AnnotationMirror intRangeAnno)
Convert an
@IntRange annotation to an @IntVal annotation, or to UNKNOWNVAL if
the input is too wide to be represented as an @IntVal . |
AnnotationMirror |
convertIntValToIntRange(AnnotationMirror intValAnno)
Converts an
@IntVal annotation to an @IntRange annotation. |
AnnotationMirror |
createArrayLenAnnotation(List<Integer> values)
Returns a
ArrayLen annotation using the values. |
AnnotationMirror |
createArrayLenRangeAnnotation(int from,
int to)
Create an
@ArrayLenRange annotation from the two (inclusive) bounds. |
AnnotationMirror |
createArrayLenRangeAnnotation(Range range)
Create an
@ArrayLenRange annotation from the range. |
AnnotationMirror |
createBooleanAnnotation(List<Boolean> values)
Returns a
BoolVal annotation using the values. |
AnnotationMirror |
createCharAnnotation(List<Character> values)
Returns a
IntVal annotation using the values. |
AnnotationMirror |
createDoubleValAnnotation(List<Double> values)
Returns a
DoubleVal annotation using the values. |
CFTransfer |
createFlowTransferFunction(CFAbstractAnalysis<CFValue,CFStore,CFTransfer> analysis)
Returns the appropriate transfer function that is used for the org.checkerframework.dataflow
analysis.
|
AnnotationMirror |
createIntRangeAnnotation(Range range)
Create an
@IntRange or @IntVal annotation from the range. |
AnnotationMirror |
createIntValAnnotation(List<Long> values)
|
AnnotationMirror |
createNumberAnnotationMirror(List<Number> values) |
QualifierHierarchy |
createQualifierHierarchy(MultiGraphQualifierHierarchy.MultiGraphFactory factory)
Factory method to easily change what QualifierHierarchy is created.
|
AnnotationMirror |
createStringAnnotation(List<String> values)
Returns a
StringVal annotation using the values. |
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
ImplicitsTypeAnnotator
that adds annotations to a type based on the content of the type itself. |
static List<Integer> |
getArrayLength(AnnotationMirror arrayAnno)
Returns the set of possible array lengths as a sorted list with no duplicate values.
|
static List<Boolean> |
getBooleanValues(AnnotationMirror boolAnno)
Returns the set of possible values as a sorted list with no duplicate values.
|
static List<Character> |
getCharValues(AnnotationMirror intAnno)
Returns the set of possible values as a sorted list with no duplicate values.
|
Set<AnnotationMirror> |
getDeclAnnotations(Element elt)
Returns all of the actual annotation mirrors used to annotate this element (includes stub
files and declaration annotations from overridden methods).
|
static List<Double> |
getDoubleValues(AnnotationMirror doubleAnno)
Returns the set of possible values as a sorted list with no duplicate values.
|
protected Set<Class<? extends Annotation>> |
getFieldInvariantDeclarationAnnotations()
Returns the set of classes of field invariant annotations.
|
FieldInvariants |
getFieldInvariants(TypeElement element)
Returns the field invariants for the given class.
|
static List<Long> |
getIntValues(AnnotationMirror intAnno)
Returns the set of possible values as a sorted list with no duplicate values.
|
Integer |
getMaxLenValue(AnnotationMirror annotation)
Used to find the maximum length of an array.
|
Long |
getMinimumIntegralValue(AnnotatedTypeMirror atm)
Returns the smallest possible value that an integral annotation might take on.
|
int |
getMinLenFromString(String arrayExpression,
Tree tree,
TreePath currentPath)
Returns the minimum length of an array expression or 0 if the min length is unknown.
|
Integer |
getMinLenValue(AnnotatedTypeMirror atm) |
Integer |
getMinLenValue(AnnotationMirror annotation)
Used to find the minimum length of an array, which is useful for array bounds checking.
|
static Range |
getRange(AnnotationMirror rangeAnno)
Returns a
Range bounded by the values specified in the given @Range
annotation. |
static List<String> |
getStringValues(AnnotationMirror stringAnno)
Returns the set of possible values as a sorted list with no duplicate values.
|
boolean |
isIntRange(AnnotationMirror anm) |
boolean |
isIntRange(Set<AnnotationMirror> anmSet) |
Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> |
methodFromUse(ExpressionTree tree,
ExecutableElement methodElt,
AnnotatedTypeMirror receiverType)
Creates array length annotations for the result of the Enum.values() method, which is the
number of possible values of the enum.
|
createFlowAnalysis
addCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotations, addDefaultAnnotations, addTypeNameImplicit, addUncheckedCodeDefaults, addUncheckedStandardDefaults, analyze, analyze, applyInferredAnnotations, checkAndPerformFlowAnalysis, checkForDefaultQualifierInHierarchy, constructorFromUse, createCFGVisualizer, createDependentTypesHelper, createQualifierDefaults, createQualifierPolymorphism, fromNewClass, getAnnotatedTypeLhs, getAnnotatedTypeLhsNoTypeVarDefault, getAnnotationFromJavaExpressionString, getCFGVisualizer, getDependentTypesHelper, getEmptyStore, getFinalLocalValues, getInferredValueFor, getMethodReturnType, getMethodReturnType, getNodeForTree, getReceiverFromJavaExpressionString, getRegularExitStore, getResultingTypeOfConstructorMemberReference, getReturnStatementStores, getShouldDefaultTypeVarLocals, getSortedQualifierNames, getStoreAfter, getStoreBefore, getStoreBefore, getSupportedMonotonicTypeQualifiers, getTypeFactoryOfSubchecker, handleCFGViz, methodFromUse, performFlowAnalysis, postDirectSuperTypes, postInit, preProcessClassTree, setRoot, typeVariablesFromUse
adaptGetClassReturnTypeToReceiver, addAliasedAnnotation, addAliasedAnnotation, addAliasedDeclAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, annotateInheritedFromClass, annotateInheritedFromClass, checkInvalidOptionsInferSignatures, createAnnotatedTypeFormatter, createAnnotationFormatter, createQualifierHierarchy, createQualifierHierarchy, createQualifierHierarchyFactory, createTypeArgumentInference, createTypeHierarchy, createTypeVariableSubstitutor, declarationFromElement, fromElement, fromElement, fromElement, getAnnotatedNullType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFormatter, getAnnotatedTypeFromTypeTree, getAnnotationFormatter, getAnnotationMirror, getAnnotationWithMetaAnnotation, getBoxedType, getBundledTypeQualifiersWithoutPolyAll, getBundledTypeQualifiersWithPolyAll, getContext, getCurrentClassTree, getCurrentClassType, getCurrentMethodReceiver, getDeclAnnotation, getDeclAnnotationNoAliases, getDeclAnnotationWithMetaAnnotation, getElementUtils, getEnclosingMethod, getEnclosingType, getFieldInvariantAnnotationTree, getFnInterfaceFromTree, getFnInterfaceFromTree, getImplicitReceiverType, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getReceiverType, getSelfType, getStringType, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeHierarchy, getTypeVarSubstitutor, getUnboxedType, getUninferredWildcardType, getVisitorState, getWholeProgramInference, initializeReflectionResolution, isAnyEnclosingThisDeref, isFromByteCode, isFromStubFile, isMostEnclosingThisDeref, isSupportedQualifier, isWithinConstructor, parseStubFiles, postAsMemberOf, postProcessClassTree, postTypeVarSubstitution, setPathHack, toAnnotatedType, toString, type, widenToUpperBound
protected static final int MAX_VALUES
protected static final Set<String> coveredClassStrings
protected final AnnotationMirror UNKNOWNVAL
protected final AnnotationMirror BOTTOMVAL
public final AnnotationMirror POLY
PolyValue
annotation.public ValueAnnotatedTypeFactory(BaseTypeChecker checker)
public AnnotationMirror aliasedAnnotation(AnnotationMirror anno)
AnnotatedTypeFactory
Returns an aliased type of the current one
aliasedAnnotation
in class AnnotatedTypeFactory
anno
- the qualifier to check for an aliasprotected Set<Class<? extends Annotation>> createSupportedTypeQualifiers()
AnnotatedTypeFactory
Subclasses may override this method and 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 PolyAll
, and 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.
Annotations located outside the qual subdirectory, or has other ElementType
values must be explicitly listed in code by overriding the AnnotatedTypeFactory.createSupportedTypeQualifiers()
method, as shown below.
Lastly, for checkers that do not want to support PolyAll
, it must also be
explicitly written in code, as shown below.
In total, there are 5 ways to indicate annotations that are supported by a checker:
PolyAll
:
This is the default behavior. Simply place those annotations within the qual directory.
PolyAll
:
Place those annotations within the qual directory, and override AnnotatedTypeFactory.createSupportedTypeQualifiers()
by calling AnnotatedTypeFactory.getBundledTypeQualifiersWithPolyAll(Class...)
with no parameters passed in. Code
example:
@Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
return getBundledTypeQualifiersWithoutPolyAll();
}
PolyAll
,
and a list of other annotations:
Place those annotations within the qual directory, and override AnnotatedTypeFactory.createSupportedTypeQualifiers()
by calling AnnotatedTypeFactory.getBundledTypeQualifiersWithPolyAll(Class...)
with a varargs parameter list of the
other annotations. Code example:
@Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
return getBundledTypeQualifiersWithPolyAll(Regex.class, PartialRegex.class, RegexBottom.class, UnknownRegex.class);
}
PolyAll
:
Place those annotations within the qual directory, and override AnnotatedTypeFactory.createSupportedTypeQualifiers()
by calling AnnotatedTypeFactory.getBundledTypeQualifiersWithoutPolyAll(Class...)
with a varargs parameter list of the
other annotations. Code example:
@Override protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
return getBundledTypeQualifiersWithoutPolyAll(UnknownFormat.class, FormatBottom.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.getBundledTypeQualifiersWithoutPolyAll(Class...)
and AnnotatedTypeFactory.getBundledTypeQualifiersWithPolyAll(Class...)
each must return a fresh, mutable set
createSupportedTypeQualifiers
in class AnnotatedTypeFactory
public Set<AnnotationMirror> getDeclAnnotations(Element elt)
AnnotatedTypeFactory
getDeclAnnotations
in class AnnotatedTypeFactory
elt
- the element for which to determine annotationspublic CFTransfer createFlowTransferFunction(CFAbstractAnalysis<CFValue,CFStore,CFTransfer> 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.
createFlowTransferFunction
in class GenericAnnotatedTypeFactory<CFValue,CFStore,CFTransfer,CFAnalysis>
public QualifierHierarchy createQualifierHierarchy(MultiGraphQualifierHierarchy.MultiGraphFactory factory)
AnnotatedTypeFactory
createQualifierHierarchy
in class AnnotatedTypeFactory
protected TypeAnnotator createTypeAnnotator()
GenericAnnotatedTypeFactory
ImplicitsTypeAnnotator
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
ImplicitsTypeAnnotator
: Adds annotations based on ImplicitFor
meta-annotations
createTypeAnnotator
in class GenericAnnotatedTypeFactory<CFValue,CFStore,CFTransfer,CFAnalysis>
public FieldInvariants getFieldInvariants(TypeElement element)
AnnotatedTypeFactory
Subclass may implement their own field invariant annotations if FieldInvariant
is
not expressive enough. They must override this method to properly create AnnotationMirror and
also override AnnotatedTypeFactory.getFieldInvariantDeclarationAnnotations()
to return their field
invariants.
getFieldInvariants
in class AnnotatedTypeFactory
element
- class for which to get invariantselement
protected Set<Class<? extends Annotation>> getFieldInvariantDeclarationAnnotations()
AnnotatedTypeFactory
getFieldInvariantDeclarationAnnotations
in class AnnotatedTypeFactory
public Pair<AnnotatedTypeMirror.AnnotatedExecutableType,List<AnnotatedTypeMirror>> methodFromUse(ExpressionTree tree, ExecutableElement methodElt, AnnotatedTypeMirror receiverType)
methodFromUse
in class AnnotatedTypeFactory
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
ImplicitsTreeAnnotator
: Adds annotations based on ImplicitFor
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<CFValue,CFStore,CFTransfer,CFAnalysis>
public AnnotationMirror createIntValAnnotation(List<Long> values)
IntVal
or IntRange
annotation using the values. If values
is null, then UnknownVal is returned; if values
is empty, then bottom is returned. If
the number of values
is greater than MAX_VALUES, return an IntRange
. In other
cases, the values are sorted and duplicates are removed before an IntVal
is created.values
- list of longs; duplicates are allowed and the values may be in any orderpublic AnnotationMirror convertIntRangeToIntVal(AnnotationMirror intRangeAnno)
@IntRange
annotation to an @IntVal
annotation, or to UNKNOWNVAL if
the input is too wide to be represented as an @IntVal
.public AnnotationMirror createDoubleValAnnotation(List<Double> values)
DoubleVal
annotation using the values. If values
is null, then
UnknownVal is returned; if values
is empty, then bottom is returned. The values are
sorted and duplicates are removed before the annotation is created.values
- list of doubles; duplicates are allowed and the values may be in any orderDoubleVal
annotation using the valuespublic AnnotationMirror createStringAnnotation(List<String> values)
StringVal
annotation using the values. If values
is null, then
UnknownVal is returned; if values
is empty, then bottom is returned. The values are
sorted and duplicates are removed before the annotation is created. If values is larger than
the max number of values allowed (10 by default), then an ArrayLen
or an ArrayLenRange
annotation is returned.values
- list of strings; duplicates are allowed and the values may be in any orderStringVal
annotation using the valuespublic AnnotationMirror createArrayLenAnnotation(List<Integer> values)
ArrayLen
annotation using the values. If values
is null, then
UnknownVal is returned; if values
is empty, then bottom is returned. The values are
sorted and duplicates are removed before the annotation is created. If values is larger than
the max number of values allowed (10 by default), then an ArrayLenRange
annotation is
returned.values
- list of integers; duplicates are allowed and the values may be in any orderArrayLen
annotation using the valuespublic AnnotationMirror createBooleanAnnotation(List<Boolean> values)
BoolVal
annotation using the values. If values
is null, then
UnknownVal is returned; if values
is empty, then bottom is returned. The values are
sorted and duplicates are removed before the annotation is created.values
- list of booleans; duplicates are allowed and the values may be in any orderBoolVal
annotation using the valuespublic AnnotationMirror createCharAnnotation(List<Character> values)
IntVal
annotation using the values. If values
is null, then
UnknownVal is returned; if values
is empty, then bottom is returned. The values are
sorted and duplicates are removed before the annotation is created.values
- list of characters; duplicates are allowed and the values may be in any orderIntVal
annotation using the valuespublic AnnotationMirror createNumberAnnotationMirror(List<Number> values)
values
- must be a homogeneous list: every element of it has the same class.public AnnotationMirror createIntRangeAnnotation(Range range)
@IntRange
or @IntVal
annotation from the range. May return
BOTTOMVAL or UNKNOWNVAL.public AnnotationMirror createArrayLenRangeAnnotation(int from, int to)
@ArrayLenRange
annotation from the two (inclusive) bounds. Does not return
BOTTOMVAL or UNKNOWNVAL.public AnnotationMirror createArrayLenRangeAnnotation(Range range)
@ArrayLenRange
annotation from the range. May return BOTTOMVAL or
UNKNOWNVAL.public AnnotationMirror convertArrayLenToArrayLenRange(AnnotationMirror arrayLenAnno)
@ArrayLen
annotation to an @ArrayLenRange
annotation.public AnnotationMirror convertIntValToIntRange(AnnotationMirror intValAnno)
@IntVal
annotation to an @IntRange
annotation.public static Range getRange(AnnotationMirror rangeAnno)
Range
bounded by the values specified in the given @Range
annotation. Also returns an appropriate range if an @IntVal
annotation is passed.
Returns null
if the annotation is null or if the annotation is not an IntRange
, IntRangeFromPositive
, IntVal
, or ArrayLenRange
.public static List<Long> getIntValues(AnnotationMirror intAnno)
The method returns a list of Long
but is named getIntValues
because it
supports the @IntVal
annotation.
intAnno
- an @IntVal
annotation, or nullpublic static List<Double> getDoubleValues(AnnotationMirror doubleAnno)
doubleAnno
- a @DoubleVal
annotation, or nullpublic static List<Integer> getArrayLength(AnnotationMirror arrayAnno)
arrayAnno
- an @ArrayLen
annotation, or nullpublic static List<Character> getCharValues(AnnotationMirror intAnno)
intAnno
- an @IntVal
annotation, or nullpublic static List<Boolean> getBooleanValues(AnnotationMirror boolAnno)
boolAnno
- a @BoolVal
annotation, or nullpublic static List<String> getStringValues(AnnotationMirror stringAnno)
stringAnno
- a @StringVal
annotation, or nullpublic boolean isIntRange(Set<AnnotationMirror> anmSet)
public boolean isIntRange(AnnotationMirror anm)
public Integer getMinLenValue(AnnotatedTypeMirror atm)
public Integer getMaxLenValue(AnnotationMirror annotation)
public Integer getMinLenValue(AnnotationMirror annotation)
Note that this routine handles actual MinLen
annotations, because it is called by
aliasedAnnotation(AnnotationMirror)
, which transforms
MinLen
annotations into ArrayLenRange
annotations.
public Long getMinimumIntegralValue(AnnotatedTypeMirror atm)
AnnotatedTypeMirror
should contain either an @IntRange
annotation or an
@IntVal
annotation. Returns null if it does not.public int getMinLenFromString(String arrayExpression, Tree tree, TreePath currentPath)
arrayExpression
- flow expressiontree
- expression tree or variable declarationcurrentPath
- path to local scope