55
66package org.jetbrains.kotlinx.dataframe.plugin.extensions
77
8- import kotlinx.serialization.decodeFromString
98import kotlinx.serialization.encodeToString
109import kotlinx.serialization.json.Json
1110import org.jetbrains.kotlin.backend.common.FileLoweringPass
@@ -18,8 +17,10 @@ import org.jetbrains.kotlin.ir.backend.js.utils.valueArguments
1817import org.jetbrains.kotlin.ir.declarations.IrClass
1918import org.jetbrains.kotlin.ir.declarations.IrConstructor
2019import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
20+ import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithName
2121import org.jetbrains.kotlin.ir.declarations.IrFile
2222import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
23+ import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
2324import org.jetbrains.kotlin.ir.declarations.IrProperty
2425import org.jetbrains.kotlin.ir.declarations.copyAttributes
2526import org.jetbrains.kotlin.ir.declarations.createBlockBody
@@ -175,8 +176,9 @@ private class DataFrameFileLowering(val context: IrPluginContext) : FileLowering
175176
176177 val constructors = context.referenceConstructors(ClassId (FqName (" kotlin.jvm" ), Name .identifier(" JvmName" )))
177178 val jvmName = constructors.single { it.owner.valueParameters.size == 1 }
178- val markerName = ((getter.extensionReceiverParameter!! .type as IrSimpleType ).arguments.single() as IrSimpleType ).classFqName?.shortName()!!
179- val jvmNameArg = " ${markerName.identifier} _${declaration.name.identifier} "
179+ val marker =
180+ ((getter.extensionReceiverParameter!! .type as IrSimpleType ).arguments.single() as IrSimpleType ).classOrFail.owner
181+ val jvmNameArg = " ${marker.nestedName()} _${declaration.name.identifier} "
180182 getter.annotations = listOf (
181183 IrConstructorCallImpl (- 1 , - 1 , jvmName.owner.returnType, jvmName, 0 , 0 , 1 )
182184 .also {
@@ -218,6 +220,21 @@ private class DataFrameFileLowering(val context: IrPluginContext) : FileLowering
218220 return declaration
219221 }
220222
223+ private fun IrDeclarationWithName.nestedName () = buildString { computeNestedName(this @nestedName, this ) }
224+
225+ private fun computeNestedName (declaration : IrDeclarationWithName , result : StringBuilder ): Boolean {
226+ when (val parent = declaration.parent) {
227+ is IrClass -> {
228+ if (! computeNestedName(parent, result)) return false
229+ }
230+ is IrPackageFragment -> {}
231+ else -> return false
232+ }
233+ if (result.isNotEmpty()) result.append(' _' )
234+ result.append(declaration.name.asString())
235+ return true
236+ }
237+
221238 @OptIn(UnsafeDuringIrConstructionAPI ::class )
222239 override fun visitErrorCallExpression (expression : IrErrorCallExpression ): IrExpression {
223240 val origin = (expression.type.classifierOrNull?.owner as ? IrClass )?.origin ? : return expression
0 commit comments