Search in sources :

Example 1 with KotlinFunctionInfo

use of org.apache.zeppelin.kotlin.reflect.KotlinFunctionInfo in project zeppelin by apache.

the class KotlinInterpreterTest method testReflectUtil.

@Test
public void testReflectUtil() throws Exception {
    String message = interpreter.interpret("1", context).message().get(0).getData();
    assertTrue(shorten(message).contains("Int = 1"));
    interpreter.interpret("val f = { l: List<Int> -> l[0] }", context);
    message = interpreter.interpret("f", context).message().get(0).getData();
    assertTrue(shorten(message).contains("(List<Int>) -> Int"));
    interpreter.interpret("fun first(s: String): Char = s[0]", context);
    KotlinFunctionInfo first = interpreter.getFunctions().get(0);
    assertEquals("fun first(String): Char", first.toString(true));
}
Also used : KotlinFunctionInfo(org.apache.zeppelin.kotlin.reflect.KotlinFunctionInfo) Test(org.junit.Test)

Example 2 with KotlinFunctionInfo

use of org.apache.zeppelin.kotlin.reflect.KotlinFunctionInfo 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;
}
Also used : InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) KotlinVariableInfo(org.apache.zeppelin.kotlin.reflect.KotlinVariableInfo) KotlinFunctionInfo(org.apache.zeppelin.kotlin.reflect.KotlinFunctionInfo) ArrayList(java.util.ArrayList)

Aggregations

KotlinFunctionInfo (org.apache.zeppelin.kotlin.reflect.KotlinFunctionInfo)2 ArrayList (java.util.ArrayList)1 InterpreterCompletion (org.apache.zeppelin.interpreter.thrift.InterpreterCompletion)1 KotlinVariableInfo (org.apache.zeppelin.kotlin.reflect.KotlinVariableInfo)1 Test (org.junit.Test)1