jextract/jni: Move enum case classes inside the Case interface#709
Merged
ktoso merged 2 commits intoswiftlang:mainfrom Apr 17, 2026
Merged
jextract/jni: Move enum case classes inside the Case interface#709ktoso merged 2 commits intoswiftlang:mainfrom
Case interface#709ktoso merged 2 commits intoswiftlang:mainfrom
Conversation
sidepelican
commented
Apr 17, 2026
| """ | ||
| public sealed interface Case {} | ||
| public sealed interface Case { | ||
| record First() implements Case { |
Contributor
Author
There was a problem hiding this comment.
Note: public is unnecessary within an interface.
ktoso
reviewed
Apr 17, 2026
| try (var arena = SwiftArena.ofConfined()) { | ||
| Vehicle vehicle = Vehicle.transformer(Vehicle.bicycle(arena), Vehicle.car("BMW", Optional.empty(), arena), arena); | ||
| Vehicle.Transformer transformer = vehicle.getAsTransformer(arena).orElseThrow(); | ||
| Vehicle.Case.Transformer transformer = vehicle.getAsTransformer(arena).orElseThrow(); |
Collaborator
There was a problem hiding this comment.
The alternative would be to Vehicle.TransformerCase or Vehicle.$Transformer hm... The $ in the name is not ideal perhaps, we usually tell folks that things with $ in the name are "not for them" but the Case sufficient could work without the additional nesting...
WDYT, any opinions @madsodgaard ?
ktoso
reviewed
Apr 17, 2026
| /// The description of the type java.util.Optional. | ||
| static func optional(_ T: JavaType) -> JavaType { | ||
| .class(package: "java.util", name: "Optional", typeParameters: [T]) | ||
| } |
ktoso
reviewed
Apr 17, 2026
Collaborator
ktoso
left a comment
There was a problem hiding this comment.
I don't dislike this tbh... let's give @madsodgaard a chance to reply as well
Contributor
|
Yeah, I've faced this as well. Moving it into |
Collaborator
|
Okey, I'm happy with the .Case., it's fine tbh :) Thank you ! |
ktoso
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, generating Java code for a Swift enum where a case name matches a nested type name (as shown below) results in a compilation error.
This happens because
jextractgenerates two Java classes namedSuccessat the same nesting level—one for the enum case and one for the Swift struct.To avoid this, I have moved the generated case classes inside the
interface Case.Note
While a collision could still theoretically occur if the Swift enum defines its own
struct Case, the probability of encountering such a conflict is significantly lower with this new structure.