Implement Invocable on base evaluator and locally-evaluating JSR223 sample engines
fixes #KT-14707
This commit is contained in:
@@ -34,6 +34,11 @@
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-runtime</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test-junit</artifactId>
|
||||
|
||||
+4
-1
@@ -37,7 +37,7 @@ class KotlinJsr223JvmDaemonLocalEvalScriptEngine(
|
||||
getScriptArgs: (ScriptContext) -> Array<Any?>?,
|
||||
scriptArgsTypes: Array<Class<*>>?,
|
||||
compilerOut: OutputStream = System.err
|
||||
) : KotlinJsr223JvmScriptEngineBase(factory) {
|
||||
) : KotlinJsr223JvmScriptEngineBase(factory), KotlinJsr223JvmInvocableScriptEngine {
|
||||
|
||||
private val daemon by lazy { connectToCompileService(compilerJar) }
|
||||
|
||||
@@ -57,6 +57,9 @@ class KotlinJsr223JvmDaemonLocalEvalScriptEngine(
|
||||
// TODO: bindings passing works only once on the first eval, subsequent setContext/setBindings call have no effect. Consider making it dynamic, but take history into account
|
||||
val localEvaluator by lazy { GenericReplCompiledEvaluator(templateClasspath, Thread.currentThread().contextClassLoader, getScriptArgs(getContext()), scriptArgsTypes) }
|
||||
|
||||
override val replScriptInvoker: ReplScriptInvoker
|
||||
get() = localEvaluator
|
||||
|
||||
override fun eval(codeLine: ReplCodeLine, history: List<ReplCodeLine>): ReplEvalResult {
|
||||
|
||||
fun ReplCompileResult.Error.locationString() = if (location == CompilerMessageLocation.NO_LOCATION) ""
|
||||
|
||||
+6
-4
@@ -21,9 +21,7 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplCodeLine
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplEvalResult
|
||||
import org.jetbrains.kotlin.cli.common.repl.*
|
||||
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.GenericRepl
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
@@ -44,7 +42,7 @@ class KotlinJsr223JvmLocalScriptEngine(
|
||||
templateClassName: String,
|
||||
getScriptArgs: (ScriptContext) -> Array<Any?>?,
|
||||
scriptArgsTypes: Array<Class<*>>?
|
||||
) : KotlinJsr223JvmScriptEngineBase(factory) {
|
||||
) : KotlinJsr223JvmScriptEngineBase(factory), KotlinJsr223JvmInvocableScriptEngine {
|
||||
|
||||
data class MessageCollectorReport(val severity: CompilerMessageSeverity, val message: String, val location: CompilerMessageLocation)
|
||||
|
||||
@@ -105,6 +103,10 @@ class KotlinJsr223JvmLocalScriptEngine(
|
||||
put(CommonConfigurationKeys.MODULE_NAME, "kotlin-script")
|
||||
}
|
||||
|
||||
override val replScriptInvoker: ReplScriptInvoker
|
||||
get() = repl.scriptInvoker
|
||||
|
||||
|
||||
override fun eval(codeLine: ReplCodeLine, history: List<ReplCodeLine>): ReplEvalResult {
|
||||
val evalResult = repl.eval(codeLine, history)
|
||||
messageCollector.resetAndThrowOnErrors()
|
||||
|
||||
Reference in New Issue
Block a user