Class ValueCheckerUtils
java.lang.Object
org.checkerframework.common.value.ValueCheckerUtils
Utility methods for the Value Checker.
-
Method Summary
Modifier and TypeMethodDescriptiongetExactStringValue
(Tree tree, ValueAnnotatedTypeFactory factory) Either returns the exact string value of the given tree according to the Constant Value Checker, or null if the exact value is not known.getExactValue
(Tree tree, ValueAnnotatedTypeFactory factory) Either returns the exact value of the given tree according to the Constant Value Checker, or null if the exact value is not known.getExactValue
(Element element, ValueAnnotatedTypeFactory factory) Returns the exact value of an annotated element according to the Constant Value Checker, or null if the exact value is not known.getLengthsForStringValues
(List<String> values) Gets a list of lengths for a list of string values.getMaxValue
(Tree tree, ValueAnnotatedTypeFactory factory) Finds the maximum value in a Value Checker type.static int
getMinLen
(Tree tree, ValueAnnotatedTypeFactory valueAnnotatedTypeFactory) Queries the Value Checker to determine if there is a known minimum length for the array represented bytree
.getMinLenFromTree
(Tree tree, ValueAnnotatedTypeFactory valueATF) Looks up the minlen of a member select tree.getMinValue
(Tree tree, ValueAnnotatedTypeFactory factory) Finds the minimum value in a Value Checker type.getPossibleValues
(AnnotatedTypeMirror valueType, ValueAnnotatedTypeFactory valueAnnotatedTypeFactory) Returns a range representing the possible integral values represented by the passedAnnotatedTypeMirror
.getRangeFromValues
(List<? extends Number> values) Get the minimum and maximum of a list and return a range bounded by them.static List
<?> getValuesCastedToType
(AnnotationMirror anno, TypeMirror castTo, boolean isUnsigned, ValueAnnotatedTypeFactory atypeFactory) Get a list of the values of an annotation, and then cast the values to a given type.static List
<?> getValuesCastedToType
(AnnotationMirror anno, TypeMirror castTo, ValueAnnotatedTypeFactory atypeFactory) Get a list of the values of an annotation, and then cast the values to a given type.getValuesFromRange
(@Nullable Range range, Class<T> expectedType) Get all possible values from the given type and cast them into a boxed primitive type.static JavaExpression
optimize
(JavaExpression je, AnnotatedTypeFactory factory) Optimize the given JavaExpression.
-
Method Details
-
getValuesCastedToType
public static List<?> getValuesCastedToType(AnnotationMirror anno, TypeMirror castTo, ValueAnnotatedTypeFactory atypeFactory) Get a list of the values of an annotation, and then cast the values to a given type.- Parameters:
anno
- the annotation that contains valuescastTo
- the type that is cast toatypeFactory
- the type factory- Returns:
- a list of values after the casting
-
getValuesCastedToType
public static List<?> getValuesCastedToType(AnnotationMirror anno, TypeMirror castTo, boolean isUnsigned, ValueAnnotatedTypeFactory atypeFactory) Get a list of the values of an annotation, and then cast the values to a given type.- Parameters:
anno
- the annotation that contains valuescastTo
- the unannotated type that is casted toisUnsigned
- true if the type being casted to is unsignedatypeFactory
- the type factory- Returns:
- a list of values after the casting
-
getRangeFromValues
Get the minimum and maximum of a list and return a range bounded by them. -
getValuesFromRange
public static <T> @Nullable List<T> getValuesFromRange(@Nullable Range range, Class<T> expectedType) Get all possible values from the given type and cast them into a boxed primitive type. Returns null if the list would have length greater thanValueAnnotatedTypeFactory.MAX_VALUES
.expectedType
must be a boxed type, not a primitive type, because primitive types cannot be stored in a list.- Type Parameters:
T
- the type of the values to obtain- Parameters:
range
- the given rangeexpectedType
- the expected type- Returns:
- a list of all the values in the range, or null if there would be more than
ValueAnnotatedTypeFactory.MAX_VALUES
-
getLengthsForStringValues
Gets a list of lengths for a list of string values.- Parameters:
values
- list of string values- Returns:
- list of unique lengths of strings in
values
-
getPossibleValues
public static @Nullable Range getPossibleValues(AnnotatedTypeMirror valueType, ValueAnnotatedTypeFactory valueAnnotatedTypeFactory) Returns a range representing the possible integral values represented by the passedAnnotatedTypeMirror
. If the passedAnnotatedTypeMirror
does not contain anIntRange
annotation or anIntVal
annotation, returns null. -
getExactValue
Either returns the exact value of the given tree according to the Constant Value Checker, or null if the exact value is not known. This method should only be used by clients who need exactly one value -- such as the LBC's binary operator rules -- and not by those that need to know whether a valueType belongs to a particular qualifier. -
getExactValue
Returns the exact value of an annotated element according to the Constant Value Checker, or null if the exact value is not known.- Parameters:
element
- the element to get the exact value fromfactory
- a ValueAnnotatedTypeFactory used for annotation accessing- Returns:
- the exact value of the element if it is constant, or null otherwise
-
getExactStringValue
Either returns the exact string value of the given tree according to the Constant Value Checker, or null if the exact value is not known. This method should only be used by clients who need exactly one value and not by those that need to know whether a valueType belongs to a particular qualifier. -
getMinValue
Finds the minimum value in a Value Checker type. If there is no information (such as when the list of possible values is empty or null), returns null. Otherwise, returns the smallest value in the list of possible values. -
getMaxValue
Finds the maximum value in a Value Checker type. If there is no information (such as when the list of possible values is empty or null), returns null. Otherwise, returns the smallest value in the list of possible values. -
getMinLenFromTree
Looks up the minlen of a member select tree. The tree must be an access to a sequence length. -
getMinLen
Queries the Value Checker to determine if there is a known minimum length for the array represented bytree
. If not, returns 0. -
optimize
Optimize the given JavaExpression. SeeJavaExpressionOptimizer
for more details.- Parameters:
je
- the expression to optimizefactory
- the annotated type factory- Returns:
- an optimized version of the argument
-