Fix params handling in JSR 223 for Idea, add simple test
This commit is contained in:
@@ -33,7 +33,9 @@ class KotlinJvmJsr223ScriptEngine4Idea(
|
||||
disposable: Disposable,
|
||||
private val factory: ScriptEngineFactory,
|
||||
templateClasspath: List<File>,
|
||||
templateClassName: String
|
||||
templateClassName: String,
|
||||
scriptArgs: Array<Any?>?,
|
||||
scriptArgsTypes: Array<Class<*>>?
|
||||
) : AbstractScriptEngine(), ScriptEngine {
|
||||
|
||||
private val daemon by lazy {
|
||||
@@ -61,7 +63,7 @@ class KotlinJvmJsr223ScriptEngine4Idea(
|
||||
}
|
||||
}
|
||||
|
||||
val localEvaluator by lazy { GenericReplCompiledEvaluator(emptyList(), Thread.currentThread().contextClassLoader) }
|
||||
val localEvaluator by lazy { GenericReplCompiledEvaluator(emptyList(), Thread.currentThread().contextClassLoader, scriptArgs, scriptArgsTypes) }
|
||||
|
||||
private var lineCount = 0
|
||||
|
||||
|
||||
+3
-1
@@ -38,7 +38,9 @@ class KotlinJvmJsr223StandardScriptEngineFactory4Idea : ScriptEngineFactory {
|
||||
Disposer.newDisposable(),
|
||||
this,
|
||||
listOf(PathUtil.getKotlinPathsForIdeaPlugin().runtimePath),
|
||||
"kotlin.script.StandardScriptTemplate")
|
||||
"kotlin.script.StandardScriptTemplate",
|
||||
arrayOf(emptyArray<String>()),
|
||||
null)
|
||||
|
||||
override fun getOutputStatement(toDisplay: String?): String = "print(\"$toDisplay\")"
|
||||
override fun getMethodCallSyntax(obj: String, m: String, vararg args: String): String = "$obj.$m(${args.joinToString()})"
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.repl
|
||||
|
||||
import com.intellij.testFramework.PlatformTestCase
|
||||
import org.junit.Test
|
||||
import javax.script.ScriptEngineManager
|
||||
import javax.script.ScriptException
|
||||
import kotlin.test.assertFails
|
||||
|
||||
class IdeaJsr223Test : PlatformTestCase() {
|
||||
|
||||
@Test
|
||||
fun testJsr223Engine() {
|
||||
val semgr = ScriptEngineManager()
|
||||
|
||||
val engine = semgr.getEngineByName("kotlin")
|
||||
|
||||
assertNotNull(engine)
|
||||
|
||||
val res0 = assertFails { engine.eval("val x =") }
|
||||
assertTrue("Unexpected check results: $res0", (res0 as? ScriptException)?.message?.contains("incomplete code") ?: false)
|
||||
|
||||
val res1 = engine.eval("val x = 5")
|
||||
assertNull("Unexpected eval result: $res1", res1)
|
||||
|
||||
val res2 = engine.eval("x + 2")
|
||||
assertEquals(7, res2)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user