Debugger: log error on evaluating fragment with non-kotlin context

This commit is contained in:
Pavel V. Talanov
2014-10-21 15:40:58 +04:00
parent c3efe1b9b7
commit db8d1b58b8
@@ -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.*")