use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class SameLenAnnotatedTypeFactory method createSameLen.
/**
* Creates a @SameLen annotation whose values are the given strings.
*/
public AnnotationMirror createSameLen(String... val) {
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, SameLen.class);
Arrays.sort(val);
builder.setValue("value", val);
return builder.build();
}
use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class ContractsUtils method getAnnotationMirrorOfQualifier.
/**
* Returns the annotation mirror as specified by the "qualifier" element in {@code
* qualifierAnno}. If {@code argumentAnno} is specified, then arguments are copied from {@code
* argumentAnno} to the returned annotation, renamed according to {@code argumentMap}.
*
* <p>This is a helper method intended to be called from {@link
* getAnnotationMirrorOfContractAnnotation} and {@link getAnnotationMirrorOfMetaAnnotation}. Use
* one of those methods if possible.
*
* @param qualifierAnno annotation specifying the qualifier class
* @param argumentAnno annotation containing the argument values, or {@code null}
* @param argumentRenaming renaming of argument names, which maps from names in {@code
* argumentAnno} to names used in the returned annotation, or {@code null}
*/
private AnnotationMirror getAnnotationMirrorOfQualifier(AnnotationMirror qualifierAnno, AnnotationMirror argumentAnno, Map<String, String> argumentRenaming) {
@SuppressWarnings("unchecked") Class<? extends Annotation> c = (Class<? extends Annotation>) AnnotationUtils.getElementValueClass(qualifierAnno, "qualifier", false);
AnnotationMirror anno;
if (argumentAnno == null || argumentRenaming.isEmpty()) {
// If there are no arguments, use factory method that allows caching
anno = AnnotationBuilder.fromClass(factory.getElementUtils(), c);
} else {
AnnotationBuilder builder = new AnnotationBuilder(factory.getProcessingEnv(), c);
builder.copyRenameElementValuesFromAnnotation(argumentAnno, argumentRenaming);
anno = builder.build();
}
if (factory.isSupportedQualifier(anno)) {
return anno;
} else {
AnnotationMirror aliasedAnno = factory.aliasedAnnotation(anno);
if (factory.isSupportedQualifier(aliasedAnno)) {
return aliasedAnno;
} else {
return null;
}
}
}
use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class SearchIndexAnnotatedTypeFactory method createSearchIndexFor.
/**
* Create a new {@code @SearchIndexFor} annotation with the given arrays as its arguments.
*/
AnnotationMirror createSearchIndexFor(List<String> arrays) {
if (arrays.size() == 0) {
return UNKNOWN;
}
// remove duplicates
arrays = new ArrayList<>(new HashSet<>(arrays));
Collections.sort(arrays);
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, SearchIndexFor.class);
builder.setValue("value", arrays);
return builder.build();
}
use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class SearchIndexAnnotatedTypeFactory method createNegativeIndexFor.
/**
* Create a new {@code @NegativeIndexFor} annotation with the given arrays as its arguments.
*/
AnnotationMirror createNegativeIndexFor(List<String> arrays) {
if (arrays.size() == 0) {
return UNKNOWN;
}
// remove duplicates
arrays = new ArrayList<>(new HashSet<>(arrays));
Collections.sort(arrays);
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, NegativeIndexFor.class);
builder.setValue("value", arrays);
return builder.build();
}
use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class InitializationAnnotatedTypeFactory method createUnclassifiedAnnotation.
/**
* Returns a {@link UnknownInitialization} annotation with a given type frame.
*/
public AnnotationMirror createUnclassifiedAnnotation(TypeMirror typeFrame) {
assert typeFrame != null;
Class<? extends Annotation> clazz = useFbc ? UnknownInitialization.class : Raw.class;
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, clazz);
builder.setValue("value", typeFrame);
return builder.build();
}
Aggregations