Skip to content

[pigeon] Fix style of Kotlin enums #140938

Closed

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

Activity

  1. added
    in triagePresently being triaged by the triage team
    c: new featureNothing broken; request for a new capability
    packageflutter/packages repository. See also p: labels.
    c: proposalA detailed proposal for a change to Flutter
    p: pigeonrelated to pigeon messaging codegen tool
    and removed
    in triagePresently being triaged by the triage team
    on Jan 4, 2024
  2. stuartmorgan-g commented on Jan 5, 2024

    @stuartmorgan-g
    Contributor

    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).

  3. changed the title [-][pigeon] Support for appropriate naming conventions of enum case tailored to the platform.[/-] [+][pigeon] Fix style of Kotlin enums[/+] on Jan 5, 2024
  4. added
    platform-androidAndroid applications specifically
    P2Important issues not at the top of the work list
    and removed
    c: new featureNothing broken; request for a new capability
    c: proposalA detailed proposal for a change to Flutter
    on Jan 5, 2024
  5. stuartmorgan-g commented on Jan 5, 2024

    @stuartmorgan-g
    Contributor

    Specifically, when using lower camel case for enum cases, Android generates uppercase concatenated strings.

    I assume you mean "The Pigeon Kotlin generator generates" here; Android is not generating anything.

  6. stuartmorgan-g commented on Jan 5, 2024

    @stuartmorgan-g
    Contributor

    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.)

  7. added
    r: fixedIssue is closed as already fixed in a newer version
    on Feb 16, 2024
  8. github-actions commented on Mar 1, 2024

    @github-actions

    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 -v and a minimal reproduction of the issue.

  9. locked as resolved and limited conversation to collaborators on Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: 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