Evaluator: Allow to evaluate expression on synthetic lines in .kt files

This commit is contained in:
Yan Zhulanow
2019-02-21 00:52:19 +03:00
parent 16266259f5
commit cadb70f64a
4 changed files with 35 additions and 2 deletions
@@ -89,12 +89,12 @@ object KotlinEvaluationBuilder : EvaluatorBuilder {
return EvaluatorBuilderImpl.getInstance()!!.build(codeFragment, position)
}
if (position.line < 0) {
if (position.line < 0 && position.file !is KtFile) {
evaluationException("Couldn't evaluate Kotlin expression at $position")
}
val file = position.file
if (file is KtFile) {
if (file is KtFile && position.line >= 0) {
val document = PsiDocumentManager.getInstance(file.project).getDocument(file)
if (document == null || document.lineCount < position.line) {
evaluationException(
@@ -0,0 +1,18 @@
package dataClassCopy
fun main() {
val a = Foo("foo")
//Breakpoint!
a.copy("bar")
}
data class Foo(val a: String)
// STEP_INTO: 1
// STEP_OUT: 1
// EXPRESSION: Foo("baz")
// RESULT: instance of dataClassCopy.Foo(id=ID): LdataClassCopy/Foo;
// EXPRESSION: a
// RESULT: Unresolved reference: a
@@ -0,0 +1,10 @@
LineBreakpoint created at dataClassCopy.kt:6
Run Java
Connected to the target VM
dataClassCopy.kt:6
dataClassCopy.kt:9
dataClassCopy.kt:-1
Compile bytecode for Foo("baz")
Disconnected from the target VM
Process finished with exit code 0
@@ -91,6 +91,11 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/collections.kt");
}
@TestMetadata("dataClassCopy.kt")
public void testDataClassCopy() throws Exception {
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/dataClassCopy.kt");
}
@TestMetadata("defaultParameterValues.kt")
public void testDefaultParameterValues() throws Exception {
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/defaultParameterValues.kt");