use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class ValueAnnotatedTypeFactory method createArrayLenRangeAnnotation.
/**
* Create an {@code @ArrayLenRange} annotation from the two (inclusive) bounds. Does not return
* BOTTOMVAL or UNKNOWNVAL.
*/
public AnnotationMirror createArrayLenRangeAnnotation(int from, int to) {
assert from <= to;
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, ArrayLenRange.class);
builder.setValue("from", from);
builder.setValue("to", to);
return builder.build();
}
use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class ValueAnnotatedTypeFactory method createStringAnnotation.
/**
* Returns a {@link StringVal} annotation using the values. If {@code values} is null, then
* UnknownVal is returned; if {@code values} is empty, then bottom is returned. The values are
* sorted and duplicates are removed before the annotation is created. If values is larger than
* the max number of values allowed (10 by default), then an {@link ArrayLen} or an {@link
* ArrayLenRange} annotation is returned.
*
* @param values list of strings; duplicates are allowed and the values may be in any order
* @return a {@link StringVal} annotation using the values
*/
public AnnotationMirror createStringAnnotation(List<String> values) {
if (values == null) {
return UNKNOWNVAL;
}
if (values.isEmpty()) {
return BOTTOMVAL;
}
values = ValueCheckerUtils.removeDuplicates(values);
if (values.size() > MAX_VALUES) {
// Too many strings are replaced by their lengths
List<Integer> lengths = ValueCheckerUtils.getLengthsForStringValues(values);
return createArrayLenAnnotation(lengths);
} else {
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, StringVal.class);
builder.setValue("value", values);
return builder.build();
}
}
use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class ValueAnnotatedTypeFactory method createIntRangeAnnotation.
/**
* Create an {@code @IntRange} annotation from the two (inclusive) bounds. Does not return
* BOTTOMVAL or UNKNOWNVAL.
*/
private AnnotationMirror createIntRangeAnnotation(long from, long to) {
assert from <= to;
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, IntRange.class);
builder.setValue("from", from);
builder.setValue("to", to);
return builder.build();
}
Aggregations