Direct mapping of script implicit receivers and env vars to parameters

This commit is contained in:
Ilya Chernikov
2018-07-24 15:19:34 +02:00
parent e1ee31b4ce
commit ac65aebb19
6 changed files with 53 additions and 89 deletions
@@ -92,14 +92,10 @@ abstract class AbstractCustomScriptCodegenTest : CodegenTestCase() {
private fun runScript(scriptClass: Class<*>, receivers: List<Any?>, environmentVars: Map<String, Any?>, scriptParams: List<Any>): Any? {
val ctorParams = arrayListOf<Any>()
if (receivers.isNotEmpty()) {
ctorParams.add(receivers.toTypedArray())
}
if (environmentVars.isNotEmpty()) {
ctorParams.add(environmentVars)
}
val ctorParams = arrayListOf<Any?>()
ctorParams.addAll(scriptParams)
ctorParams.addAll(receivers)
ctorParams.addAll(environmentVars.values)
val constructor = scriptClass.constructors[0]
return constructor.newInstance(*ctorParams.toTypedArray())