use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class InitializationAnnotatedTypeFactory method createFreeAnnotation.
/**
* Returns a {@link UnderInitialization} annotation with a given type frame.
*/
public AnnotationMirror createFreeAnnotation(Class<?> typeFrame) {
assert typeFrame != null;
assert useFbc : "The rawness type system does not have a @UnderInitialization annotation.";
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, UnderInitialization.class);
builder.setValue("value", typeFrame);
return builder.build();
}
use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class KeyForAnnotatedTypeFactory method createKeyForAnnotationMirrorWithValue.
/*
* Given a string array 'values', returns an AnnotationMirror corresponding to @KeyFor(values)
*/
public AnnotationMirror createKeyForAnnotationMirrorWithValue(LinkedHashSet<String> values) {
// Create an AnnotationBuilder with the ArrayList
AnnotationBuilder builder = new AnnotationBuilder(getProcessingEnv(), KeyFor.class);
builder.setValue("value", values.toArray());
// Return the resulting AnnotationMirror
return builder.build();
}
use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class UnitsAnnotationClassLoader method isSupportedAnnotationClass.
/**
* Custom filter for units annotations:
*
* <p>This filter will ignore (by returning false) any units annotation which is an alias of
* another base unit annotation (identified via {@link UnitsMultiple} meta-annotation). Alias
* annotations can still be used in source code; they are converted into a base annotation by
* {@link UnitsAnnotatedTypeFactory#aliasedAnnotation(AnnotationMirror)}. This filter simply
* makes sure that the alias annotations themselves don't become part of the type hierarchy as
* their base annotations already are in the hierarchy.
*/
@Override
protected boolean isSupportedAnnotationClass(Class<? extends Annotation> annoClass) {
// build the initial annotation mirror (missing prefix)
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, annoClass);
AnnotationMirror initialResult = builder.build();
// further refine to see if the annotation is an alias of some other SI Unit annotation
for (AnnotationMirror metaAnno : initialResult.getAnnotationType().asElement().getAnnotationMirrors()) {
// base units
if (AnnotationUtils.areSameByClass(metaAnno, UnitsMultiple.class)) {
return false;
}
}
// Not an alias unit
return true;
}
use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class UnitsRelationsTools method buildAnnoMirrorWithSpecificPrefix.
/**
* Creates an AnnotationMirror representing a unit defined by annoClass, with the specific
* Prefix p
*
* @param env the Checker Processing Environment, provided as a parameter in init() of a
* UnitsRelations implementation
* @param annoClass the Class of an Annotation representing a Unit (eg m.class for meters)
* @param p a Prefix value
* @return an AnnotationMirror of the Unit with the Prefix p, or null if it cannot be
* constructed
*/
@Nullable
public static AnnotationMirror buildAnnoMirrorWithSpecificPrefix(final ProcessingEnvironment env, final Class<? extends Annotation> annoClass, final Prefix p) {
if (env == null || annoClass == null || p == null) {
return null;
}
AnnotationBuilder builder = new AnnotationBuilder(env, annoClass);
builder.setValue("value", p);
return builder.build();
}
use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class FormatterTreeUtil method stringToInvalidFormatAnnotation.
/**
* Takes an invalid formatter string and, returns a syntax trees element that represents a
* {@link InvalidFormat} annotation with the invalid formatter string as value.
*/
// package-private
AnnotationMirror stringToInvalidFormatAnnotation(String invalidFormatString) {
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, InvalidFormat.class.getCanonicalName());
builder.setValue("value", invalidFormatString);
return builder.build();
}
Aggregations