KotlinInterpreter extends Interpreter { @Override public InterpreterResult interpret(String code, InterpreterContext context) throws InterpreterException{ Job<?> runningJob = getRunningJob(context.getParagraphId()); if (runningJob != null) { runningJob.info().put("CURRENT_THREAD", Thread.currentThread()); } return runWithOutput(code, context.out); } KotlinInterpreter(Properties properties); KotlinReplProperties getKotlinReplProperties(); @Override void open(); @Override void close(); @Override InterpreterResult interpret(String code,
                                     InterpreterContext context); @Override void cancel(InterpreterContext context); @Override FormType getFormType(); @Override int getProgress(InterpreterContext context); @Override List<InterpreterCompletion> completion(String buf, int cursor,
      InterpreterContext interpreterContext); List<KotlinVariableInfo> getVariables(); List<KotlinFunctionInfo> getFunctions();  }
@Test public void testIncomplete() throws Exception { InterpreterResult result = interpreter.interpret("val x =", context); assertEquals(ERROR, result.code()); }
@Test public void testCompileError() throws Exception { InterpreterResult result = interpreter.interpret("prinln(1)", context); assertEquals(ERROR, result.code()); assertEquals("Unresolved reference: prinln", result.message().get(0).getData().trim()); }
@Test public void testRuntimeError() throws Exception { InterpreterResult result = interpreter.interpret( "throw RuntimeException(\"Error Message\")", context); assertEquals(ERROR, result.code()); assertEquals("Error Message", result.message().get(0).getData().trim()); }
@Test public void testGetVariablesFromCode() throws Exception { interpreter.interpret("val x = 1", context); interpreter.interpret("val y = 2", context); interpreter.interpret("val x = 3", context); interpreter.interpret("val l = listOf(1,2,3)", context); interpreter.interpret("kc.showVars()", context); System.out.println(output); assertTrue(output.contains("x: Int = 3")); assertTrue(output.contains("y: Int = 2")); assertTrue(output.contains("l: List<Int> = [1, 2, 3]")); InterpreterResult res = interpreter.interpret("kc.vars = null", context); assertTrue(res.message().get(0).getData().contains("Val cannot be reassigned")); }