Search in sources :

Example 16 with AnnotationBuilder

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

the class AnnotationBuilderTest method testToString3.

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

Example 17 with AnnotationBuilder

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

the class AnnotationBuilderTest method testClassPositive.

@Test
public void testClassPositive() {
    AnnotationBuilder builder = new AnnotationBuilder(env, ClassElt.class);
    builder.setValue("value", String.class);
    builder.setValue("value", int.class);
    builder.setValue("value", int[].class);
    builder.setValue("value", void.class);
    Object storedValue = builder.build().getElementValues().values().iterator().next().getValue();
    assertTrue("storedValue is " + storedValue.getClass(), storedValue instanceof TypeMirror);
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) TypeMirror(javax.lang.model.type.TypeMirror) Test(org.junit.Test)

Example 18 with AnnotationBuilder

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

the class AnnotationBuilderTest method testToString1.

@Test
public void testToString1() {
    AnnotationBuilder builder = new AnnotationBuilder(env, Anno.class);
    assertEquals("@tests.AnnotationBuilderTest.Anno", builder.build().toString());
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) Test(org.junit.Test)

Example 19 with AnnotationBuilder

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

the class AnnotationBuilderTest method testAnnoAsArgPositive.

@Test
public void testAnnoAsArgPositive() {
    AnnotationMirror anno = AnnotationBuilder.fromClass(env.getElementUtils(), MyAnno.class);
    AnnotationBuilder builder = new AnnotationBuilder(env, ContainingAnno.class);
    builder.setValue("value", anno);
    assertEquals("@tests.AnnotationBuilderTest.ContainingAnno(@tests.AnnotationBuilderTest.MyAnno)", builder.build().toString());
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) Test(org.junit.Test)

Example 20 with AnnotationBuilder

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

the class AnnotationBuilderTest method testEnumNegative.

@Test(expected = SourceChecker.CheckerError.class)
public void testEnumNegative() {
    AnnotationBuilder builder = new AnnotationBuilder(env, EnumElt.class);
    builder.setValue("value", 2);
}
Also used : 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