Search in sources :

Example 1 with ModelUtils.createFactory

use of spoon.testing.utils.ModelUtils.createFactory in project spoon by INRIA.

the class AnnotationValuesTest method testCtAnnotationAPI.

@Test
public void testCtAnnotationAPI() throws Exception {
    Factory factory = ModelUtils.createFactory();
    CtAnnotation<Annotation> annotation = factory.Core().createAnnotation();
    annotation.addValue("integers", 7);
    on(annotation).giveMeAnnotationValue("integers").isTypedBy(CtLiteral.class);
    annotation.addValue("integers", 42);
    on(annotation).giveMeAnnotationValue("integers").isTypedBy(CtNewArray.class);
    annotation.addValue("classes", String.class);
    on(annotation).giveMeAnnotationValue("classes").isTypedBy(CtFieldAccess.class);
    annotation.addValue("classes", Integer.class);
    on(annotation).giveMeAnnotationValue("classes").isTypedBy(CtNewArray.class);
    annotation.addValue("field", AnnotationValuesTest.class.getDeclaredField("i"));
    on(annotation).giveMeAnnotationValue("field").isTypedBy(CtFieldAccess.class);
}
Also used : ModelUtils.createFactory(spoon.testing.utils.ModelUtils.createFactory) Factory(spoon.reflect.factory.Factory) CtAnnotation(spoon.reflect.declaration.CtAnnotation) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Aggregations

Annotation (java.lang.annotation.Annotation)1 Test (org.junit.Test)1 CtAnnotation (spoon.reflect.declaration.CtAnnotation)1 Factory (spoon.reflect.factory.Factory)1 ModelUtils.createFactory (spoon.testing.utils.ModelUtils.createFactory)1