use of org.apache.zeppelin.kotlin.reflect.KotlinVariableInfo in project zeppelin by apache.
the class KotlinCompleter method completion.
public List<InterpreterCompletion> completion(String buf, int cursor, InterpreterContext interpreterContext) {
if (ctx == null) {
return new ArrayList<>(keywords);
}
List<InterpreterCompletion> result = new ArrayList<>();
for (KotlinVariableInfo var : ctx.getVars()) {
result.add(new InterpreterCompletion(var.getName(), var.getName(), shorten(var.getType())));
}
for (KotlinFunctionInfo fun : ctx.getFunctions()) {
result.add(new InterpreterCompletion(fun.getName(), fun.getName(), fun.toString(true)));
}
result.addAll(keywords);
return result;
}
use of org.apache.zeppelin.kotlin.reflect.KotlinVariableInfo in project zeppelin by apache.
the class KotlinInterpreterTest method testWrapper.
@Test
public void testWrapper() throws Exception {
String code = "import org.jetbrains.kotlin.cli.common.repl.InvokeWrapper\n" + "var k = 0\n" + "val wrapper = object : InvokeWrapper {\n" + " override operator fun <T> invoke(body: () -> T): T {\n" + " println(\"START\")\n" + " val result = body()\n" + " println(\"END\")\n" + " k = k + 1\n" + " return result\n" + " }\n" + "}\n" + "kc.setWrapper(wrapper)\n";
interpreter.interpret(code, context);
interpreter.interpret("println(\"hello!\")", context);
List<KotlinVariableInfo> vars = interpreter.getVariables();
for (KotlinVariableInfo v : vars) {
if (v.getName().equals("k")) {
assertEquals(1, v.getValue());
}
}
InterpreterResult result = interpreter.interpret("kc.vars", context);
assertTrue(result.message().get(0).getData().contains("k: kotlin.Int = 1"));
}
use of org.apache.zeppelin.kotlin.reflect.KotlinVariableInfo in project zeppelin by apache.
the class KotlinInterpreterTest method testVariables.
@Test
public void testVariables() throws Exception {
interpreter.interpret("val x = 1", context);
interpreter.interpret("val x = 2", context);
List<KotlinVariableInfo> vars = interpreter.getVariables();
assertEquals(2, vars.size());
KotlinVariableInfo varX = vars.stream().filter(info -> info.getName().equals("x")).findFirst().orElseGet(() -> {
Assert.fail();
return null;
});
assertEquals(2, varX.getValue());
assertEquals("kotlin.Int", varX.getType());
}
Aggregations