conjure-java icon indicating copy to clipboard operation
conjure-java copied to clipboard

[draft] Generate 'sealed interfaces' for Conjure unions (feature flagged)

Open iamdanfox opened this issue 3 years ago • 0 comments

Before this PR

For hackweek, I'm hoping to enable folks to use Java 17's pattern-matching-switch-expressions (https://openjdk.org/jeps/406) to visit the different possible variants of a Conjure union. My primary goal is to make code more readable, but I think it should come with a performance boost too.

After this PR

==COMMIT_MSG== A new feature flag (--sealedUnions) allows users to opt-in to generating Java 17 sealed interfaces for their conjure unions. ==COMMIT_MSG==

Other related work is tracked on https://quip/3YEnAt26mmtE.

Outstanding TODOs:

  • [ ] don't require conjure-java to build and publish using a java 17 JVM.
  • [x] Generate a throwOnKnown method
    • [ ] do we want to change from a SafeIllegalArgumentException now?
  • [x] Generate a way to get the Known interface (maybe just optional initially?)
  • [x] Name escaping of the 'Known' interface name
  • [ ] Testing
    • [ ] get --enable-preview working in Intellij (https://github.com/palantir/gradle-baseline/pull/2319) so I can write some tests
    • [ ] support switch expressions in palantir-java-format (maybe goethe 0.8.0 is all I need... pls mavencentral hurry up)
    • [ ] exhaustive serialization tests, plus tostring tests, plus equality tests

Possible downsides?

iamdanfox avatar Jul 12 '22 13:07 iamdanfox