use of spoon.support.compiler.FileSystemFolder in project spoon by INRIA.
the class ResourceTest method testFileSystemFolder.
@Test
public void testFileSystemFolder() throws Exception {
String dir = "src/test/resources/spoon/test/api/";
FileSystemFolder fileSystemFolder = new FileSystemFolder(new File(dir));
// there is one file in api
assertEquals(2, fileSystemFolder.getAllFiles().size());
assertEquals(2, fileSystemFolder.getAllJavaFiles().size());
String entry = "src/test/resources/spoon/test/api/Foo.java";
FileSystemFile file = new FileSystemFile(new File(entry));
String entry1 = "src/test/resources/spoon/test/api/CommentedClass.java";
FileSystemFile file1 = new FileSystemFile(new File(entry1));
assertThat(fileSystemFolder.getAllFiles().contains(file), is(true));
assertThat(fileSystemFolder.getAllFiles().contains(file1), is(true));
}
use of spoon.support.compiler.FileSystemFolder in project spoon by INRIA.
the class ResourceTest method testVirtualFolder.
@Test
public void testVirtualFolder() throws Exception {
String dir = "src/test/resources/spoon/test/api/";
FileSystemFolder fileSystemFolder = new FileSystemFolder(new File(dir));
String dir2 = "src/test/resources/spoon/test/exceptions/";
FileSystemFolder fileSystemFolder2 = new FileSystemFolder(new File(dir2));
SpoonFolder folder = new VirtualFolder();
folder.addFolder(fileSystemFolder);
folder.addFolder(fileSystemFolder2);
assertEquals(4, folder.getAllFiles().size());
// the README is not a Java file
assertEquals(3, folder.getAllJavaFiles().size());
}
use of spoon.support.compiler.FileSystemFolder in project spoon by INRIA.
the class FileSystemFolderTest method jarFileIsNotSubfolder.
@Test
public void jarFileIsNotSubfolder() {
String folderPath = "./src/test/resources/folderWithJar";
FileSystemFolder folder = new FileSystemFolder(new File(folderPath));
List<SpoonFolder> subFolders = folder.getSubFolders();
assertTrue(subFolders.isEmpty());
}
use of spoon.support.compiler.FileSystemFolder in project spoon by INRIA.
the class TemplateTest method createTypeFromTemplate.
@Test
public void createTypeFromTemplate() throws Exception {
// contract: the Substitution API provides a method createTypeFromTemplate
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] { "--output-type", "nooutput" });
launcher.addTemplateResource(new FileSystemFolder("./src/test/java/spoon/test/template/testclasses/types"));
launcher.buildModel();
Factory factory = launcher.getFactory();
Map<String, Object> parameters = new HashMap<>();
// replace someMethod with genMethod
parameters.put("someMethod", "genMethod");
// contract: we can generate interface
final CtType<?> aIfaceModel = launcher.getFactory().Interface().get(AnIfaceModel.class);
CtType<?> genIface = Substitution.createTypeFromTemplate("generated.GenIface", aIfaceModel, parameters);
assertNotNull(genIface);
assertSame(genIface, factory.Type().get("generated.GenIface"));
CtMethod<?> generatedIfaceMethod = genIface.getMethod("genMethod");
assertNotNull(generatedIfaceMethod);
assertNull(genIface.getMethod("someMethod"));
// add new substitution request - replace AnIfaceModel by GenIface
parameters.put("AnIfaceModel", genIface.getReference());
// contract: we can generate class
final CtType<?> aClassModel = launcher.getFactory().Class().get(AClassModel.class);
CtType<?> genClass = Substitution.createTypeFromTemplate("generated.GenClass", aClassModel, parameters);
assertNotNull(genClass);
assertSame(genClass, factory.Type().get("generated.GenClass"));
CtMethod<?> generatedClassMethod = genClass.getMethod("genMethod");
assertNotNull(generatedClassMethod);
assertNull(genClass.getMethod("someMethod"));
assertTrue(generatedIfaceMethod != generatedClassMethod);
assertTrue(generatedClassMethod.isOverriding(generatedIfaceMethod));
// contract: we can generate enum
parameters.put("case1", "GOOD");
parameters.put("case2", "BETTER");
final CtType<?> aEnumModel = launcher.getFactory().Type().get(AnEnumModel.class);
CtEnum<?> genEnum = (CtEnum<?>) Substitution.createTypeFromTemplate("generated.GenEnum", aEnumModel, parameters);
assertNotNull(genEnum);
assertSame(genEnum, factory.Type().get("generated.GenEnum"));
assertEquals(2, genEnum.getEnumValues().size());
assertEquals("GOOD", genEnum.getEnumValues().get(0).getSimpleName());
assertEquals("BETTER", genEnum.getEnumValues().get(1).getSimpleName());
}
Aggregations