Class ValueCheckerUtils
- java.lang.Object
-
- org.checkerframework.common.value.ValueCheckerUtils
-
public class ValueCheckerUtils extends java.lang.Object
Utility methods for the Value Checker.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @Nullable java.lang.String
getExactStringValue(com.sun.source.tree.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.static @Nullable java.lang.Long
getExactValue(com.sun.source.tree.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.static @Nullable java.lang.Long
getExactValue(javax.lang.model.element.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.static java.util.List<java.lang.Integer>
getLengthsForStringValues(java.util.List<java.lang.String> values)
Gets a list of lengths for a list of string values.static @Nullable java.lang.Long
getMaxValue(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory factory)
Finds the maximum value in a Value Checker type.static int
getMinLen(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory valueAnnotatedTypeFactory)
Queries the Value Checker to determine if there is a known minimum length for the array represented bytree
.static @Nullable java.lang.Integer
getMinLenFromTree(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory valueATF)
Looks up the minlen of a member select tree.static @Nullable java.lang.Long
getMinValue(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory factory)
Finds the minimum value in a Value Checker type.static @Nullable Range
getPossibleValues(AnnotatedTypeMirror valueType, ValueAnnotatedTypeFactory valueAnnotatedTypeFactory)
Returns a range representing the possible integral values represented by the passedAnnotatedTypeMirror
.static @Nullable Range
getRangeFromValues(java.util.List<? extends java.lang.Number> values)
Get the minimum and maximum of a list and return a range bounded by them.static java.util.List<?>
getValuesCastedToType(javax.lang.model.element.AnnotationMirror anno, javax.lang.model.type.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 java.util.List<?>
getValuesCastedToType(javax.lang.model.element.AnnotationMirror anno, javax.lang.model.type.TypeMirror castTo, ValueAnnotatedTypeFactory atypeFactory)
Get a list of the values of an annotation, and then cast the values to a given type.static <T> @Nullable java.util.List<T>
getValuesFromRange(@Nullable Range range, java.lang.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 Detail
-
getValuesCastedToType
public static java.util.List<?> getValuesCastedToType(javax.lang.model.element.AnnotationMirror anno, javax.lang.model.type.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 java.util.List<?> getValuesCastedToType(javax.lang.model.element.AnnotationMirror anno, javax.lang.model.type.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
public static @Nullable Range getRangeFromValues(java.util.List<? extends java.lang.Number> values)
Get the minimum and maximum of a list and return a range bounded by them.
-
getValuesFromRange
public static <T> @Nullable java.util.List<T> getValuesFromRange(@Nullable Range range, java.lang.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
public static java.util.List<java.lang.Integer> getLengthsForStringValues(java.util.List<java.lang.String> values)
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
public static @Nullable java.lang.Long getExactValue(com.sun.source.tree.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. 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
public static @Nullable java.lang.Long getExactValue(javax.lang.model.element.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.- 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
public static @Nullable java.lang.String getExactStringValue(com.sun.source.tree.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. 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
public static @Nullable java.lang.Long getMinValue(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory factory)
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
public static @Nullable java.lang.Long getMaxValue(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory factory)
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
public static @Nullable java.lang.Integer getMinLenFromTree(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory valueATF)
Looks up the minlen of a member select tree. The tree must be an access to a sequence length.
-
getMinLen
public static int getMinLen(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory valueAnnotatedTypeFactory)
Queries the Value Checker to determine if there is a known minimum length for the array represented bytree
. If not, returns 0.
-
optimize
public static JavaExpression optimize(JavaExpression je, AnnotatedTypeFactory factory)
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
-
-