Skip to content

[pigeon] Fix style of Kotlin enums #140938

@yuukiw00w

Description

@yuukiw00w

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 }
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listgood first issueRelatively approachable for first-time contributorsp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions