public class ValueAnnotatedTypeFactory extends BaseAnnotatedTypeFactory
| Modifier and Type | Class and Description |
|---|---|
protected class |
ValueAnnotatedTypeFactory.ValueTreeAnnotator
The TreeAnnotator for this AnnotatedTypeFactory.
|
protected class |
ValueAnnotatedTypeFactory.ValueTypeAnnotator
Performs pre-processing on annotations written by users, replacing illegal annotations by
legal ones.
|
GenericAnnotatedTypeFactory.ScanStateAnnotatedTypeFactory.InheritedFromClassAnnotator, AnnotatedTypeFactory.ParameterizedExecutableType| Modifier and Type | Field and Description |
|---|---|
protected AnnotationMirror |
BOTTOMVAL
The bottom type for this hierarchy.
|
protected static Set<String> |
COVERED_CLASS_STRINGS
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.
|
analysis, cfgVisualizer, defaults, dependentTypesHelper, emptyStore, flowByDefault, flowResult, flowResultAnalysisCaches, initializationStaticStore, initializationStore, methodInvocationStores, poly, regularExitStores, returnStatementStores, scannedClasses, transfer, treeAnnotator, typeAnnotatorchecker, elements, fromExpressionTreeCache, fromMemberTreeCache, fromTypeTreeCache, ignoreUninferredTypeArguments, loader, objectGetClass, 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 |
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 |
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. |
protected TypeHierarchy |
createTypeHierarchy()
Creates the type subtyping checker using the current type qualifier hierarchy.
|
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.
|
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, 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. |
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 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.
|
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.
|
long |
getToValueFromIntRange(AnnotatedTypeMirror atm)
Finds the appropriate value for the
to value of an annotated type mirror containing
an IntRange annotation. |
boolean |
isIntRange(AnnotationMirror anm) |
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.
|
createFlowAnalysisaddCheckedCodeDefaults, addCheckedStandardDefaults, addComputedTypeAnnotations, addComputedTypeAnnotations, addComputedTypeAnnotations, addDefaultAnnotations, addTypeNameImplicit, addUncheckedCodeDefaults, addUncheckedStandardDefaults, analyze, applyInferredAnnotations, checkAndPerformFlowAnalysis, checkForDefaultQualifierInHierarchy, constructorFromUse, createAndInitQualifierDefaults, createCFGVisualizer, createDependentTypesHelper, createQualifierDefaults, createQualifierPolymorphism, fromNewClass, getAnnotatedTypeLhs, getAnnotatedTypeLhsNoTypeVarDefault, getAnnotatedTypeRhsUnaryAssign, getAnnotatedTypeVarargsArray, getAnnotationFromJavaExpressionString, getAnnotationFromReceiver, getAnnotationMirrorFromJavaExpressionString, getCFGVisualizer, getDependentTypesHelper, getEmptyStore, getFinalLocalValues, getFirstNodeOfKindForTree, getInferredValueFor, getMethodReturnType, getMethodReturnType, getNodesForTree, getQualifierPolymorphism, getReceiverFromJavaExpressionString, getRegularExitStore, getResultingTypeOfConstructorMemberReference, getReturnStatementStores, getShouldDefaultTypeVarLocals, getSortedQualifierNames, getStoreAfter, getStoreAfter, getStoreAfter, getStoreBefore, getStoreBefore, getStoreBefore, getSupportedMonotonicTypeQualifiers, getTypeFactoryOfSubchecker, handleCFGViz, methodFromUse, performFlowAnalysis, postDirectSuperTypes, postInit, preProcessClassTree, setRoot, typeVariablesFromUseadaptGetClassReturnTypeToReceiver, addAliasedAnnotation, addAliasedAnnotation, addAliasedAnnotation, addAliasedAnnotation, addAliasedDeclAnnotation, addAnnotationFromFieldInvariant, addInheritedAnnotation, annotateInheritedFromClass, annotateInheritedFromClass, checkInvalidOptionsInferSignatures, createAnnotatedTypeFormatter, createAnnotationClassLoader, createAnnotationFormatter, createQualifierHierarchy, createQualifierHierarchy, createQualifierHierarchyFactory, createTypeArgumentInference, createTypeVariableSubstitutor, declarationFromElement, fromElement, fromElement, fromElement, getAnnotatedNullType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFormatter, getAnnotatedTypeFromTypeTree, getAnnotationFormatter, getAnnotationMirror, getAnnotationWithMetaAnnotation, getBoxedType, getBundledTypeQualifiersWithoutPolyAll, getBundledTypeQualifiersWithPolyAll, getCacheSize, getContext, getCurrentClassTree, getCurrentClassType, getCurrentMethodReceiver, getDeclAnnotation, getDeclAnnotationNoAliases, getDeclAnnotations, getDeclAnnotationWithMetaAnnotation, getElementUtils, getEnclosingElementForArtificialTree, 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, setEnclosingElementForArtificialTree, toAnnotatedType, toString, type, widenToUpperBoundprotected static final int MAX_VALUES
protected static final Set<String> COVERED_CLASS_STRINGS
protected final AnnotationMirror UNKNOWNVAL
protected final AnnotationMirror BOTTOMVAL
public final AnnotationMirror POLY
PolyValue annotation.public ValueAnnotatedTypeFactory(BaseTypeChecker checker)
public AnnotationMirror canonicalAnnotation(AnnotationMirror anno)
AnnotatedTypeFactoryA canonical annotation is the internal annotation that will be used by the Checker Framework in the aliased annotation's place.
canonicalAnnotation in class AnnotatedTypeFactoryanno - the qualifier to check for an aliasprotected Set<Class<? extends Annotation>> createSupportedTypeQualifiers()
AnnotatedTypeFactorySubclasses 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 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.
To not support PolyAll, see examples below.
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:
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 AnnotatedTypeFactorypublic CFTransfer createFlowTransferFunction(CFAbstractAnalysis<CFValue,CFStore,CFTransfer> analysis)
GenericAnnotatedTypeFactoryThis 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)
AnnotatedTypeFactorycreateQualifierHierarchy in class AnnotatedTypeFactoryprotected TypeHierarchy createTypeHierarchy()
AnnotatedTypeFactorySubclasses may override this method to specify new type-checking rules beyond the typical java subtyping rules.
createTypeHierarchy in class AnnotatedTypeFactoryprotected TypeAnnotator createTypeAnnotator()
GenericAnnotatedTypeFactoryImplicitsTypeAnnotator
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@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 AnnotatedTypeFactoryelement - class for which to get invariantselementprotected Set<Class<? extends Annotation>> getFieldInvariantDeclarationAnnotations()
AnnotatedTypeFactorygetFieldInvariantDeclarationAnnotations in class AnnotatedTypeFactorypublic AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(ExpressionTree tree, ExecutableElement methodElt, AnnotatedTypeMirror receiverType)
methodFromUse in class AnnotatedTypeFactorytree - 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 annotation.public long getToValueFromIntRange(AnnotatedTypeMirror atm)
to value of an annotated type mirror containing
an IntRange annotation.atm - an annotated type mirror that contains an IntRange annotation.protected TreeAnnotator createTreeAnnotator()
GenericAnnotatedTypeFactoryTreeAnnotator 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 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 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 sequenceExpression, Tree tree, TreePath currentPath)
sequenceExpression - flow expressiontree - expression tree or variable declarationcurrentPath - path to local scope