Repository: JetBrains/compose-multiplatform
File: gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/InfoPlistBuilder.kt (Kotlin)

Code before:
                ) {
                    it.toString(nestingLevel + 1)
                }

            override fun toString(): String = super.toString()

            constructor(vararg elements: InfoPlistValue) : this(elements.asList())
        }

        data class InfoPlistMapValue(val elements: Map<InfoPlistKey, InfoPlistValue>) : InfoPlistValue() {
            override fun toString(nestingLevel: Int): String =
                if (elements.isEmpty()) "${indentForLevel(nestingLevel)}<dict/>"
                else elements.entries.joinToString(
                    separator = "\n",
                    prefix = "${indentForLevel(nestingLevel)}<dict>\n",
                    postfix = "\n${indentForLevel(nestingLevel)}</dict>",
                ) { (key, value) ->
                    "${indentForLevel(nestingLevel + 1)}<key>${key.name}</key>\n${value.toString(nestingLevel + 1)}"
                }
            override fun toString() = super.toString()

            constructor(vararg elements: Pair<InfoPlistKey, InfoPlistValue>) : this(elements.toMap())
        }

        data class InfoPlistStringValue(val value: String) : InfoPlistValue() {
            override fun toString(nestingLevel: Int): String = if (value.isEmpty()) "${indentForLevel(nestingLevel)}<string/>" else "${indentForLevel(nestingLevel)}<string>$value</string>"
            override fun toString() = super.toString()
        }
    }

    private val values = LinkedHashMap<InfoPlistKey, InfoPlistValue>()

    operator fun get(key: InfoPlistKey): InfoPlistValue? = values[key]
    operator fun set(key: InfoPlistKey, value: String?) = set(key, value?.let(::InfoPlistStringValue))
    operator fun set(key: InfoPlistKey, value: List<InfoPlistValue>?) = set(key, value?.let(::InfoPlistListValue))
    operator fun set(key: InfoPlistKey, value: Map<InfoPlistKey, InfoPlistValue>?) =
        set(key, value?.let(::InfoPlistMapValue))

    operator fun set(key: InfoPlistKey, value: InfoPlistValue?) {
        if (value != null) {
            values[key] = value
        } else {
            values.remove(key)
        }
    }

    fun writeToFile(file: File) {
        file.writer().buffered().use { writer ->
            writer.run {
                appendLine("<?xml version=\"1.0\" ?>")
                appendLine("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"https://www.apple.com/DTDs/PropertyList-1.0.dtd\">")

Review comment (refactor):
is it necessary? I guess we may simplify the logic and use `<string></string>` for empty strings

Code after:
                    it.asPlistEntry(nestingLevel + 1)
                }

            constructor(vararg elements: InfoPlistValue) : this(elements.asList())
        }

        data class InfoPlistMapValue(val elements: Map<InfoPlistKey, InfoPlistValue>) : InfoPlistValue() {
            override fun asPlistEntry(nestingLevel: Int): String =
                if (elements.isEmpty()) "${indentForLevel(nestingLevel)}<dict/>"
                else elements.entries.joinToString(
                    separator = "\n",
                    prefix = "${indentForLevel(nestingLevel)}<dict>\n",
                    postfix = "\n${indentForLevel(nestingLevel)}</dict>",
                ) { (key, value) ->
                    "${indentForLevel(nestingLevel + 1)}<key>${key.name}</key>\n${value.asPlistEntry(nestingLevel + 1)}"
                }

            constructor(vararg elements: Pair<InfoPlistKey, InfoPlistValue>) : this(elements.toMap())
        }

        data class InfoPlistStringValue(val value: String) : InfoPlistValue() {
            override fun asPlistEntry(nestingLevel: Int): String = if (value.isEmpty()) "${indentForLevel(nestingLevel)}<string/>" else "${indentForLevel(nestingLevel)}<string>$value</string>"
        }
    }

    private val values = LinkedHashMap<InfoPlistKey, InfoPlistValue>()

    operator fun get(key: InfoPlistKey): InfoPlistValue? = values[key]
    operator fun set(key: InfoPlistKey, value: String?) = set(key, value?.let(::InfoPlistStringValue))
    operator fun set(key: InfoPlistKey, value: List<InfoPlistValue>?) = set(key, value?.let(::InfoPlistListValue))
    operator fun set(key: InfoPlistKey, value: Map<InfoPlistKey, InfoPlistValue>?) =
        set(key, value?.let(::InfoPlistMapValue))

    operator fun set(key: InfoPlistKey, value: InfoPlistValue?) {
        if (value != null) {
            values[key] = value
        } else {
            values.remove(key)
        }
    }

    fun writeToFile(file: File) {
        file.writer().buffered().use { writer ->
            writer.run {
                appendLine("<?xml version=\"1.0\" ?>")
                appendLine("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"https://www.apple.com/DTDs/PropertyList-1.0.dtd\">")
                appendLine("<plist version=\"1.0\">")
                appendLine("${indentForLevel(1)}<dict>")
                for ((k, v) in values) {
                    appendLine("${indentForLevel(2)}<key>${k.name}</key>")
                    appendLine(v.asPlistEntry(2))