Implement support for "resX" result fields in REPL

This commit is contained in:
vitaly.khudobakhshov
2018-12-03 13:09:43 +01:00
committed by Ilya Chernikov
parent 79e577ae27
commit c901d6cebc
10 changed files with 128 additions and 32 deletions
@@ -108,18 +108,14 @@ open class GenericReplEvaluator(
historyActor.addFinal(compileResult.lineId, EvalClassWithInstanceAndLoader(scriptClass.kotlin, scriptInstance, classLoader, invokeWrapper))
val resultField = scriptClass.getDeclaredField(SCRIPT_RESULT_FIELD_NAME).apply { isAccessible = true }
val resultFieldName = scriptResultFieldName(compileResult.lineId.no)
val resultField = scriptClass.getDeclaredField(resultFieldName).apply { isAccessible = true }
val resultValue: Any? = resultField.get(scriptInstance)
return if (compileResult.hasResult) ReplEvalResult.ValueResult(resultValue, compileResult.type)
return if (compileResult.hasResult) ReplEvalResult.ValueResult(resultFieldName, resultValue, compileResult.type)
else ReplEvalResult.UnitResult()
}
}
companion object {
private val SCRIPT_RESULT_FIELD_NAME = "\$\$result"
}
}
private open class HistoryActionsForNoRepeat(val state: GenericReplEvaluatorState) {
@@ -121,8 +121,11 @@ interface ReplEvalAction {
}
sealed class ReplEvalResult : Serializable {
class ValueResult(val value: Any?, val type: String?) : ReplEvalResult() {
override fun toString(): String = "$value : $type"
class ValueResult(val name: String, val value: Any?, val type: String?) : ReplEvalResult() {
override fun toString(): String {
return "$name: $type = $value"
}
companion object { private val serialVersionUID: Long = 1L }
}
@@ -50,6 +50,8 @@ fun String.replNormalizeLineBreaks() = replace(END_LINE, "\n")
fun makeScriptBaseName(codeLine: ReplCodeLine) =
"Line_${codeLine.no}${if (codeLine.generation > REPL_CODE_LINE_FIRST_GEN) "_gen_${codeLine.generation}" else ""}"
fun scriptResultFieldName(lineNo: Int) = "res$lineNo"
fun renderReplStackTrace(cause: Throwable, startFromMethodName: String): String {
val newTrace = arrayListOf<StackTraceElement>()
var skip = true