From db8d1b58b830090c60e2afda208c6b3df81f1062 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Tue, 21 Oct 2014 15:40:58 +0400 Subject: [PATCH] Debugger: log error on evaluating fragment with non-kotlin context --- .../debugger/evaluate/KotlinEvaluationBuilder.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt index 98c32a1b559..ba2f82cdbfc 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt +++ b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt @@ -72,6 +72,9 @@ import com.intellij.openapi.project.Project import org.jetbrains.jet.lang.resolve.DescriptorUtils import org.jetbrains.jet.codegen.StackValue import org.jetbrains.jet.lang.types.Flexibility +import org.jetbrains.jet.lang.psi.JetElement +import org.jetbrains.jet.plugin.util.attachment.attachmentsByPsiFile +import com.intellij.openapi.diagnostic.Attachment private val RECEIVER_NAME = "\$receiver" private val THIS_NAME = "this" @@ -87,6 +90,15 @@ object KotlinEvaluationBuilder: EvaluatorBuilder { throw EvaluateExceptionUtil.createEvaluateException("Couldn't evaluate kotlin expression in non-kotlin context") } + if (codeFragment.getContext() !is JetElement) { + val attachments = (attachmentsByPsiFile(position.getFile()) + + attachmentsByPsiFile(codeFragment) + + listOf(Attachment("breakpoint.info", "line: ${position.getLine()}")) + ).copyToArray() + logger.error("Trying to evaluate ${codeFragment.javaClass} with context ${codeFragment.getContext()?.javaClass}", *attachments) + throw EvaluateExceptionUtil.createEvaluateException("Couldn't evaluate kotlin expression in this context") + } + val packageName = file.getPackageDirective()?.getFqName()?.asString() if (packageName != null && packageName.isNotEmpty()) { codeFragment.addImportsFromString("import $packageName.*")