Search in sources :

Example 1 with EnumAccessTemplate

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

the class TemplateEnumAccessTest method testEnumAccessTest.

@Test
public void testEnumAccessTest() throws Exception {
    // contract: the template engine supports enum value access substitution
    Launcher launcher = new Launcher();
    launcher.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/EnumAccessTemplate.java"));
    launcher.buildModel();
    Factory factory = launcher.getFactory();
    CtClass<?> resultKlass = factory.Class().create(factory.Package().getOrCreate("spoon.test.template"), "EnumAccessResult");
    new EnumAccessTemplate(ElementType.FIELD, launcher.getFactory()).apply(resultKlass);
    assertEquals("java.lang.annotation.ElementType.FIELD.name()", resultKlass.getMethod("method").getBody().getStatement(0).toString());
    launcher.setSourceOutputDirectory(new File("./target/spooned/"));
    launcher.getModelBuilder().generateProcessedSourceFiles(OutputType.CLASSES);
    ModelUtils.canBeBuilt(new File("./target/spooned/spoon/test/template/EnumAccessResult.java"), 8);
}
Also used : Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) FileSystemFile(spoon.support.compiler.FileSystemFile) FileSystemFile(spoon.support.compiler.FileSystemFile) File(java.io.File) EnumAccessTemplate(spoon.test.template.testclasses.EnumAccessTemplate) Test(org.junit.Test)

Aggregations

File (java.io.File)1 Test (org.junit.Test)1 Launcher (spoon.Launcher)1 Factory (spoon.reflect.factory.Factory)1 FileSystemFile (spoon.support.compiler.FileSystemFile)1 EnumAccessTemplate (spoon.test.template.testclasses.EnumAccessTemplate)1