Search in sources :

Example 1 with AnotherFieldAccessTemplate

use of spoon.test.template.testclasses.AnotherFieldAccessTemplate in project spoon by INRIA.

the class TemplateTest method testAnotherFieldAccessNameSubstitution.

@Test
public void testAnotherFieldAccessNameSubstitution() 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/AnotherFieldAccessTemplate.java"));
    spoon.buildModel();
    Factory factory = spoon.getFactory();
    {
        // contract: String value is substituted in String literal
        final CtClass<?> result = (CtClass<?>) new AnotherFieldAccessTemplate().apply(factory.Class().create("x.X"));
        assertEquals("int x;", result.getField("x").toString());
        assertEquals("int m_x;", result.getField("m_x").toString());
        assertEquals("java.lang.System.out.println(((x) + (m_x)))", result.getAnonymousExecutables().get(0).getBody().getStatement(0).toString());
    }
}
Also used : CtClass(spoon.reflect.declaration.CtClass) AnotherFieldAccessTemplate(spoon.test.template.testclasses.AnotherFieldAccessTemplate) 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 CtClass (spoon.reflect.declaration.CtClass)1 Factory (spoon.reflect.factory.Factory)1 FileSystemFile (spoon.support.compiler.FileSystemFile)1 AnotherFieldAccessTemplate (spoon.test.template.testclasses.AnotherFieldAccessTemplate)1