Search in sources :

Example 1 with SubstituteRootTemplate

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

the class TemplateTest method testStatementTemplateRootSubstitution.

@Test
public void testStatementTemplateRootSubstitution() throws Exception {
    // contract: the template engine supports substitution of root element
    Launcher spoon = new Launcher();
    spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/SubstituteRootTemplate.java"));
    spoon.buildModel();
    Factory factory = spoon.getFactory();
    CtClass<?> templateClass = factory.Class().get(SubstituteRootTemplate.class);
    CtBlock<Void> templateParam = (CtBlock) templateClass.getMethod("sampleBlock").getBody();
    CtClass<?> resultKlass = factory.Class().create("Result");
    CtStatement result = new SubstituteRootTemplate(templateParam).apply(resultKlass);
    assertEquals("java.lang.String s = \"Spoon is cool!\"", ((CtBlock) result).getStatement(0).toString());
}
Also used : CtBlock(spoon.reflect.code.CtBlock) CtStatement(spoon.reflect.code.CtStatement) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) FileSystemFile(spoon.support.compiler.FileSystemFile) SubstituteRootTemplate(spoon.test.template.testclasses.SubstituteRootTemplate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Launcher (spoon.Launcher)1 CtBlock (spoon.reflect.code.CtBlock)1 CtStatement (spoon.reflect.code.CtStatement)1 Factory (spoon.reflect.factory.Factory)1 FileSystemFile (spoon.support.compiler.FileSystemFile)1 SubstituteRootTemplate (spoon.test.template.testclasses.SubstituteRootTemplate)1