use of spoon.support.compiler.jdt.JDTBasedSpoonCompiler in project spoon by INRIA.
the class Launcher method createCompiler.
/**
* Creates a new Spoon Java compiler in order to process and compile Java
* source code.
*
* @param factory
* the factory this compiler works on
*/
public SpoonModelBuilder createCompiler(Factory factory) {
SpoonModelBuilder comp = new JDTBasedSpoonCompiler(factory);
Environment env = getEnvironment();
// building
comp.setBinaryOutputDirectory(jsapActualArgs.getFile("destination"));
// we don't have to set the source classpath
if (jsapActualArgs.contains("source-classpath")) {
comp.setSourceClasspath(jsapActualArgs.getString("source-classpath").split(System.getProperty("path.separator")));
}
env.debugMessage("destination: " + comp.getBinaryOutputDirectory());
env.debugMessage("source classpath: " + Arrays.toString(comp.getSourceClasspath()));
env.debugMessage("template classpath: " + Arrays.toString(comp.getTemplateClasspath()));
return comp;
}
use of spoon.support.compiler.jdt.JDTBasedSpoonCompiler in project spoon by INRIA.
the class ProcessingTest method testProcessorWithNoArgumentsInConstructor.
@Test
public void testProcessorWithNoArgumentsInConstructor() throws Exception {
/* throw correctly an exception when trying to use a processor with constructor with args */
Launcher l = new Launcher();
l.getEnvironment().setLevel(Level.ERROR.toString());
l.buildModel();
try {
new JDTBasedSpoonCompiler(l.getFactory()).instantiateAndProcess(Collections.singletonList("spoon.test.processing.ProcessingTest$WrongProcessor"));
fail();
} catch (SpoonException e) {
assertTrue(e.getMessage().startsWith("Unable to instantiate processor"));
assertTrue(e.getMessage().endsWith("Your processor should have a constructor with no arguments"));
// we are able to retrieve the exception parent
assertTrue(e.getCause() instanceof java.lang.InstantiationException);
}
}
Aggregations