Skip to content

Commit

Permalink
Add forbidden names to enum case naming algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipDolnik committed Nov 16, 2023
1 parent 9d48453 commit 01a9e01
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion SKIE/acceptance-tests
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 01a9e01

Please sign in to comment.