Skip to content

JNI: Java enum constants keep the Swift case names - #23

Open
piercifani wants to merge 2 commits into
jni/18-async-closuresfrom
jni/19-enum-swift-case-names
Open

piercifani wants to merge 2 commits into
jni/18-async-closuresfrom
jni/19-enum-swift-case-names

Conversation

@piercifani

@piercifani piercifani commented Nov 3, 2026 •

Copy link
Copy Markdown

Stack 19/21 · base: jni/18-async-closures · previous: #22 · next: #24 (jni/20-nullability-annotations)

Problem

With payloadlessEnumsAsJavaEnums (#17), Java enum constants were uppercased, like the Discriminator of enum classes: OrderStatus.FILLED. Swift code spells the case .filled, and so does Kotlin code written against the Swift API or translated from it.

Changes

  • Names: constants keep the Swift case name, OrderStatus.filled, matching the case factory method filled() they sit next to.
  • Keywords: a case named after a Java keyword, such as `default`, gets a trailing _, as methods already do.
  • Docs: payloadlessEnumsAsJavaEnums' documentation says how constants are named.

Discriminator, on enum classes, keeps its uppercase names.

Kotlin in this PR

JavaEnumsTest.kt uses the Swift names:

val label = when (Orders.fill(OrderStatus.pending)) {
    OrderStatus.pending -> "pending"
    OrderStatus.filled -> "filled"
    OrderStatus.cancelled -> "cancelled"
}

Why Skip needs it

Skip keeps Swift's case names in the Kotlin enum classes it generates, and the app's Kotlin code refers to them by those names.

Testing

  • Kotlin sample: JavaEnumsTest passes with the Swift names, as does the full Kotlin sample (47 tests).
  • JNIJavaEnumTests: constants named like the cases; a new test for `default` → default_.
  • Full swift test --disable-experimental-prebuilts --disable-sandbox (690 tests) and ./gradlew :Samples:SwiftJavaExtractJNISampleApp:test (302 tests) pass, measured with the next PR applied.
  • swift run generate-config-docs --check; swift format format leaves changed files unchanged; git diff --check.

🤖 Generated with Claude Code

piercifani and others added 2 commits November 3, 2026 21:22
With `payloadlessEnumsAsJavaEnums`, constants were uppercased like the
`Discriminator` of enum classes: `OrderStatus.FILLED`. They now keep the
case name, `OrderStatus.filled`, as Swift code spells it and as the case
factory method `filled()` already does. Kotlin code written against the
Swift API, or translated from it, uses the same names. A case named
after a Java keyword, such as `` `default` ``, gets a trailing `_`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant