use of spoon.test.template.testclasses.InvocationTemplate in project spoon by INRIA.
the class TemplateTest method testTemplateInvocationSubstitution.
@Test
public void testTemplateInvocationSubstitution() throws Exception {
// contract: the template engine supports substitution of method names in method calls.
Launcher spoon = new Launcher();
spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/InvocationTemplate.java"));
spoon.buildModel();
Factory factory = spoon.getFactory();
CtClass<?> resultKlass = factory.Class().create("Result");
new InvocationTemplate(factory.Type().OBJECT, "hashCode").apply(resultKlass);
CtMethod<?> templateMethod = (CtMethod<?>) resultKlass.getElements(new NamedElementFilter<>(CtMethod.class, "invoke")).get(0);
CtStatement templateRoot = (CtStatement) templateMethod.getBody().getStatement(0);
// iface.$method$() becomes iface.hashCode()
assertEquals("iface.hashCode()", templateRoot.toString());
}
Aggregations