public class ValueCheckerUtils
extends java.lang.Object
Constructor and Description |
---|
ValueCheckerUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Class<?> |
getArrayClassObject(javax.lang.model.type.TypeMirror componentType) |
static java.lang.Class<?> |
getClassFromType(javax.lang.model.type.TypeMirror type) |
static 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 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.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 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 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 by
tree . |
static java.lang.Integer |
getMinLenFromTree(com.sun.source.tree.Tree tree,
ValueAnnotatedTypeFactory valueATF)
Looks up the minlen of a member select tree.
|
static java.lang.Long |
getMinValue(com.sun.source.tree.Tree tree,
ValueAnnotatedTypeFactory factory)
Finds the minimum value in a Value Checker type.
|
static Range |
getPossibleValues(AnnotatedTypeMirror valueType,
ValueAnnotatedTypeFactory valueAnnotatedTypeFactory)
Returns a range representing the possible integral values represented by the passed
AnnotatedTypeMirror . |
static 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<java.lang.String> |
getValueOfAnnotationWithStringArgument(javax.lang.model.element.AnnotationMirror anno)
Gets the value field of an annotation with a list of strings in its value field.
|
static java.util.List<?> |
getValuesCastedToType(javax.lang.model.element.AnnotationMirror anno,
javax.lang.model.type.TypeMirror castTo)
Get a list of values of annotation, and then cast them to a given type.
|
static <T> java.util.List<T> |
getValuesFromRange(Range range,
java.lang.Class<T> expectedType)
Get all possible values from the given type and cast them into a boxed primitive type.
|
static <T extends java.lang.Comparable<T>> |
removeDuplicates(java.util.List<T> values) |
public static java.lang.Class<?> getClassFromType(javax.lang.model.type.TypeMirror type)
public static java.lang.Class<?> getArrayClassObject(javax.lang.model.type.TypeMirror componentType)
public static java.util.List<?> getValuesCastedToType(javax.lang.model.element.AnnotationMirror anno, javax.lang.model.type.TypeMirror castTo)
anno
- the annotation that contains valuescastTo
- the type that is casted topublic static Range getRangeFromValues(java.util.List<? extends java.lang.Number> values)
public static <T> java.util.List<T> getValuesFromRange(Range range, java.lang.Class<T> expectedType)
expectedType
must be a boxed type, not a primitive type, because primitive types
cannot be stored in a list.
range
- the given rangeexpectedType
- the expected typepublic static <T extends java.lang.Comparable<T>> java.util.List<T> removeDuplicates(java.util.List<T> values)
public static java.util.List<java.lang.Integer> getLengthsForStringValues(java.util.List<java.lang.String> values)
values
- list of string valuesvalues
public static java.util.List<java.lang.String> getValueOfAnnotationWithStringArgument(javax.lang.model.element.AnnotationMirror anno)
For the Index Checker, this will get a list of array names from an Upper Bound or SameLen annotation. making this safe to call on any Upper Bound or SameLen annotation.
public static Range getPossibleValues(AnnotatedTypeMirror valueType, ValueAnnotatedTypeFactory valueAnnotatedTypeFactory)
AnnotatedTypeMirror
. If the passed AnnotatedTypeMirror
does not contain an IntRange
annotation or an IntVal
annotation, returns null.public static java.lang.Long getExactValue(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory factory)
public static java.lang.Long getExactValue(javax.lang.model.element.Element element, ValueAnnotatedTypeFactory factory)
element
- the element to get the exact value fromfactory
- ValueAnnotatedTypeFactory used for annotation accessingpublic static java.lang.String getExactStringValue(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory factory)
public static java.lang.Long getMinValue(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory factory)
public static java.lang.Long getMaxValue(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory factory)
public static java.lang.Integer getMinLenFromTree(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory valueATF)
public static int getMinLen(com.sun.source.tree.Tree tree, ValueAnnotatedTypeFactory valueAnnotatedTypeFactory)
tree
. If not, returns 0.