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(TypeMirror 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 LockAnnotatedTypeFactory method createGuardedByAnnotationMirror.
/**
* @param values a list of lock expressions
* @return an AnnotationMirror corresponding to @GuardedBy(values)
*/
private AnnotationMirror createGuardedByAnnotationMirror(List<String> values) {
AnnotationBuilder builder = new AnnotationBuilder(getProcessingEnv(), GuardedBy.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 FormatterTreeUtil method categoriesToFormatAnnotation.
/**
* Takes a list of ConversionCategory elements, and returns a syntax tree element that
* represents a {@link Format} annotation with the list as value.
*/
public AnnotationMirror categoriesToFormatAnnotation(ConversionCategory[] args) {
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, Format.class.getCanonicalName());
builder.setValue("value", args);
return builder.build();
}
use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class I18nFormatterTransfer method visitMethodInvocation.
@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(MethodInvocationNode node, TransferInput<CFValue, CFStore> in) {
I18nFormatterAnnotatedTypeFactory atypeFactory = (I18nFormatterAnnotatedTypeFactory) analysis.getTypeFactory();
TransferResult<CFValue, CFStore> result = super.visitMethodInvocation(node, in);
I18nFormatterTreeUtil tu = atypeFactory.treeUtil;
// If hasFormat is called, make sure that the format string is annotated correctly
if (tu.isHasFormatCall(node, atypeFactory)) {
CFStore thenStore = result.getRegularStore();
CFStore elseStore = thenStore.copy();
ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(result.getResultValue(), thenStore, elseStore);
Result<I18nConversionCategory[]> cats = tu.getHasFormatCallCategories(node);
if (cats.value() == null) {
tu.failure(cats, "i18nformat.indirect.arguments");
} else {
Receiver firstParam = FlowExpressions.internalReprOf(atypeFactory, node.getArgument(0));
AnnotationMirror anno = atypeFactory.treeUtil.categoriesToFormatAnnotation(cats.value());
thenStore.insertValue(firstParam, anno);
}
return newResult;
}
// If isFormat is called, annotate the format string with I18nInvalidFormat
if (tu.isIsFormatCall(node, atypeFactory)) {
CFStore thenStore = result.getRegularStore();
CFStore elseStore = thenStore.copy();
ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(result.getResultValue(), thenStore, elseStore);
Receiver firstParam = FlowExpressions.internalReprOf(atypeFactory, node.getArgument(0));
AnnotationBuilder builder = new AnnotationBuilder(tu.processingEnv, I18nInvalidFormat.class.getCanonicalName());
// No need to set a value of @I18nInvalidFormat
builder.setValue("value", "");
elseStore.insertValue(firstParam, builder.build());
return newResult;
}
// corresponding key's value
if (tu.isMakeFormatCall(node, atypeFactory)) {
Result<I18nConversionCategory[]> cats = tu.makeFormatCallCategories(node, atypeFactory);
if (cats.value() == null) {
tu.failure(cats, "i18nformat.key.not.found");
} else {
AnnotationMirror anno = atypeFactory.treeUtil.categoriesToFormatAnnotation(cats.value());
CFValue newResultValue = analysis.createSingleAnnotationValue(anno, result.getResultValue().getUnderlyingType());
return new RegularTransferResult<>(newResultValue, result.getRegularStore());
}
}
return result;
}
use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.
the class I18nFormatterTreeUtil method stringToInvalidFormatAnnotation.
/**
* Takes an invalid formatter string and returns a syntax trees element that represents a {@link
* I18nInvalidFormat} annotation with the invalid formatter string as value.
*/
// package-private
AnnotationMirror stringToInvalidFormatAnnotation(String invalidFormatString) {
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, I18nInvalidFormat.class.getCanonicalName());
builder.setValue("value", invalidFormatString);
return builder.build();
}
Aggregations