use of spoon.SpoonModelBuilder in project spoon by INRIA.
the class PackageTest method testAnnotationOnPackage.
@Test
public void testAnnotationOnPackage() throws Exception {
Launcher launcher = new Launcher();
Factory factory = launcher.getFactory();
factory.getEnvironment().setAutoImports(false);
SpoonModelBuilder compiler = launcher.createCompiler(factory);
launcher.setSourceOutputDirectory("./target/spooned/");
compiler.addInputSource(new File("./src/test/java/spoon/test/pkg/testclasses/"));
compiler.build();
compiler.generateProcessedSourceFiles(OutputType.CLASSES);
final SpoonModelBuilder newCompiler = launcher.createCompiler(launcher.createFactory());
newCompiler.addInputSource(new File("./target/spooned/spoon/test/pkg/testclasses/"));
try {
assertTrue(newCompiler.build());
} catch (Exception ignore) {
fail();
}
}
use of spoon.SpoonModelBuilder in project spoon by INRIA.
the class DefaultPrettyPrinterTest method testPrintAMethodWithImports.
@Test
public void testPrintAMethodWithImports() throws Exception {
final Launcher launcher = new Launcher();
final Factory factory = launcher.getFactory();
factory.getEnvironment().setAutoImports(true);
final SpoonModelBuilder compiler = launcher.createCompiler();
compiler.addInputSource(new File("./src/test/java/spoon/test/prettyprinter/testclasses/"));
compiler.build();
final String expected = "public List<?> aMethod() {" + nl + " return new ArrayList<>();" + nl + "}";
final CtClass<?> aClass = (CtClass<?>) factory.Type().get(AClass.class);
assertEquals(expected, aClass.getMethodsByName("aMethod").get(0).toString());
final CtConstructorCall<?> constructorCall = aClass.getElements(new TypeFilter<CtConstructorCall<?>>(CtConstructorCall.class)).get(0);
final CtTypeReference<?> ctTypeReference = constructorCall.getType().getActualTypeArguments().get(0);
assertTrue(ctTypeReference.isImplicit());
assertEquals("Object", ctTypeReference.getSimpleName());
}
use of spoon.SpoonModelBuilder in project spoon by INRIA.
the class PropertiesTest method testNonExistingDirectory.
@Test
public void testNonExistingDirectory() throws Exception {
File tempFile = File.createTempFile("SPOON", "SPOON");
tempFile.delete();
Launcher spoon = new Launcher();
Factory factory = spoon.createFactory();
SpoonModelBuilder compiler = spoon.createCompiler(factory, SpoonResourceHelper.resources("./src/test/java/spoon/test/properties/testclasses/Sample.java"));
compiler.build();
compiler.instantiateAndProcess(Arrays.asList(SimpleProcessor.class.getName()));
assertEquals(factory.getEnvironment().getErrorCount(), 0);
}
use of spoon.SpoonModelBuilder in project spoon by INRIA.
the class VisibilityTest method testVisibilityOfClassesNamedByClassesInJavaLangPackage.
@Test
public void testVisibilityOfClassesNamedByClassesInJavaLangPackage() throws Exception {
final File sourceOutputDir = new File("target/spooned/spoon/test/visibility_package/testclasses");
final Launcher launcher = new Launcher();
launcher.getEnvironment().setAutoImports(true);
launcher.getEnvironment().setSourceOutputDirectory(sourceOutputDir);
final Factory factory = launcher.getFactory();
final SpoonModelBuilder compiler = launcher.createCompiler();
compiler.addInputSource(new File("./src/test/java/spoon/test/visibility/testclasses/"));
compiler.setSourceOutputDirectory(sourceOutputDir);
compiler.build();
compiler.generateProcessedSourceFiles(OutputType.CLASSES);
// Class must be imported.
final CtClass<?> aDouble = (CtClass<?>) factory.Type().get(spoon.test.visibility.testclasses.internal.Double.class);
assertNotNull(aDouble);
assertEquals(spoon.test.visibility.testclasses.internal.Double.class, aDouble.getActualClass());
// Class mustn't be imported.
final CtClass<?> aFloat = (CtClass<?>) factory.Type().get(spoon.test.visibility.testclasses.Float.class);
assertNotNull(aFloat);
assertEquals(spoon.test.visibility.testclasses.Float.class, aFloat.getActualClass());
canBeBuilt(new File("./target/spooned/spoon/test/visibility_package/testclasses/"), 7);
}
use of spoon.SpoonModelBuilder in project dspot by STAMP-project.
the class DSpotCompiler method compile.
public static boolean compile(String pathToSources, String dependencies, File binaryOutputDirectory) {
Launcher launcher = new Launcher();
if (Main.verbose) {
launcher.getEnvironment().setLevel("DEBUG");
}
launcher.getEnvironment().setNoClasspath(true);
launcher.getEnvironment().setCommentEnabled(true);
launcher.getEnvironment().setOutputType(OutputType.CLASSES);
if (!new File("target/dspot/dependencies/compare").exists()) {
DSpotUtils.copyPackageFromResources("fr/inria/diversify/compare/", "MethodsHandler", "ObjectLog", "Observation", "Utils");
}
String[] sourcesArray = (pathToSources + PATH_SEPARATOR).split(PATH_SEPARATOR);
Arrays.stream(sourcesArray).forEach(launcher::addInputResource);
String[] dependenciesArray = dependencies.split(PATH_SEPARATOR);
launcher.getModelBuilder().setSourceClasspath(dependenciesArray);
launcher.buildModel();
SpoonModelBuilder modelBuilder = launcher.getModelBuilder();
modelBuilder.setBinaryOutputDirectory(binaryOutputDirectory);
return modelBuilder.compile(SpoonModelBuilder.InputType.CTTYPES);
}
Aggregations