Search in sources :

Example 1 with SubstitutionByExpressionTemplate

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

the class TemplateInvocationSubstitutionTest method testSubstitutionByExpression.

@Test
public void testSubstitutionByExpression() throws Exception {
    // contract: the template engine understands fields whose type extends from TemplateParameter as template parameter automatically. No need for extra annotation
    Launcher spoon = new Launcher();
    spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/SubstitutionByExpressionTemplate.java"));
    spoon.buildModel();
    Factory factory = spoon.getFactory();
    CtClass<?> resultKlass = factory.Class().create("Result");
    CtBlock<?> result = new SubstitutionByExpressionTemplate(factory.createLiteral("abc")).apply(resultKlass);
    assertEquals("java.lang.System.out.println(\"abc\".substring(1))", result.getStatement(0).toString());
}
Also used : InvocationSubstitutionByExpressionTemplate(spoon.test.template.testclasses.InvocationSubstitutionByExpressionTemplate) SubstitutionByExpressionTemplate(spoon.test.template.testclasses.SubstitutionByExpressionTemplate) 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 InvocationSubstitutionByExpressionTemplate (spoon.test.template.testclasses.InvocationSubstitutionByExpressionTemplate)1 SubstitutionByExpressionTemplate (spoon.test.template.testclasses.SubstitutionByExpressionTemplate)1