use of spoon.test.template.testclasses.InnerClassTemplate in project spoon by INRIA.
the class TemplateTest method testSubstituteInnerClass.
@Test
public void testSubstituteInnerClass() throws Exception {
// contract: the inner class is substituted well too and references to target class are substituted well
Launcher spoon = new Launcher();
spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/InnerClassTemplate.java"));
spoon.buildModel();
Factory factory = spoon.getFactory();
CtClass<?> result = factory.Class().create("x.Result");
new InnerClassTemplate().apply(result);
assertEquals(1, result.getNestedTypes().size());
CtType<?> innerType = result.getNestedType("Inner");
assertNotNull(innerType);
CtField<?> innerField = innerType.getField("innerField");
assertNotNull(innerField);
assertSame(innerType, innerField.getDeclaringType());
CtFieldReference<?> fr = innerType.filterChildren((CtFieldReference<?> e) -> true).first();
// check that reference to declaring type is correctly substituted
assertEquals("x.Result$Inner", fr.getDeclaringType().getQualifiedName());
}
Aggregations