Search in sources :

Example 1 with SubstituteArrayAccessTemplate

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

the class TemplateArrayAccessTest method testArrayAccess.

@Test
public void testArrayAccess() throws Exception {
    // contract: the template engine supports variable access, typed as Array substitution
    Launcher spoon = new Launcher();
    spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/SubstituteArrayAccessTemplate.java"));
    spoon.buildModel();
    Factory factory = spoon.getFactory();
    CtClass<?> resultKlass = factory.Class().create("Result");
    CtStatement result = new SubstituteArrayAccessTemplate(new String[] { "a", null, "b" }).apply(resultKlass);
    assertEquals("new java.lang.String[]{ \"a\", null, \"b\" }.toString()", result.toString());
}
Also used : CtStatement(spoon.reflect.code.CtStatement) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) FileSystemFile(spoon.support.compiler.FileSystemFile) SubstituteArrayAccessTemplate(spoon.test.template.testclasses.SubstituteArrayAccessTemplate) Test(org.junit.Test)

Aggregations

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