Search in sources :

Example 1 with ReplEvalResult

use of org.jetbrains.kotlin.cli.common.repl.ReplEvalResult in project beakerx by twosigma.

the class KotlinCodeRunner method call.

@Override
public TryResult call() throws Exception {
    TryResult either;
    ClassLoader oldld = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(loader);
    InternalVariable.setValue(theOutput);
    try {
        theOutput.setOutputHandler();
        InternalVariable.setValue(theOutput);
        ReplEvalResult eval = repl.eval(this.codeToBeExecuted);
        either = interpretResult(eval);
    } catch (Throwable e) {
        if (e instanceof InvocationTargetException)
            e = ((InvocationTargetException) e).getTargetException();
        if ((e instanceof InterruptedException) || (e instanceof ThreadDeath)) {
            either = TryResult.createError(INTERUPTED_MSG);
        } else {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            either = TryResult.createError(sw.toString());
        }
    } finally {
        theOutput.clrOutputHandler();
        Thread.currentThread().setContextClassLoader(oldld);
    }
    return either;
}
Also used : ReplEvalResult(org.jetbrains.kotlin.cli.common.repl.ReplEvalResult) StringWriter(java.io.StringWriter) TryResult(com.twosigma.beakerx.TryResult) InvocationTargetException(java.lang.reflect.InvocationTargetException) PrintWriter(java.io.PrintWriter)

Aggregations

TryResult (com.twosigma.beakerx.TryResult)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ReplEvalResult (org.jetbrains.kotlin.cli.common.repl.ReplEvalResult)1