REPL, Refactoring: Make ReplFromTerminal and ReplInterpreter not to implement ReplConfiguration
This commit is contained in:
@@ -20,7 +20,6 @@ import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.messages.GroupingMessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplEvalResult
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.messages.unescapeLineBreaks
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
@@ -36,8 +35,8 @@ import java.util.concurrent.Future
|
||||
class ReplFromTerminal(
|
||||
disposable: Disposable,
|
||||
compilerConfiguration: CompilerConfiguration,
|
||||
replConfiguration: ReplConfiguration
|
||||
) : ReplConfiguration by replConfiguration {
|
||||
private val replConfiguration: ReplConfiguration
|
||||
) {
|
||||
private val replInitializer: Future<ReplInterpreter> = Executors.newSingleThreadExecutor().submit(Callable {
|
||||
ReplInterpreter(disposable, compilerConfiguration, replConfiguration)
|
||||
})
|
||||
@@ -45,13 +44,17 @@ class ReplFromTerminal(
|
||||
private val replInterpreter: ReplInterpreter
|
||||
get() = replInitializer.get()
|
||||
|
||||
private val messageCollector: MessageCollector = compilerConfiguration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
private val writer get() = replConfiguration.writer
|
||||
|
||||
private val messageCollector = compilerConfiguration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
|
||||
private fun doRun() {
|
||||
try {
|
||||
writer.printlnWelcomeMessage("Welcome to Kotlin version ${KotlinCompilerVersion.VERSION} " +
|
||||
"(JRE ${System.getProperty("java.runtime.version")})")
|
||||
writer.printlnWelcomeMessage("Type :help for help, :quit for quit")
|
||||
with (writer) {
|
||||
printlnWelcomeMessage("Welcome to Kotlin version ${KotlinCompilerVersion.VERSION} " +
|
||||
"(JRE ${System.getProperty("java.runtime.version")})")
|
||||
printlnWelcomeMessage("Type :help for help, :quit for quit")
|
||||
}
|
||||
|
||||
// Display compiler messages related to configuration and CLI arguments, quit if there are errors
|
||||
val hasErrors = messageCollector.hasErrors()
|
||||
@@ -67,15 +70,15 @@ class ReplFromTerminal(
|
||||
}
|
||||
}
|
||||
catch (e: Exception) {
|
||||
exceptionReporter.report(e)
|
||||
replConfiguration.exceptionReporter.report(e)
|
||||
throw e
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
commandReader.flushHistory()
|
||||
replConfiguration.commandReader.flushHistory()
|
||||
}
|
||||
catch (e: Exception) {
|
||||
exceptionReporter.report(e)
|
||||
replConfiguration.exceptionReporter.report(e)
|
||||
throw e
|
||||
}
|
||||
|
||||
@@ -89,7 +92,7 @@ class ReplFromTerminal(
|
||||
}
|
||||
|
||||
private fun one(next: WhatNextAfterOneLine): WhatNextAfterOneLine {
|
||||
var line = commandReader.readLine(next) ?: return WhatNextAfterOneLine.QUIT
|
||||
var line = replConfiguration.commandReader.readLine(next) ?: return WhatNextAfterOneLine.QUIT
|
||||
|
||||
line = unescapeLineBreaks(line)
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ class ReplInterpreter(
|
||||
disposable: Disposable,
|
||||
private val configuration: CompilerConfiguration,
|
||||
private val replConfiguration: ReplConfiguration
|
||||
): ReplConfiguration by replConfiguration {
|
||||
|
||||
) {
|
||||
private val lineNumber = AtomicInteger()
|
||||
|
||||
private val previousIncompleteLines = arrayListOf<String>()
|
||||
@@ -92,12 +91,12 @@ class ReplInterpreter(
|
||||
try {
|
||||
|
||||
val evalRes = scriptEvaluator.compileAndEval(evalState, ReplCodeLine(lineNumber.getAndIncrement(), 0, fullText), null, object : InvokeWrapper {
|
||||
override fun <T> invoke(body: () -> T): T = executionInterceptor.execute(body)
|
||||
override fun <T> invoke(body: () -> T): T = replConfiguration.executionInterceptor.execute(body)
|
||||
})
|
||||
|
||||
when {
|
||||
evalRes !is ReplEvalResult.Incomplete -> previousIncompleteLines.clear()
|
||||
allowIncompleteLines -> previousIncompleteLines.add(line)
|
||||
replConfiguration.allowIncompleteLines -> previousIncompleteLines.add(line)
|
||||
else -> return ReplEvalResult.Error.CompileTime("incomplete code")
|
||||
}
|
||||
return evalRes
|
||||
|
||||
Reference in New Issue
Block a user