All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.seskar.compiler.specialname.backend.SpecialNameTransformer.kt Maven / Gradle / Ivy

There is a newer version: 3.32.0
Show newest version
package seskar.compiler.specialname.backend

import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclarationBase
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import seskar.compiler.common.backend.JsName

internal class SpecialNameTransformer(
    private val context: IrPluginContext,
) : IrElementTransformerVoid() {
    override fun visitClass(
        declaration: IrClass,
    ): IrStatement {
        processSpecialName(declaration)

        return super.visitClass(declaration)
    }

    override fun visitProperty(
        declaration: IrProperty,
    ): IrStatement {
        processSpecialName(declaration)

        return declaration
    }

    override fun visitFunction(
        declaration: IrFunction,
    ): IrStatement {
        processSpecialName(declaration)

        return super.visitFunction(declaration)
    }

    private fun processSpecialName(
        declaration: IrDeclarationBase,
    ) {
        val specialName = declaration.specialName()
        if (specialName != null) {
            declaration.annotations += JsName(context, specialName)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy