From 01a9e01fec593e5c715d3f58014ddb811b6fcc8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Doln=C3=ADk?= Date: Thu, 16 Nov 2023 16:40:06 +0100 Subject: [PATCH] Add forbidden names to enum case naming algorithm. --- SKIE/acceptance-tests | 2 +- .../features/enums/EnumEntryRenamingPhase.kt | 33 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/SKIE/acceptance-tests b/SKIE/acceptance-tests index 07aa7487..080676c6 160000 --- a/SKIE/acceptance-tests +++ b/SKIE/acceptance-tests @@ -1 +1 @@ -Subproject commit 07aa7487ab2773bc766f13ce15f95eae8ea7ada0 +Subproject commit 080676c6cf22c842e77cc1ba889df4d67633861c diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/enums/EnumEntryRenamingPhase.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/enums/EnumEntryRenamingPhase.kt index da3b45da..fc2ec9a7 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/enums/EnumEntryRenamingPhase.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/enums/EnumEntryRenamingPhase.kt @@ -12,6 +12,29 @@ import org.jetbrains.kotlin.backend.konan.KonanFqNames object EnumEntryRenamingPhase : SirPhase { + private val forbiddenNames = setOf( + "alloc", + "copy", + "mutableCopy", + "new", + "init", + "isProxy", + "retainCount", + "zone", + "release", + "initialize", + "load", + "class", + "superclass", + "classFallbacksForKeyedArchiver", + "classForKeyedUnarchiver", + "description", + "debugDescription", + "version", + "hash", + "useStoredAccessor", + ) + context(SirPhase.Context) override fun execute() { kirProvider.allEnums @@ -51,7 +74,15 @@ object EnumEntryRenamingPhase : SirPhase { val lowerCaseWords = words.map { it.lowercase() } - return lowerCaseWords.first() + lowerCaseWords.drop(1).joinToString("") { it.replaceFirstChar(Char::uppercaseChar) } + val nameCandidate = lowerCaseWords.first() + lowerCaseWords.drop(1).joinToString("") { + it.replaceFirstChar(Char::uppercaseChar) + } + + return if (nameCandidate in forbiddenNames) { + "the" + nameCandidate.replaceFirstChar(Char::uppercaseChar) + } else { + nameCandidate + } } private class NameParser(