Class ValueCheckerUtils


  • public class ValueCheckerUtils
    extends java.lang.Object
    Utility methods for the Value Checker.
    • 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 values
        castTo - the type that is cast to
        atypeFactory - 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 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​(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 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 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 passed AnnotatedTypeMirror. If the passed AnnotatedTypeMirror does not contain an IntRange annotation or an IntVal 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 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 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 by tree. If not, returns 0.