Repository navigation
[pigeon] Fix style of Kotlin enums #140938
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Description
Use case
I am currently working with the Pigeon package in Flutter, where I use enums to define common data types across Swift, Kotlin, and Dart. However, I have encountered an issue with the naming convention for enum cases. Specifically, when using lower camel case for enum cases, Android generates uppercase concatenated strings. As a result, Pigeon currently supports only single-word enum cases.
enum SampleEnum {
sampleVersion,
sampleTest,
}enum class SampleEnum(val raw: Int) {
SAMPLEVERSION(0),
SAMPLETEST(1);
companion object {
fun ofRaw(raw: Int): SampleEnum? {
return values().firstOrNull { it.raw == raw }
}
}
}Proposal
I propose implementing a feature in the Pigeon package that supports defining enum cases in lower camel case, resulting in lower camel case conversion for Swift(maintaining the current behavior) and screaming snake case conversion for Kotlin.
In Kotlin, the corresponding generated code should adopt screaming snake case for enum cases.
enum class SampleEnum(val raw: Int) {
SAMPLE_VERSION(0),
SAMPLE_TEST(1);
companion object {
fun ofRaw(raw: Int): SampleEnum? {
return values().firstOrNull { it.raw == raw }
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Activity
stuartmorgan-g commentedon Jan 5, 2024
Retitling; the current title is asking for a policy that we translate names to the appropriate style for each language, which is already the policy for Pigeon. The current Kotlin enum behavior is just a bug.
https://developer.android.com/kotlin/style-guide doesn't appear to say anything about enums specifically, so we can fall back to https://kotlinlang.org/docs/coding-conventions.html#property-names. That allows for either screaming snake case or upper camel case, so we should just pick one; screaming snake as requested here seems fine (and will require fewer changes to existing code for pigeon clients, since only multi-word enum values will change).
[-][pigeon] Support for appropriate naming conventions of enum case tailored to the platform.[/-][+][pigeon] Fix style of Kotlin enums[/+]stuartmorgan-g commentedon Jan 5, 2024
I assume you mean "The Pigeon Kotlin generator generates" here; Android is not generating anything.
stuartmorgan-g commentedon Jan 5, 2024
This just requires a trivial change here, and appropriate Dart unit tests.
(And a major version bump since it's a breaking change as we define it for Pigeon.)
[pigeon] Implement Screaming Snake Case Conversion for Kotlin Enum Ca…
github-actions commentedon Mar 1, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.