Evaluate expression: ClassCastException trying evaluate kotlin expression from java file

EA-56624 Fixed
This commit is contained in:
Natalia Ukhorskaya
2014-05-26 17:52:37 +04:00
parent 0c2120b578
commit 3557977588
@@ -77,12 +77,14 @@ object KotlinEvaluationBuilder: EvaluatorBuilder {
return EvaluatorBuilderImpl.getInstance()!!.build(codeFragment, position)
}
val elementAt = position.getElementAt()
if (elementAt != null) {
val packageName = (elementAt.getContainingFile() as JetFile).getPackageDirective()?.getFqName()?.asString()
if (packageName != null) {
codeFragment.addImportsFromString("import $packageName.*")
}
val file = position.getFile()
if (file !is JetFile) {
throw EvaluateExceptionUtil.createEvaluateException("Couldn't evaluate kotlin expression in non-kotlin context")
}
val packageName = file.getPackageDirective()?.getFqName()?.asString()
if (packageName != null) {
codeFragment.addImportsFromString("import $packageName.*")
}
return ExpressionEvaluatorImpl(KotlinEvaluator(codeFragment as JetCodeFragment, position))
}