Search in sources :

Example 46 with AnnotationBuilder

use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.

the class I18nFormatterTreeUtil method categoriesToFormatAnnotation.

/**
 * Takes a list of ConversionCategory elements, and returns a syntax tree element that
 * represents a {@link I18nFormat} annotation with the list as value.
 */
public AnnotationMirror categoriesToFormatAnnotation(I18nConversionCategory[] args) {
    AnnotationBuilder builder = new AnnotationBuilder(processingEnv, I18nFormat.class.getCanonicalName());
    builder.setValue("value", args);
    return builder.build();
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) I18nFormat(org.checkerframework.checker.i18nformatter.qual.I18nFormat)

Example 47 with AnnotationBuilder

use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.

the class AnnotationBuilderTest method createAnnoWithoutValues.

@Test
public void createAnnoWithoutValues() {
    AnnotationBuilder builder = new AnnotationBuilder(env, Encrypted.class);
    // AnnotationMirror anno =
    builder.build();
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) Test(org.junit.Test)

Example 48 with AnnotationBuilder

use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.

the class AnnotationBuilderTest method addingValuesAfterBuilding.

@Test(expected = SourceChecker.CheckerError.class)
public void addingValuesAfterBuilding() {
    AnnotationBuilder builder = new AnnotationBuilder(env, AnnoWithStringArg.class);
    builder.setValue("value", "m");
    // AnnotationMirror anno =
    builder.build();
    builder.setValue("value", "n");
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) Test(org.junit.Test)

Example 49 with AnnotationBuilder

use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.

the class AnnotationBuilderTest method testToString4.

@Test
public void testToString4() {
    AnnotationBuilder builder = new AnnotationBuilder(env, Anno.class);
    builder.setValue("value", "m");
    builder.setValue("can", new Object[] { 1 });
    assertEquals("@tests.AnnotationBuilderTest.Anno(value=\"m\", can={1})", builder.build().toString());
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) Test(org.junit.Test)

Example 50 with AnnotationBuilder

use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.

the class AnnotationBuilderTest method createAnnoWithValues0.

@Test
public void createAnnoWithValues0() {
    AnnotationBuilder builder = new AnnotationBuilder(env, AnnoWithStringArg.class);
    builder.setValue("value", "m");
    AnnotationMirror anno = builder.build();
    assertEquals(1, anno.getElementValues().size());
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) Test(org.junit.Test)

Aggregations

AnnotationBuilder (org.checkerframework.javacutil.AnnotationBuilder)63 Test (org.junit.Test)30 AnnotationMirror (javax.lang.model.element.AnnotationMirror)11 ArrayList (java.util.ArrayList)3 InvalidFormat (org.checkerframework.checker.formatter.qual.InvalidFormat)3 I18nInvalidFormat (org.checkerframework.checker.i18nformatter.qual.I18nInvalidFormat)3 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Elements (javax.lang.model.util.Elements)2 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 QualifierHierarchy (org.checkerframework.framework.type.QualifierHierarchy)2 NodeList (com.github.javaparser.ast.NodeList)1 Expression (com.github.javaparser.ast.expr.Expression)1 MarkerAnnotationExpr (com.github.javaparser.ast.expr.MarkerAnnotationExpr)1 MemberValuePair (com.github.javaparser.ast.expr.MemberValuePair)1 NormalAnnotationExpr (com.github.javaparser.ast.expr.NormalAnnotationExpr)1 SingleMemberAnnotationExpr (com.github.javaparser.ast.expr.SingleMemberAnnotationExpr)1 Annotation (java.lang.annotation.Annotation)1 List (java.util.List)1 TypeElement (javax.lang.model.element.TypeElement)1