Class ValueCheckerUtils

java.lang.Object
org.checkerframework.common.value.ValueCheckerUtils

public class ValueCheckerUtils extends Object
Utility methods for the Value Checker.
  • 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 values
      castTo - the type that is cast to
      atypeFactory - 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 values
      castTo - the unannotated type that is casted to
      isUnsigned - true if the type being casted to is unsigned
      atypeFactory - the type factory
      Returns:
      a list of values after the casting
    • getRangeFromValues

      public static @Nullable Range getRangeFromValues(List<? extends Number> values)
      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 than ValueAnnotatedTypeFactory.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 range
      expectedType - 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 List<Integer> getLengthsForStringValues(List<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 passed AnnotatedTypeMirror. If the passed AnnotatedTypeMirror does not contain an IntRange annotation or an IntVal annotation, returns null.
    • getExactValue

      public static @Nullable Long 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. 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 Long 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.
      Parameters:
      element - the element to get the exact value from
      factory - a ValueAnnotatedTypeFactory used for annotation accessing
      Returns:
      the exact value of the element if it is constant, or null otherwise
    • getExactStringValue

      public static @Nullable String getExactStringValue(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 Long getMinValue(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 Long getMaxValue(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 Integer getMinLenFromTree(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(Tree tree, ValueAnnotatedTypeFactory valueAnnotatedTypeFactory)
      Queries the Value Checker to determine if there is a known minimum length for the array represented by tree. If not, returns 0.
    • optimize

      public static JavaExpression optimize(JavaExpression je, AnnotatedTypeFactory factory)
      Optimize the given JavaExpression. See JavaExpressionOptimizer for more details.
      Parameters:
      je - the expression to optimize
      factory - the annotated type factory
      Returns:
      an optimized version of the argument