use of spoon.support.compiler.FileSystemFile in project spoon by INRIA.
the class TemplateTest method testFieldAccessNameSubstitution.
@Test
public void testFieldAccessNameSubstitution() 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/FieldAccessTemplate.java"));
spoon.buildModel();
Factory factory = spoon.getFactory();
{
// contract: String value is substituted in String literal
final CtClass<?> result = (CtClass<?>) new FieldAccessTemplate("value").apply(factory.Class().create("x.X"));
assertEquals("int value;", result.getField("value").toString());
assertEquals("value = 7", result.getMethodsByName("m").get(0).getBody().getStatement(0).toString());
}
}
use of spoon.support.compiler.FileSystemFile 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());
}
use of spoon.support.compiler.FileSystemFile in project spoon by INRIA.
the class TemplateArrayAccessTest method testArrayLengthAccess.
@Test
public void testArrayLengthAccess() throws Exception {
// contract: the template engine replaces length of collection of parameter values by number
Launcher spoon = new Launcher();
spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/SubstituteArrayLengthTemplate.java"));
spoon.buildModel();
Factory factory = spoon.getFactory();
CtClass<?> resultKlass = factory.Class().create("Result");
CtStatement result = new SubstituteArrayLengthTemplate(new String[] { "a", null, "b" }).apply(resultKlass);
assertEquals("if (3 > 0);", result.toString());
}
Aggregations