Search in sources :

Example 1 with CeylonModelLoader

use of com.redhat.ceylon.compiler.java.loader.CeylonModelLoader in project ceylon-compiler by ceylon.

the class ModelLoaderTests method verifyCompilerClassLoading.

protected void verifyCompilerClassLoading(String ceylon, final RunnableTest test, List<String> options) {
    // now compile the ceylon usage file
    JavacTaskImpl task2 = getCompilerTask(options, ceylon);
    // get the context to grab the declarations
    final Context context2 = task2.getContext();
    // declarations from the jar anymore because we've overridden the jar and the javac jar index is corrupted
    class Listener implements TaskListener {

        @Override
        public void started(TaskEvent e) {
        }

        @Override
        public void finished(TaskEvent e) {
            if (e.getKind() == Kind.ENTER) {
                CeylonModelLoader modelLoader = (CeylonModelLoader) CeylonModelLoader.instance(context2);
                test.test(modelLoader);
            }
        }
    }
    Listener listener = new Listener();
    task2.setTaskListener(listener);
    try {
        Boolean success = task2.call();
        Assert.assertTrue("Compilation failed", success);
    } catch (AssertionError x) {
        throw x;
    } catch (Throwable x) {
        // make sure we unwrap it
        while (x.getCause() != null) x = x.getCause();
        if (x instanceof Error)
            throw (Error) x;
        if (x instanceof RuntimeException)
            throw (RuntimeException) x;
        throw new RuntimeException(x);
    }
}
Also used : Context(com.sun.tools.javac.util.Context) JavacTaskImpl(com.sun.tools.javac.api.JavacTaskImpl) CeylonModelLoader(com.redhat.ceylon.compiler.java.loader.CeylonModelLoader) TaskListener(com.sun.source.util.TaskListener) TaskEvent(com.sun.source.util.TaskEvent) TaskListener(com.sun.source.util.TaskListener) CompilerError(com.redhat.ceylon.compiler.java.test.CompilerError)

Aggregations

CeylonModelLoader (com.redhat.ceylon.compiler.java.loader.CeylonModelLoader)1 CompilerError (com.redhat.ceylon.compiler.java.test.CompilerError)1 TaskEvent (com.sun.source.util.TaskEvent)1 TaskListener (com.sun.source.util.TaskListener)1 JavacTaskImpl (com.sun.tools.javac.api.JavacTaskImpl)1 Context (com.sun.tools.javac.util.Context)1