Direct mapping of script implicit receivers and env vars to parameters
This commit is contained in:
@@ -33,11 +33,9 @@ import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.UnderscoreUtilKt;
|
import org.jetbrains.kotlin.resolve.calls.util.UnderscoreUtilKt;
|
||||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes;
|
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature;
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.script.ScriptEnvironmentPropertyDescriptor;
|
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor;
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor;
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||||
@@ -521,10 +519,7 @@ public class PropertyCodegen {
|
|||||||
|
|
||||||
FunctionGenerationStrategy strategy;
|
FunctionGenerationStrategy strategy;
|
||||||
if (accessor == null || !accessor.hasBody()) {
|
if (accessor == null || !accessor.hasBody()) {
|
||||||
if (accessorDescriptor.getCorrespondingProperty() instanceof ScriptEnvironmentPropertyDescriptor) {
|
if (p instanceof KtProperty && ((KtProperty) p).hasDelegate()) {
|
||||||
strategy = new ScriptEnvPropertyAccessorStrategy(state, accessorDescriptor);
|
|
||||||
}
|
|
||||||
else if (p instanceof KtProperty && ((KtProperty) p).hasDelegate()) {
|
|
||||||
strategy = new DelegatedPropertyAccessorStrategy(state, accessorDescriptor);
|
strategy = new DelegatedPropertyAccessorStrategy(state, accessorDescriptor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -637,42 +632,6 @@ public class PropertyCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ScriptEnvPropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased {
|
|
||||||
public static final Type MAP_IFACE_TYPE = Type.getObjectType("java/util/Map");
|
|
||||||
public static final String MAP_FIELD_NAME = "$scriptEnvironment";
|
|
||||||
private final PropertyAccessorDescriptor propertyAccessorDescriptor;
|
|
||||||
|
|
||||||
public ScriptEnvPropertyAccessorStrategy(@NotNull GenerationState state, @NotNull PropertyAccessorDescriptor descriptor) {
|
|
||||||
super(state);
|
|
||||||
this.propertyAccessorDescriptor = descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
|
||||||
InstructionAdapter v = codegen.v;
|
|
||||||
|
|
||||||
Type scriptType = state.getTypeMapper().mapOwner(propertyAccessorDescriptor);
|
|
||||||
String scriptInternalName = scriptType.getInternalName();
|
|
||||||
v.load(0, scriptType);
|
|
||||||
v.getfield(scriptInternalName, MAP_FIELD_NAME, MAP_IFACE_TYPE.getDescriptor());
|
|
||||||
v.aconst(propertyAccessorDescriptor.getCorrespondingProperty().getName().asString());
|
|
||||||
if (propertyAccessorDescriptor instanceof PropertyGetterDescriptor) {
|
|
||||||
v.invokeinterface(MAP_IFACE_TYPE.getInternalName(), "get",
|
|
||||||
Type.getMethodDescriptor(AsmTypes.OBJECT_TYPE, AsmTypes.OBJECT_TYPE));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Type valueType = state.getTypeMapper().mapType(propertyAccessorDescriptor.getCorrespondingProperty());
|
|
||||||
v.load(1, valueType);
|
|
||||||
StackValue.coerce(valueType, AsmTypes.OBJECT_TYPE, v);
|
|
||||||
v.visitMethodInsn(Opcodes.INVOKEINTERFACE, MAP_IFACE_TYPE.getInternalName(), "put",
|
|
||||||
Type.getMethodDescriptor(Type.BOOLEAN_TYPE, AsmTypes.OBJECT_TYPE, AsmTypes.OBJECT_TYPE), true);
|
|
||||||
}
|
|
||||||
Type returnType = state.getTypeMapper().mapReturnType(propertyAccessorDescriptor);
|
|
||||||
StackValue.coerce(AsmTypes.OBJECT_TYPE, returnType, v);
|
|
||||||
v.areturn(returnType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void genDelegate(@NotNull PropertyDescriptor delegate, @NotNull PropertyDescriptor delegateTo, @NotNull StackValue field) {
|
public void genDelegate(@NotNull PropertyDescriptor delegate, @NotNull PropertyDescriptor delegateTo, @NotNull StackValue field) {
|
||||||
ClassDescriptor toClass = (ClassDescriptor) delegateTo.getContainingDeclaration();
|
ClassDescriptor toClass = (ClassDescriptor) delegateTo.getContainingDeclaration();
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny
|
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces
|
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces
|
||||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
|
||||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE
|
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin.Companion.NO_ORIGIN
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin.Companion.NO_ORIGIN
|
||||||
@@ -61,10 +60,6 @@ class ScriptCodegen private constructor(
|
|||||||
|
|
||||||
override fun generateSyntheticPartsBeforeBody() {
|
override fun generateSyntheticPartsBeforeBody() {
|
||||||
generatePropertyMetadataArrayFieldIfNeeded(classAsmType)
|
generatePropertyMetadataArrayFieldIfNeeded(classAsmType)
|
||||||
scriptContext.scriptDescriptor.scriptEnvironmentProperties.forEach {
|
|
||||||
propertyCodegen.generateGetter(null, it, null)
|
|
||||||
propertyCodegen.generateSetter(null, it, null)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun generateSyntheticPartsAfterBody() {}
|
override fun generateSyntheticPartsAfterBody() {}
|
||||||
@@ -127,6 +122,12 @@ class ScriptCodegen private constructor(
|
|||||||
field.store(value, iv)
|
field.store(value, iv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun genFieldFromParam(fieldClassType: Type, paramIndex: Int, name: String) {
|
||||||
|
val value = StackValue.local(paramIndex, fieldClassType)
|
||||||
|
val field = StackValue.field(fieldClassType, classType, name, false, StackValue.local(0, classType))
|
||||||
|
field.store(value, iv)
|
||||||
|
}
|
||||||
|
|
||||||
if (!scriptContext.earlierScripts.isEmpty()) {
|
if (!scriptContext.earlierScripts.isEmpty()) {
|
||||||
val scriptsParamIndex = frameMap.enterTemp(AsmUtil.getArrayType(OBJECT_TYPE))
|
val scriptsParamIndex = frameMap.enterTemp(AsmUtil.getArrayType(OBJECT_TYPE))
|
||||||
|
|
||||||
@@ -145,15 +146,11 @@ class ScriptCodegen private constructor(
|
|||||||
|
|
||||||
iv.load(0, classType)
|
iv.load(0, classType)
|
||||||
|
|
||||||
fun Int.incrementIf(cond: Boolean): Int = if (cond) plus(1) else this
|
|
||||||
val valueParamStart = 1
|
|
||||||
.incrementIf(scriptContext.earlierScripts.isNotEmpty())
|
|
||||||
|
|
||||||
val valueParameters = scriptDescriptor.unsubstitutedPrimaryConstructor.valueParameters
|
val valueParameters = scriptDescriptor.unsubstitutedPrimaryConstructor.valueParameters
|
||||||
for (superclassParam in ctorDesc.valueParameters) {
|
for (superclassParam in ctorDesc.valueParameters) {
|
||||||
val valueParam = valueParameters.first { it.name == superclassParam.name }
|
val valueParam = valueParameters.first { it.name == superclassParam.name }
|
||||||
val paramType = typeMapper.mapType(valueParam.type)
|
val paramType = typeMapper.mapType(valueParam.type)
|
||||||
iv.load(valueParam!!.index + valueParamStart, paramType)
|
iv.load(valueParam!!.index + scriptContext.ctorValueParametersStart + 1, paramType)
|
||||||
frameMap.enterTemp(paramType)
|
frameMap.enterTemp(paramType)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,21 +164,17 @@ class ScriptCodegen private constructor(
|
|||||||
}
|
}
|
||||||
iv.load(0, classType)
|
iv.load(0, classType)
|
||||||
|
|
||||||
if (scriptDefinition.implicitReceivers.isNotEmpty()) {
|
scriptDescriptor.implicitReceivers.forEachIndexed { receiverIndex, receiver ->
|
||||||
val receiversParamIndex = frameMap.enterTemp(AsmUtil.getArrayType(OBJECT_TYPE))
|
val receiversParamIndex = frameMap.enterTemp(AsmUtil.getArrayType(OBJECT_TYPE))
|
||||||
|
val name = scriptContext.getImplicitReceiverName(receiverIndex)
|
||||||
scriptContext.receiverDescriptors.forEachIndexed { receiverIndex, receiver ->
|
genFieldFromParam(typeMapper.mapClass(receiver), receiversParamIndex, name)
|
||||||
val name = scriptContext.getImplicitReceiverName(receiverIndex)
|
|
||||||
genFieldFromArrayElement(receiver, receiversParamIndex, receiverIndex, name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scriptDefinition.environmentVariables.isNotEmpty()) {
|
scriptDescriptor.scriptEnvironmentProperties.forEachIndexed { envVarIndex, envVar ->
|
||||||
val envParamIndex = frameMap.enterTemp(AsmTypes.OBJECT_TYPE)
|
val fieldClassType = typeMapper.mapType(envVar)
|
||||||
val mapType = PropertyCodegen.ScriptEnvPropertyAccessorStrategy.MAP_IFACE_TYPE
|
val envVarParamIndex = frameMap.enterTemp(fieldClassType)
|
||||||
iv.load(0, classType)
|
val name = scriptContext.getEnvironmentVarName(envVarIndex)
|
||||||
iv.load(envParamIndex, mapType)
|
genFieldFromParam(fieldClassType, envVarParamIndex, name)
|
||||||
iv.putfield(classType.internalName, PropertyCodegen.ScriptEnvPropertyAccessorStrategy.MAP_FIELD_NAME, mapType.descriptor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val codegen = ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, methodContext, state, this)
|
val codegen = ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, methodContext, state, this)
|
||||||
@@ -216,12 +209,12 @@ class ScriptCodegen private constructor(
|
|||||||
null
|
null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (scriptContext.scriptDescriptor.scriptEnvironmentProperties.isNotEmpty()) {
|
for (envVarIndex in scriptDescriptor.scriptEnvironmentProperties.indices) {
|
||||||
classBuilder.newField(
|
classBuilder.newField(
|
||||||
NO_ORIGIN,
|
NO_ORIGIN,
|
||||||
ACC_PUBLIC or ACC_FINAL,
|
ACC_PUBLIC or ACC_FINAL,
|
||||||
PropertyCodegen.ScriptEnvPropertyAccessorStrategy.MAP_FIELD_NAME,
|
scriptContext.getEnvironmentVarName(envVarIndex),
|
||||||
PropertyCodegen.ScriptEnvPropertyAccessorStrategy.MAP_IFACE_TYPE.descriptor,
|
scriptContext.getEnvironmentVarType(envVarIndex).descriptor,
|
||||||
null,
|
null,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.psi.KtExpression
|
|||||||
import org.jetbrains.kotlin.psi.KtScript
|
import org.jetbrains.kotlin.psi.KtScript
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
||||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.script.ScriptEnvironmentDescriptor
|
import org.jetbrains.kotlin.resolve.lazy.descriptors.script.ScriptEnvironmentDescriptor
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
@@ -64,7 +65,16 @@ class ScriptContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getImplicitReceiverName(index: Int): String = "\$\$implicitReceiver$index"
|
val ctorValueParametersStart = if (earlierScripts.isNotEmpty()) 1 else 0
|
||||||
|
|
||||||
|
private val ctorImplicitReceiversParametersStart =
|
||||||
|
ctorValueParametersStart + (scriptDescriptor.getSuperClassNotAny()?.unsubstitutedPrimaryConstructor?.valueParameters?.size ?: 0)
|
||||||
|
|
||||||
|
private val ctorEnvironmentVarsParametersStart =
|
||||||
|
ctorImplicitReceiversParametersStart + scriptDescriptor.implicitReceivers.size
|
||||||
|
|
||||||
|
fun getImplicitReceiverName(index: Int): String =
|
||||||
|
scriptDescriptor.unsubstitutedPrimaryConstructor.valueParameters[ctorImplicitReceiversParametersStart + index].name.identifier
|
||||||
|
|
||||||
fun getImplicitReceiverType(index: Int): Type? {
|
fun getImplicitReceiverType(index: Int): Type? {
|
||||||
val receivers = script.kotlinScriptDefinition.value.implicitReceivers
|
val receivers = script.kotlinScriptDefinition.value.implicitReceivers
|
||||||
@@ -72,6 +82,11 @@ class ScriptContext(
|
|||||||
return kClass?.java?.classId?.let(AsmUtil::asmTypeByClassId)
|
return kClass?.java?.classId?.let(AsmUtil::asmTypeByClassId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getEnvironmentVarName(index: Int): String =
|
||||||
|
scriptDescriptor.unsubstitutedPrimaryConstructor.valueParameters[ctorEnvironmentVarsParametersStart + index].name.identifier
|
||||||
|
|
||||||
|
fun getEnvironmentVarType(index: Int): Type = typeMapper.mapType(scriptDescriptor.scriptEnvironmentProperties[index].type)
|
||||||
|
|
||||||
fun getOuterReceiverExpression(prefix: StackValue?, thisOrOuterClass: ClassDescriptor): StackValue {
|
fun getOuterReceiverExpression(prefix: StackValue?, thisOrOuterClass: ClassDescriptor): StackValue {
|
||||||
if (thisOrOuterClass is ScriptEnvironmentDescriptor) {
|
if (thisOrOuterClass is ScriptEnvironmentDescriptor) {
|
||||||
return prefix ?: StackValue.LOCAL_0
|
return prefix ?: StackValue.LOCAL_0
|
||||||
|
|||||||
+13
-12
@@ -22,10 +22,10 @@ import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
|
||||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||||
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider
|
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||||
|
|
||||||
class LazyScriptClassMemberScope(
|
class LazyScriptClassMemberScope(
|
||||||
@@ -39,16 +39,13 @@ class LazyScriptClassMemberScope(
|
|||||||
val baseClass = scriptDescriptor.baseClassDescriptor()
|
val baseClass = scriptDescriptor.baseClassDescriptor()
|
||||||
val baseConstructorDescriptor = baseClass?.unsubstitutedPrimaryConstructor
|
val baseConstructorDescriptor = baseClass?.unsubstitutedPrimaryConstructor
|
||||||
if (baseConstructorDescriptor != null) {
|
if (baseConstructorDescriptor != null) {
|
||||||
val builtIns = scriptDescriptor.builtIns
|
val implicitReceiversParamTypes =
|
||||||
val implicitReceiversParamType =
|
scriptDescriptor.implicitReceivers.mapIndexed { idx, receiver ->
|
||||||
if (scriptDescriptor.scriptDefinition().implicitReceivers.isEmpty()) null
|
"$IMPLICIT_RECEIVER_PARAM_NAME_PREFIX$idx" to receiver.defaultType
|
||||||
else {
|
|
||||||
"implicitReceivers" to builtIns.array.substitute(builtIns.anyType)!!
|
|
||||||
}
|
}
|
||||||
val environmentVarsParamType =
|
val environmentVarsParamTypes =
|
||||||
if (scriptDescriptor.scriptDefinition().environmentVariables.isEmpty()) null
|
scriptDescriptor.scriptEnvironmentProperties.map {
|
||||||
else {
|
it.name.identifier to it.type
|
||||||
"environmentVariables" to builtIns.map.substitute(builtIns.stringType, builtIns.nullableAnyType)!!
|
|
||||||
}
|
}
|
||||||
val annotations = baseConstructorDescriptor.annotations
|
val annotations = baseConstructorDescriptor.annotations
|
||||||
val constructorDescriptor = ClassConstructorDescriptorImpl.create(
|
val constructorDescriptor = ClassConstructorDescriptorImpl.create(
|
||||||
@@ -56,7 +53,7 @@ class LazyScriptClassMemberScope(
|
|||||||
)
|
)
|
||||||
var paramsIndexBase = baseConstructorDescriptor.valueParameters.lastIndex + 1
|
var paramsIndexBase = baseConstructorDescriptor.valueParameters.lastIndex + 1
|
||||||
val syntheticParameters =
|
val syntheticParameters =
|
||||||
listOf(implicitReceiversParamType, environmentVarsParamType).mapNotNull { param: Pair<String, KotlinType>? ->
|
(implicitReceiversParamTypes + environmentVarsParamTypes).mapNotNull { param: Pair<String, KotlinType> ->
|
||||||
if (param == null) null
|
if (param == null) null
|
||||||
else ValueParameterDescriptorImpl(
|
else ValueParameterDescriptorImpl(
|
||||||
constructorDescriptor,
|
constructorDescriptor,
|
||||||
@@ -95,6 +92,10 @@ class LazyScriptClassMemberScope(
|
|||||||
|
|
||||||
override fun createPropertiesFromPrimaryConstructorParameters(name: Name, result: MutableSet<PropertyDescriptor>) {
|
override fun createPropertiesFromPrimaryConstructorParameters(name: Name, result: MutableSet<PropertyDescriptor>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val IMPLICIT_RECEIVER_PARAM_NAME_PREFIX = "\$\$implicitReceiver"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ClassDescriptor.substitute(vararg types: KotlinType): KotlinType? =
|
private fun ClassDescriptor.substitute(vararg types: KotlinType): KotlinType? =
|
||||||
|
|||||||
+2
-2
@@ -22,8 +22,8 @@ class ScriptEnvironmentPropertyDescriptor(
|
|||||||
script,
|
script,
|
||||||
null,
|
null,
|
||||||
Annotations.EMPTY,
|
Annotations.EMPTY,
|
||||||
Modality.OPEN,
|
Modality.FINAL,
|
||||||
Visibilities.PUBLIC,
|
Visibilities.PRIVATE,
|
||||||
isVar,
|
isVar,
|
||||||
name,
|
name,
|
||||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||||
|
|||||||
@@ -92,14 +92,10 @@ abstract class AbstractCustomScriptCodegenTest : CodegenTestCase() {
|
|||||||
|
|
||||||
private fun runScript(scriptClass: Class<*>, receivers: List<Any?>, environmentVars: Map<String, Any?>, scriptParams: List<Any>): Any? {
|
private fun runScript(scriptClass: Class<*>, receivers: List<Any?>, environmentVars: Map<String, Any?>, scriptParams: List<Any>): Any? {
|
||||||
|
|
||||||
val ctorParams = arrayListOf<Any>()
|
val ctorParams = arrayListOf<Any?>()
|
||||||
if (receivers.isNotEmpty()) {
|
|
||||||
ctorParams.add(receivers.toTypedArray())
|
|
||||||
}
|
|
||||||
if (environmentVars.isNotEmpty()) {
|
|
||||||
ctorParams.add(environmentVars)
|
|
||||||
}
|
|
||||||
ctorParams.addAll(scriptParams)
|
ctorParams.addAll(scriptParams)
|
||||||
|
ctorParams.addAll(receivers)
|
||||||
|
ctorParams.addAll(environmentVars.values)
|
||||||
|
|
||||||
val constructor = scriptClass.constructors[0]
|
val constructor = scriptClass.constructors[0]
|
||||||
return constructor.newInstance(*ctorParams.toTypedArray())
|
return constructor.newInstance(*ctorParams.toTypedArray())
|
||||||
|
|||||||
Reference in New Issue
Block a user