codegen-java/kotlin: Support generating sealed classes
It would be very nice to generate sealed Java/Kotlin classes whenever possible. This would improve code comprehension, pattern matching, and the IDE experience.
Potential solutions:
- Infer which abstract and open Pkl classes can be sealed in Java/Kotlin. At a minimum, this would require passing all Pkl modules at once to Java/KotlinCodeGenerator so that it can check if a class is subclassed in another module. Currently, Java/KotlinCodeGenerator only accepts a single module whereas CliJava/KotlinCodeGenerator accepts multiple.
- Support sealed classes in Pkl. This feels like a cleaner solution and could prove equally useful as supporting open vs. non-open classes.
Infer which abstract and open Pkl classes can be sealed in Java/Kotlin.
Without a sealed in Pkl, there's no way to ensure that the provided set of classes is exhaustive. For example:
- Library publishes Pkl bindings + Java codegen'd classes
- Application uses library, extends Pkl classes and does is own codegen
I think the conclusion is that moving forward with this feature would require a sealed SPICE.
Yeah; I think that's right
How about reserving the keyword sealed for now?
I'm okay with that!
@stackoverflow, @holzensp: thoughts?