public class ValueAnnotatedTypeFactory extends BaseAnnotatedTypeFactory
GenericAnnotatedTypeFactory.ScanState
AnnotatedTypeFactory.ParameterizedExecutableType
Modifier and Type | Field and Description |
---|---|
static String |
ARRAYLEN_NAME
Fully-qualified class name of
ArrayLen . |
static String |
ARRAYLENRANGE_NAME
Fully-qualified class name of
ArrayLenRange . |
protected ExecutableElement |
arrayLenRangeFromElement
The from() element/field of an @ArrayLenRange annotation.
|
protected ExecutableElement |
arrayLenRangeToElement
The to() element/field of an @ArrayLenRange annotation.
|
protected ExecutableElement |
arrayLenValueElement
The value() element/field of an @ArrayLen annotation.
|
AnnotationMirror |
BOOLEAN_FALSE
The canonical @
BoolVal (false) annotation. |
AnnotationMirror |
BOOLEAN_TRUE
The canonical @
BoolVal (true) annotation. |
static String |
BOOLVAL_NAME
Fully-qualified class name of
BoolVal . |
protected ExecutableElement |
boolValValueElement
The value() element/field of a @BoolVal annotation.
|
protected AnnotationMirror |
BOTTOMVAL
The bottom type for this hierarchy.
|
static String |
BOTTOMVAL_NAME
Fully-qualified class name of
BottomVal . |
static String |
DOUBLEVAL_NAME
Fully-qualified class name of
DoubleVal . |
protected ExecutableElement |
doubleValValueElement
The value() element/field of a @DoubleVal annotation.
|
protected ReflectiveEvaluator |
evaluator
Helper class that evaluates statically executable methods, constructors, and fields.
|
static String |
INTRANGE_FROMGTENEGONE_NAME
Fully-qualified class name of
IntRangeFromGTENegativeOne . |
static String |
INTRANGE_FROMNONNEG_NAME
Fully-qualified class name of
IntRangeFromNonNegative . |
static String |
INTRANGE_FROMPOS_NAME
Fully-qualified class name of
IntRangeFromPositive . |
static String |
INTRANGE_NAME
Fully-qualified class name of
IntRange . |
protected ExecutableElement |
intRangeFromElement
The from() element/field of an @IntRange annotation.
|
protected ExecutableElement |
intRangeToElement
The to() element/field of an @IntRange annotation.
|
static String |
INTVAL_NAME
Fully-qualified class name of
IntVal . |
protected ExecutableElement |
intValValueElement
The value() element/field of a @IntVal annotation.
|
static String |
MATCHES_REGEX_NAME
Fully-qualified class name of
MatchesRegex . |
ExecutableElement |
matchesRegexValueElement
The value() element/field of a @MatchesRegex annotation.
|
protected static int |
MAX_VALUES
The maximum number of values allowed in an annotation's array.
|
static String |
MINLEN_NAME
Fully-qualified class name of
MinLen . |
protected ExecutableElement |
minLenFieldInvariantFieldElement
The field() element/field of a @MinLenFieldInvariant annotation.
|
protected ExecutableElement |
minLenFieldInvariantMinLenElement
The minLen() element/field of a @MinLenFieldInvariant annotation.
|
protected ExecutableElement |
minLenValueElement
The value() element/field of a @MinLen annotation.
|
AnnotationMirror |
POLY
The canonical @
PolyValue annotation. |
static String |
POLY_NAME
Fully-qualified class name of
PolyValue . |
static String |
STRINGVAL_NAME
Fully-qualified class name of
StringVal . |
ExecutableElement |
stringValValueElement
The value() element/field of a @StringVal annotation.
|
static String |
UNKNOWN_NAME
Fully-qualified class name of
UnknownVal . |
protected AnnotationMirror |
UNKNOWNVAL
The top type for this hierarchy.
|
analysis, cfgVisualizer, contractsUtils, defaults, dependentTypesHelper, emptyStore, exceptionalExitStores, flowByDefault, flowResult, flowResultAnalysisCaches, formalParameterPattern, hasOrIsSubchecker, initializationStaticStore, initializationStore, methodInvocationStores, poly, regularExitStores, relevantJavaTypes, returnStatementStores, scannedClasses, shouldClearSubcheckerSharedCFGs, sideEffectsUnrefineAliases, subcheckerSharedCFG, transfer, treeAnnotator, typeAnnotator
ajavaTypes, artificialTreeToEnclosingElementMap, checker, currentFileAjavaTypes, elements, fromExpressionTreeCache, fromMemberTreeCache, fromTypeTreeCache, ignoreUninferredTypeArguments, loader, methodValClassNameElement, methodValMethodNameElement, methodValParamsElement, objectGetClass, processingEnv, qualHierarchy, qualifierUpperBounds, reflectionResolver, root, shouldCache, stubTypes, trees, typeArgumentInference, typeFormatter, typeHierarchy, types, typeVarSubstitutor, uid, wpiOutputFormat
Constructor and Description |
---|
ValueAnnotatedTypeFactory(BaseTypeChecker checker) |
Modifier and Type | Method and Description |
---|---|
AnnotationMirror |
canonicalAnnotation(AnnotationMirror anno)
Returns the canonical annotation for the passed annotation.
|
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 |
createDoubleAnnotation(List<Double> values)
Returns a
DoubleVal 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 |
createMatchesRegexAnnotation(@Nullable List<String> regexes)
Creates an
MatchesRegex annotation for the given regular expressions. |
AnnotationMirror |
createNumberAnnotationMirror(List<Number> values)
Returns an annotation that represents the given set of values.
|
protected QualifierHierarchy |
createQualifierHierarchy()
Returns the
QualifierHierarchy to be used by this checker. |
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
DefaultForTypeAnnotator that adds annotations to a type based on the content
of the type itself. |
protected TypeHierarchy |
createTypeHierarchy()
Creates the type hierarchy to be used by this factory.
|
List<Integer> |
getArrayLength(AnnotationMirror arrayAnno)
Returns the set of possible array lengths as a sorted list with no duplicate values.
|
protected int |
getArrayLenRangeFromValue(AnnotationMirror anno)
Gets the from() element/field out of an ArrayLenRange annotation.
|
protected int |
getArrayLenRangeToValue(AnnotationMirror anno)
Gets the to() element/field out of an ArrayLenRange annotation.
|
Boolean |
getBooleanValue(AnnotationMirror boolAnno)
Returns the single possible boolean value, or null if there is not exactly one possible value.
|
@Nullable List<Boolean> |
getBooleanValues(AnnotationMirror boolAnno)
Returns the set of possible boolean values as a sorted list with no duplicate values.
|
List<Character> |
getCharValues(AnnotationMirror intAnno)
Returns the set of possible values as a sorted list with no duplicate values.
|
List<Double> |
getDoubleValues(AnnotationMirror doubleAnno)
Returns the set of possible values as a sorted list with no duplicate values.
|
AnnotatedTypeMirror |
getDummyAssignedTo(ExpressionTree expressionTree)
Returns the annotation type mirror for the type of
expressionTree with default
annotations applied. |
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, as expressed by the user in
@FieldInvariant method annotations. |
long |
getFromValueFromIntRange(AnnotatedTypeMirror atm)
Finds the appropriate value for the
from value of an annotated type mirror containing
an IntRange annotation. |
protected long |
getIntRangeFromValue(AnnotationMirror intRangeAnno)
Gets the from() element/field out of an IntRange annotation.
|
protected long |
getIntRangeFromValue(AnnotationMirror intRangeAnno,
long defaultValue)
Gets the from() element/field out of an IntRange annotation.
|
protected long |
getIntRangeToValue(AnnotationMirror intRangeAnno)
Gets the to() element/field out of an IntRange annotation.
|
protected long |
getIntRangeToValue(AnnotationMirror intRangeAnno,
long defaultValue)
Gets the to() element/field out of an IntRange annotation.
|
List<Long> |
getIntValues(AnnotationMirror intAnno)
Returns the set of possible values as a sorted list with no duplicate values.
|
List<String> |
getMatchesRegexValues(AnnotationMirror matchesRegexAnno)
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 sequenceExpression,
Tree tree,
TreePath currentPath)
Returns the minimum length of an array expression or 0 if the min length is unknown.
|
int |
getMinLenValue(AnnotatedTypeMirror atm) |
int |
getMinLenValue(AnnotationMirror annotation)
Used to find the minimum length of an array, which is useful for array bounds checking.
|
int |
getMinLenValue(Set<AnnotationMirror> annotations)
Returns the minimum length of an array.
|
protected int |
getMinLenValueValue(AnnotationMirror anno)
Gets the value() element/field out of a MinLen annotation.
|
Range |
getRange(AnnotationMirror rangeAnno)
Returns a
Range bounded by the values specified in the given @Range annotation. |
List<String> |
getStringValues(AnnotationMirror stringAnno)
Returns the set of possible values as a sorted list with no duplicate values.
|
long |
getToValueFromIntRange(AnnotatedTypeMirror atm)
Finds the appropriate value for the
to value of an annotated type mirror containing an
IntRange annotation. |
boolean |
isImmutable(TypeMirror type)
A fact about an array, such as its length, cannot be changed via side effects to the array.
|
boolean |
isIntRange(AnnotationMirror anno)
Returns true if
anno is an IntRange , IntRangeFromPositive , IntRangeFromNonNegative , or IntRangeFromGTENegativeOne . |
boolean |
isIntRange(Set<AnnotationMirror> anmSet) |
AnnotatedTypeFactory.ParameterizedExecutableType |
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
addAnnotationsFromDefaultForType, addCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotations, addDefaultAnnotations, addSharedCFGForTree, addUncheckedStandardDefaults, analyze, applyInferredAnnotations, applyQualifierParameterDefaults, applyQualifierParameterDefaults, checkAndPerformFlowAnalysis, checkForDefaultQualifierInHierarchy, constructorFromUse, constructorFromUsePreSubstitution, createAndInitQualifierDefaults, createCFGVisualizer, createContractsFromMethod, createDefaultForTypeAnnotator, createDefaultForUseTypeAnnotator, createDependentTypesHelper, createQualifierDefaults, createQualifierPolymorphism, createRequiresOrEnsuresQualifier, getAnnotatedTypeLhs, getAnnotatedTypeLhsNoTypeVarDefault, getAnnotatedTypeRhsUnaryAssign, getAnnotatedTypeVarargsArray, getAnnotationFromJavaExpression, getAnnotationFromJavaExpressionString, getAnnotationMirrorFromJavaExpressionString, getAnnotationsFromJavaExpression, getCFGVisualizer, getContractAnnotations, getContractAnnotations, getContractExpressions, getContractsFromMethod, getDefaultForTypeAnnotator, getDefaultValueAnnotatedType, getDependentTypesHelper, getEmptyStore, getEnsuresQualifierIfResult, getExceptionalExitStore, getExplicitNewClassAnnos, getExplicitNewClassClassTypeArgs, getExpressionAndOffsetFromJavaExpressionString, getFinalLocalValues, getFirstNodeOfKindForTree, getInferredValueFor, getMethodReturnType, getNodesForTree, getPostconditionAnnotations, getPostconditionAnnotations, getPostconditionAnnotations, getPreconditionAnnotations, getPreconditionAnnotations, getPreconditionAnnotations, getPreOrPostconditionAnnotations, getQualifierPolymorphism, getRegularExitStore, getResultingTypeOfConstructorMemberReference, getReturnStatementStores, getSharedCFGForTree, getShouldDefaultTypeVarLocals, getSortedQualifierNames, getStoreAfter, getStoreAfter, getStoreAfter, getStoreBefore, getStoreBefore, getStoreBefore, getSupportedMonotonicTypeQualifiers, getTypeFactoryOfSubchecker, handleCFGViz, isRelevant, methodFromUse, methodFromUsePreSubstitution, parseJavaExpressionString, performFlowAnalysis, postAnalyze, postAsMemberOf, postDirectSuperTypes, postInit, preProcessClassTree, setRoot, typeVariablesFromUse
adaptGetClassReturnTypeToReceiver, addAliasedAnnotation, addAliasedAnnotation, addAliasedAnnotation, addAliasedDeclAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAliasedTypeAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, applyCaptureConversion, applyCaptureConversion, applyUnboxing, areSameByClass, binaryTreeArgTypes, binaryTreeArgTypes, checkInvalidOptionsInferSignatures, compoundAssignmentTreeArgTypes, containsSameByClass, containsUninferredTypeArguments, createAnnotatedTypeFormatter, createAnnotationClassLoader, createAnnotationFormatter, createQualifierUpperBounds, createTypeArgumentInference, createTypeVariableSubstitutor, declarationFromElement, doesAnnotatedForApplyToThisChecker, fromElement, fromElement, fromElement, fromNewClass, getAnnotatedNullType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFormatter, getAnnotatedTypeFromTypeTree, getAnnotationByClass, getAnnotationFormatter, getAnnotationMirror, getAnnotationWithMetaAnnotation, getBoxedType, getBundledTypeQualifiers, getCacheSize, getChecker, getCheckerNames, getContractExpressions, getContractListValues, getCurrentClassTree, getCurrentMethodReceiver, getDeclAnnotation, getDeclAnnotationNoAliases, getDeclAnnotations, getDeclAnnotationWithMetaAnnotation, getDefaultTypeDeclarationBounds, getElementUtils, getEnclosingClassOrMethod, getEnclosingElementForArtificialTree, getEnclosingType, getExpressionAndOffset, getFieldInvariantAnnotationTree, getFnInterfaceFromTree, getFunctionTypeFromTree, getFunctionTypeFromTree, getImplicitReceiverType, getIterableElementType, getIterableElementType, getMethodReturnType, getNarrowedAnnotations, getNarrowedPrimitive, getPath, getProcessingEnv, getQualifierHierarchy, getQualifierParameterHierarchies, getQualifierParameterHierarchies, getQualifierUpperBounds, getReceiverType, getSelfType, getStringType, getSupportedTypeQualifierNames, getSupportedTypeQualifiers, getTreeUtils, getTypeArgumentInference, getTypeDeclarationBounds, getTypeHierarchy, getTypeOfExtendsImplements, getTypeVarSubstitutor, getUnboxedType, getUninferredWildcardType, getVisitorTreePath, getWholeProgramInference, getWidenedAnnotations, getWidenedType, getWidenedType, hasExplicitNoQualifierParameterInHierarchy, hasExplicitQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, hasQualifierParameterInHierarchy, initializeAtm, initializeReflectionResolution, isFromByteCode, isFromStubFile, isSupportedQualifier, isSupportedQualifier, isSupportedQualifier, isWithinConstructor, mergeAnnotationFileAnnosIntoType, negateConstant, order, parseAnnotationFiles, postProcessClassTree, prepareMethodForWriting, prepareMethodForWriting, replaceAnnotations, replaceAnnotations, setEnclosingElementForArtificialTree, setVisitorTreePath, shouldWarnIfStubRedundantWithBytecode, toAnnotatedType, toString, type, wpiAdjustForUpdateField, wpiAdjustForUpdateNonField
public static final String UNKNOWN_NAME
UnknownVal
.public static final String BOTTOMVAL_NAME
BottomVal
.public static final String POLY_NAME
PolyValue
.public static final String ARRAYLEN_NAME
ArrayLen
.public static final String BOOLVAL_NAME
BoolVal
.public static final String DOUBLEVAL_NAME
DoubleVal
.public static final String INTVAL_NAME
IntVal
.public static final String STRINGVAL_NAME
StringVal
.public static final String ARRAYLENRANGE_NAME
ArrayLenRange
.public static final String INTRANGE_NAME
IntRange
.public static final String INTRANGE_FROMGTENEGONE_NAME
IntRangeFromGTENegativeOne
.public static final String INTRANGE_FROMNONNEG_NAME
IntRangeFromNonNegative
.public static final String INTRANGE_FROMPOS_NAME
IntRangeFromPositive
.public static final String MINLEN_NAME
MinLen
.public static final String MATCHES_REGEX_NAME
MatchesRegex
.protected static final int MAX_VALUES
protected final AnnotationMirror UNKNOWNVAL
protected final AnnotationMirror BOTTOMVAL
public final AnnotationMirror POLY
PolyValue
annotation.public final AnnotationMirror BOOLEAN_TRUE
BoolVal
(true) annotation.public final AnnotationMirror BOOLEAN_FALSE
BoolVal
(false) annotation.protected final ExecutableElement arrayLenValueElement
protected final ExecutableElement arrayLenRangeFromElement
protected final ExecutableElement arrayLenRangeToElement
protected final ExecutableElement boolValValueElement
protected final ExecutableElement doubleValValueElement
protected final ExecutableElement intRangeFromElement
protected final ExecutableElement intRangeToElement
protected final ExecutableElement intValValueElement
public final ExecutableElement matchesRegexValueElement
protected final ExecutableElement minLenValueElement
protected final ExecutableElement minLenFieldInvariantFieldElement
protected final ExecutableElement minLenFieldInvariantMinLenElement
public final ExecutableElement stringValValueElement
protected final ReflectiveEvaluator evaluator
public ValueAnnotatedTypeFactory(BaseTypeChecker checker)
public AnnotationMirror canonicalAnnotation(AnnotationMirror anno)
AnnotatedTypeFactory
A canonical annotation is the internal annotation that will be used by the Checker Framework in the aliased annotation's place.
canonicalAnnotation
in class AnnotatedTypeFactory
anno
- the qualifier to check for an aliasprotected 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
public 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>
protected 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
protected TypeHierarchy createTypeHierarchy()
AnnotatedTypeFactory
Subclasses may override this method to specify new type-checking rules beyond the typical Java subtyping rules.
createTypeHierarchy
in class AnnotatedTypeFactory
protected 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<CFValue,CFStore,CFTransfer,CFAnalysis>
public FieldInvariants getFieldInvariants(TypeElement element)
AnnotatedTypeFactory
@FieldInvariant
method annotations.
Subclasses 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 AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(ExpressionTree tree, ExecutableElement methodElt, AnnotatedTypeMirror receiverType)
methodFromUse
in class AnnotatedTypeFactory
tree
- either a MethodInvocationTree or a MemberReferenceTreemethodElt
- the element of the referenced methodreceiverType
- the type of the receiverAnnotatedTypeFactory.methodFromUse(MethodInvocationTree)
public long getFromValueFromIntRange(AnnotatedTypeMirror atm)
from
value of an annotated type mirror containing
an IntRange
annotation.atm
- an annotated type mirror that contains an IntRange
annotationpublic long getToValueFromIntRange(AnnotatedTypeMirror atm)
to
value of an annotated type mirror containing an
IntRange
annotation.atm
- an annotated type mirror that contains an IntRange
annotationprotected long getIntRangeFromValue(AnnotationMirror intRangeAnno)
getFromValueFromIntRange(org.checkerframework.framework.type.AnnotatedTypeMirror)
if it might not exist.intRangeAnno
- an IntRange annotationprotected long getIntRangeFromValue(AnnotationMirror intRangeAnno, long defaultValue)
getFromValueFromIntRange(org.checkerframework.framework.type.AnnotatedTypeMirror)
if it might not exist.intRangeAnno
- an IntRange annotationdefaultValue
- the value to return if there is no from() element/fieldprotected long getIntRangeToValue(AnnotationMirror intRangeAnno, long defaultValue)
getToValueFromIntRange(org.checkerframework.framework.type.AnnotatedTypeMirror)
if it might not exist.intRangeAnno
- an IntRange annotationdefaultValue
- the value to retur if there is no to() element/fieldprotected long getIntRangeToValue(AnnotationMirror intRangeAnno)
getToValueFromIntRange(org.checkerframework.framework.type.AnnotatedTypeMirror)
if it might not exist.intRangeAnno
- an IntRange annotationprotected int getArrayLenRangeFromValue(AnnotationMirror anno)
anno
- an ArrayLenRange annotationprotected int getArrayLenRangeToValue(AnnotationMirror anno)
anno
- an ArrayLenRange annotationprotected int getMinLenValueValue(AnnotationMirror anno)
anno
- a MinLen annotationprotected 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<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
.intRangeAnno
- an @IntRange
annotation@IntVal
annotation corresponding to the argumentpublic 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 createDoubleAnnotation(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 doubleacters; duplicates are allowed and the values may be in any orderIntVal
annotation using the valuespublic AnnotationMirror createNumberAnnotationMirror(List<Number> values)
values
- a homogeneous list: every element of it has the same classpublic 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 createMatchesRegexAnnotation(@Nullable List<String> regexes)
MatchesRegex
annotation for the given regular expressions.regexes
- a list of Java regular expressionspublic AnnotationMirror convertArrayLenToArrayLenRange(AnnotationMirror arrayLenAnno)
@ArrayLen
annotation to an @ArrayLenRange
annotation.arrayLenAnno
- an ArrayLen annotationpublic AnnotationMirror convertIntValToIntRange(AnnotationMirror intValAnno)
@IntVal
annotation to an @IntRange
annotation.public 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
.rangeAnno
- a @Range
annotationRange
that the annotation representspublic 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 List<Double> getDoubleValues(AnnotationMirror doubleAnno)
doubleAnno
- a @DoubleVal
annotation, or nullpublic List<Integer> getArrayLength(AnnotationMirror arrayAnno)
arrayAnno
- an @ArrayLen
annotation, or nullpublic List<Character> getCharValues(AnnotationMirror intAnno)
intAnno
- an @IntVal
annotation, or null@IntVal
annotationpublic Boolean getBooleanValue(AnnotationMirror boolAnno)
boolAnno
- a @BoolVal
annotation, or nullgetBooleanValues(javax.lang.model.element.AnnotationMirror)
public @Nullable List<Boolean> getBooleanValues(AnnotationMirror boolAnno)
boolAnno
- a @BoolVal
annotation, or nullpublic List<String> getStringValues(AnnotationMirror stringAnno)
stringAnno
- a @StringVal
annotation, or nullpublic List<String> getMatchesRegexValues(AnnotationMirror matchesRegexAnno)
matchesRegexAnno
- a @MatchesRegex
annotation, or nullpublic boolean isIntRange(Set<AnnotationMirror> anmSet)
public boolean isIntRange(AnnotationMirror anno)
anno
is an IntRange
, IntRangeFromPositive
, IntRangeFromNonNegative
, or IntRangeFromGTENegativeOne
.anno
- annotation mirroranno
is an IntRange
, IntRangeFromPositive
, IntRangeFromNonNegative
, or IntRangeFromGTENegativeOne
public int getMinLenValue(AnnotatedTypeMirror atm)
public Integer getMaxLenValue(AnnotationMirror annotation)
public int getMinLenValue(AnnotationMirror annotation)
Note that this routine handles actual MinLen
annotations, because it is called by
canonicalAnnotation(AnnotationMirror)
, which transforms
MinLen
annotations into ArrayLenRange
annotations.
public int getMinLenValue(Set<AnnotationMirror> annotations)
annotations
- the annotations on the array expressionpublic Long getMinimumIntegralValue(AnnotatedTypeMirror atm)
AnnotatedTypeMirror
should contain either an @IntRange
annotation or an
@IntVal
annotation. Returns null if it does not.atm
- annotated typeatm
could be the typepublic int getMinLenFromString(String sequenceExpression, Tree tree, TreePath currentPath)
sequenceExpression
- Java expressiontree
- expression tree or variable declarationcurrentPath
- path to local scopepublic AnnotatedTypeMirror getDummyAssignedTo(ExpressionTree expressionTree)
expressionTree
with default
annotations applied.getDummyAssignedTo
in class AnnotatedTypeFactory
expressionTree
- an expression which has no assignment context and for which type
arguments need to be inferrednull
or an annotated type mirror that inferrence should pretend expressionTree
is assigned topublic boolean isImmutable(TypeMirror type)
isImmutable
in class AnnotatedTypeFactory
type
- type to test.