Search in sources :

Example 6 with JDTBasedSpoonCompiler

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;
}
Also used : StandardEnvironment(spoon.support.StandardEnvironment) Environment(spoon.compiler.Environment) JDTBasedSpoonCompiler(spoon.support.compiler.jdt.JDTBasedSpoonCompiler)

Example 7 with JDTBasedSpoonCompiler

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);
    }
}
Also used : SpoonException(spoon.SpoonException) Launcher(spoon.Launcher) JDTBasedSpoonCompiler(spoon.support.compiler.jdt.JDTBasedSpoonCompiler) Test(org.junit.Test)

Aggregations

JDTBasedSpoonCompiler (spoon.support.compiler.jdt.JDTBasedSpoonCompiler)7 Launcher (spoon.Launcher)5 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 CompilationUnit (org.eclipse.jdt.internal.compiler.batch.CompilationUnit)2 SpoonException (spoon.SpoonException)2 JDTBatchCompiler (spoon.support.compiler.jdt.JDTBatchCompiler)2 MalformedURLException (java.net.MalformedURLException)1 Before (org.junit.Before)1 Environment (spoon.compiler.Environment)1 Factory (spoon.reflect.factory.Factory)1 StandardEnvironment (spoon.support.StandardEnvironment)1