Search in sources :

Example 1 with InnerClassTemplate

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());
}
Also used : FieldAccessOfInnerClassTemplate(spoon.test.template.testclasses.FieldAccessOfInnerClassTemplate) InnerClassTemplate(spoon.test.template.testclasses.InnerClassTemplate) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) FileSystemFile(spoon.support.compiler.FileSystemFile) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Launcher (spoon.Launcher)1 Factory (spoon.reflect.factory.Factory)1 FileSystemFile (spoon.support.compiler.FileSystemFile)1 FieldAccessOfInnerClassTemplate (spoon.test.template.testclasses.FieldAccessOfInnerClassTemplate)1 InnerClassTemplate (spoon.test.template.testclasses.InnerClassTemplate)1