use of spoon.test.template.testclasses.FieldAccessTemplate in project spoon by INRIA.
the class TemplateTest method testFieldAccessNameSubstitution.
@Test
public void testFieldAccessNameSubstitution() throws Exception {
// contract: the substitution of name of whole field is possible
Launcher spoon = new Launcher();
spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/FieldAccessTemplate.java"));
spoon.buildModel();
Factory factory = spoon.getFactory();
{
// contract: String value is substituted in String literal
final CtClass<?> result = (CtClass<?>) new FieldAccessTemplate("value").apply(factory.Class().create("x.X"));
assertEquals("int value;", result.getField("value").toString());
assertEquals("value = 7", result.getMethodsByName("m").get(0).getBody().getStatement(0).toString());
}
}
Aggregations