Skip to content

jextract-swift support for Swift enums #29

Open
@ktoso

Description

@ktoso

May be best to tackle after we have handled structs over here in #26.

Importing a Swift enum should cause slightly different shape of Java types, because we can emulate the general shape and feel of enums with a sealed class hierarchy in Java (available from JDK 17).

E.g. a swift enum like:

enum Animal { 
case capybara(name: String)
case fish(name: String, water: WaterKind)
}
enum WaterKind { 
case sea
case river
}

may be nice to import as something similar to the following:

sealed interface Animal permits Capybara, Fish {

}
final class Capybara implements Animal {
    final String name;
    Capybara(String name) {
        this.name = name;
    }
}
final class Fish implements Animal {
    final String name;
    final WaterKind water;

    Fish(String name, WaterKind water) {
        this.name = name;
        this.water = water;
    }
}

// No associated values; maybe consider plain enum?
enum WaterKind {
    Sea, River
}

We need to consider if it makes sense to make a normal enum for the case without associated values or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    jextract-swiftIssues related to jextract-swift

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions