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