Move invokable parts to JSR223 only, remove unneeded code

This commit is contained in:
Ilya Chernikov
2016-12-09 17:14:09 +01:00
parent aab1759dc5
commit fc416476a8
9 changed files with 64 additions and 135 deletions
@@ -106,6 +106,7 @@ class KotlinRemoteReplCompiler(
}
}
// TODO: consider removing daemon eval completely - it is not required now and has questionable security. This will simplify daemon interface as well
class KotlinRemoteReplEvaluator(
disposable: Disposable,
compileService: CompileService,
@@ -138,6 +139,8 @@ class KotlinRemoteReplEvaluator(
operationsTracer = operationsTracer
), ReplEvaluator {
override val lastEvaluatedScript: ClassWithInstance? = null // not implemented, no need so far
// TODO: invokeWrapper is ignored here, and in the daemon the session wrapper is used instead; So consider to make it per call (avoid performance penalties though)
override fun eval(codeLine: ReplCodeLine, history: List<ReplCodeLine>, invokeWrapper: InvokeWrapper?): ReplEvalResult {
return compileService.remoteReplLineEval(sessionId, codeLine, history).get()
@@ -324,7 +324,7 @@ class CompileServiceImpl(
CompileService.CallResult.Error("Sorry, only JVM target platform is supported now")
else {
val disposable = Disposer.newDisposable()
val repl = KotlinJvmReplService(disposable, templateClasspath, templateClassName, scriptArgs, scriptArgsTypes, compilerMessagesOutputStream, evalOutputStream, evalErrorStream, evalInputStream, operationsTracer)
val repl = KotlinJvmReplService(disposable, templateClasspath, templateClassName, scriptArgs, scriptArgsTypes, compilerMessagesOutputStream, operationsTracer)
val sessionId = state.sessions.leaseSession(ClientOrSessionProxy(aliveFlagPath, repl, disposable))
CompileService.CallResult.Good(sessionId)
@@ -26,13 +26,11 @@ import org.jetbrains.kotlin.cli.jvm.repl.compileAndEval
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.daemon.common.DummyProfiler
import org.jetbrains.kotlin.daemon.common.RemoteInputStream
import org.jetbrains.kotlin.daemon.common.RemoteOperationsTracer
import org.jetbrains.kotlin.daemon.common.RemoteOutputStream
import org.jetbrains.kotlin.script.KotlinScriptDefinition
import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate
import org.jetbrains.kotlin.utils.PathUtil
import java.io.BufferedInputStream
import java.io.BufferedOutputStream
import java.io.File
import java.io.PrintStream
@@ -45,9 +43,6 @@ open class KotlinJvmReplService(
scriptArgs: Array<Any?>?,
scriptArgsTypes: Array<Class<*>>?,
compilerOutputStreamProxy: RemoteOutputStream,
evalOutputStream: RemoteOutputStream?,
evalErrorStream: RemoteOutputStream?,
evalInputStream: RemoteInputStream?,
val operationsTracer: RemoteOperationsTracer?
) : ReplCompiler, ReplEvaluator {
@@ -115,32 +110,12 @@ open class KotlinJvmReplService(
else GenericReplCompiler(disposable, scriptDef, configuration, messageCollector)
}
private val invokeWrapper : InvokeWrapper? by lazy {
if (evalOutputStream == null && evalErrorStream == null && evalInputStream == null) null
else object : InvokeWrapper {
val out = evalOutputStream?.let { PrintStream(BufferedOutputStream(RemoteOutputStreamClient(it, DummyProfiler()), REMOTE_STREAM_BUFFER_SIZE)) }
val err = evalErrorStream?.let { PrintStream(BufferedOutputStream(RemoteOutputStreamClient(it, DummyProfiler()), REMOTE_STREAM_BUFFER_SIZE)) }
val `in` = evalInputStream?.let { BufferedInputStream(RemoteInputStreamClient(it, DummyProfiler()), REMOTE_STREAM_BUFFER_SIZE) }
override operator fun<T> invoke(body: () -> T): T {
val prevOut = swapOrNull(out, { System.out }, { System.setOut(it) })
val prevErr = swapOrNull(err, { System.err }, { System.setErr(it) })
val prevIn = swapOrNull(`in`, { System.`in` }, { System.setIn(it) })
try {
return body()
}
finally {
prevIn?.let { System.setIn(prevIn) }
prevErr?.let { System.setErr(prevErr) }
prevOut?.let { System.setOut(prevOut) }
}
}
}
}
private val compiledEvaluator : GenericReplCompiledEvaluator by lazy {
GenericReplCompiledEvaluator(configuration.jvmClasspathRoots, null, scriptArgs, scriptArgsTypes)
}
override val lastEvaluatedScript: ClassWithInstance? get() = compiledEvaluator.lastEvaluatedScript
override fun check(codeLine: ReplCodeLine, history: List<ReplCodeLine>): ReplCheckResult {
operationsTracer?.before("check")
try {
@@ -180,10 +155,3 @@ open class KotlinJvmReplService(
}
}
}
private inline fun<T> swapOrNull(value: T?, get: () -> T, set: (T) -> Unit): T? =
value?.let {
val prevValue = get()
set(value)
prevValue
}