Search in sources :

Example 1 with AnnotationFactory

use of spoon.reflect.factory.AnnotationFactory in project spoon by INRIA.

the class SampleAnnotation method testAnnotate.

@Test
public void testAnnotate() throws Exception {
    CtClass<?> type = build("spoon.test.testclasses", "SampleClass");
    AnnotationFactory af = type.getFactory().Annotation();
    af.annotate(type, SampleAnnotation.class, "names", new String[] { "foo", "bar" });
    final CtAnnotation<SampleAnnotation> annotation = type.getAnnotation(type.getFactory().Annotation().createReference(SampleAnnotation.class));
    assertTrue(annotation.getValue("names") instanceof CtNewArray);
    final CtNewArray names = annotation.getValue("names");
    assertEquals(2, names.getElements().size());
    assertEquals("foo", ((CtLiteral) names.getElements().get(0)).getValue());
    assertEquals("bar", ((CtLiteral) names.getElements().get(1)).getValue());
}
Also used : AnnotationFactory(spoon.reflect.factory.AnnotationFactory) CtNewArray(spoon.reflect.code.CtNewArray) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 CtNewArray (spoon.reflect.code.CtNewArray)1 AnnotationFactory (spoon.reflect.factory.AnnotationFactory)1