Add expression type string to the REPL API
PR-1131
This commit is contained in:
committed by
Ilya Chernikov
parent
8783f7a94e
commit
d165ea9ea7
+1
-1
@@ -110,7 +110,7 @@ open class GenericReplEvaluator(val baseClasspath: Iterable<File>,
|
|||||||
val resultField = scriptClass.getDeclaredField(SCRIPT_RESULT_FIELD_NAME).apply { isAccessible = true }
|
val resultField = scriptClass.getDeclaredField(SCRIPT_RESULT_FIELD_NAME).apply { isAccessible = true }
|
||||||
val resultValue: Any? = resultField.get(scriptInstance)
|
val resultValue: Any? = resultField.get(scriptInstance)
|
||||||
|
|
||||||
return if (compileResult.hasResult) ReplEvalResult.ValueResult(resultValue)
|
return if (compileResult.hasResult) ReplEvalResult.ValueResult(resultValue, compileResult.type)
|
||||||
else ReplEvalResult.UnitResult()
|
else ReplEvalResult.UnitResult()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,8 @@ sealed class ReplCompileResult : Serializable {
|
|||||||
val mainClassName: String,
|
val mainClassName: String,
|
||||||
val classes: List<CompiledClassData>,
|
val classes: List<CompiledClassData>,
|
||||||
val hasResult: Boolean,
|
val hasResult: Boolean,
|
||||||
val classpathAddendum: List<File>) : ReplCompileResult()
|
val classpathAddendum: List<File>,
|
||||||
|
val type: String?) : ReplCompileResult()
|
||||||
|
|
||||||
class Incomplete : ReplCompileResult()
|
class Incomplete : ReplCompileResult()
|
||||||
|
|
||||||
@@ -110,8 +111,8 @@ interface ReplEvalAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sealed class ReplEvalResult : Serializable {
|
sealed class ReplEvalResult : Serializable {
|
||||||
class ValueResult(val value: Any?) : ReplEvalResult() {
|
class ValueResult(val value: Any?, val type: String?) : ReplEvalResult() {
|
||||||
override fun toString(): String = "Result: $value"
|
override fun toString(): String = "$value : $type"
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnitResult : ReplEvalResult()
|
class UnitResult : ReplEvalResult()
|
||||||
|
|||||||
@@ -26,6 +26,12 @@ import org.jetbrains.kotlin.codegen.ClassBuilderFactories
|
|||||||
import org.jetbrains.kotlin.codegen.KotlinCodegenFacade
|
import org.jetbrains.kotlin.codegen.KotlinCodegenFacade
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
|
import org.jetbrains.kotlin.psi.KtBlockExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtScript
|
||||||
|
import org.jetbrains.kotlin.psi.KtScriptInitializer
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
|
||||||
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.script.KotlinScriptDefinition
|
import org.jetbrains.kotlin.script.KotlinScriptDefinition
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||||
@@ -96,12 +102,24 @@ open class GenericReplCompiler(disposable: Disposable,
|
|||||||
val generatedClassname = makeScriptBaseName(codeLine)
|
val generatedClassname = makeScriptBaseName(codeLine)
|
||||||
compilerState.history.push(LineId(codeLine), scriptDescriptor)
|
compilerState.history.push(LineId(codeLine), scriptDescriptor)
|
||||||
|
|
||||||
|
val expression = psiFile.getChildOfType<KtScript>()?.
|
||||||
|
getChildOfType<KtBlockExpression>()?.
|
||||||
|
getChildOfType<KtScriptInitializer>()?.
|
||||||
|
getChildOfType<KtExpression>()
|
||||||
|
|
||||||
|
val type = expression?.let {
|
||||||
|
compilerState.analyzerEngine.trace.bindingContext.getType(it)
|
||||||
|
}?.let {
|
||||||
|
DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(it)
|
||||||
|
}
|
||||||
|
|
||||||
return ReplCompileResult.CompiledClasses(LineId(codeLine),
|
return ReplCompileResult.CompiledClasses(LineId(codeLine),
|
||||||
compilerState.history.map { it.id },
|
compilerState.history.map { it.id },
|
||||||
generatedClassname,
|
generatedClassname,
|
||||||
generationState.factory.asList().map { CompiledClassData(it.relativePath, it.asByteArray()) },
|
generationState.factory.asList().map { CompiledClassData(it.relativePath, it.asByteArray()) },
|
||||||
generationState.replSpecific.hasResult,
|
generationState.replSpecific.hasResult,
|
||||||
classpathAddendum ?: emptyList())
|
classpathAddendum ?: emptyList(),
|
||||||
|
type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.types.expressions.typeInfoFactory
|
package org.jetbrains.kotlin.types.expressions.typeInfoFactory
|
||||||
|
|
||||||
import org.jetbrains.kotlin.psi.KtExpression
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer
|
|
||||||
import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo
|
import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -38,4 +36,4 @@ fun createTypeInfo(type: KotlinType?, context: ResolutionContext<*>): KotlinType
|
|||||||
|
|
||||||
fun noTypeInfo(dataFlowInfo: DataFlowInfo): KotlinTypeInfo = createTypeInfo(null, dataFlowInfo)
|
fun noTypeInfo(dataFlowInfo: DataFlowInfo): KotlinTypeInfo = createTypeInfo(null, dataFlowInfo)
|
||||||
|
|
||||||
fun noTypeInfo(context: ResolutionContext<*>): KotlinTypeInfo = noTypeInfo(context.dataFlowInfo)
|
fun noTypeInfo(context: ResolutionContext<*>): KotlinTypeInfo = noTypeInfo(context.dataFlowInfo)
|
||||||
Reference in New Issue
Block a user