OneofMode to generate SealedClass for oneofs#3581
Conversation
31952a4 to
03e7232
Compare
scmorse
left a comment
There was a problem hiding this comment.
I know you said this is still a WIP, but I noticed some other files that probably need some updates:
wire-compiler/src/main/java/com/squareup/wire/WireCompiler.ktwire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireOutput.ktwire-gradle-plugin/api/wire-gradle-plugin.apiwire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.ktdocs/wire_compiler.md
55ce945 to
7c70231
Compare
aa613d7 to
bb132be
Compare
bb132be to
b95ff69
Compare
8688c43 to
f8a20c8
Compare
64741ee to
1af547d
Compare
| ) : FieldOrOneOfBinding<M, B>() { | ||
|
|
||
| private val builderField: Field = | ||
| builderType.getDeclaredField(messageField.name).also { it.isAccessible = true } |
There was a problem hiding this comment.
Should this use by lazy {}, like valueField does, so that it doesn't fail if builder types aren't enabled?
There was a problem hiding this comment.
Code has been updated here
| buildersOnly: Boolean = false, | ||
| escapeKotlinKeywords: Boolean = false, | ||
| enumMode: EnumMode = ENUM_CLASS, | ||
| oneofMode: OneofMode = OneofMode.FLAT, |
There was a problem hiding this comment.
I hit a binary compatibility issue testing this against cash-server. Adding oneofMode to KotlinGenerator.Companion.get changes the JVM signature of Kotlin’s generated get$default method, so existing compiled schema handlers/extensions that call KotlinGenerator.get(...) fail at runtime with NoSuchMethodError.
So I think that Cash's existing compiled extensions can’t run with the new Wire jars unless they are recompiled, is that okay? Maybe cash's extensions can just be recompiled and then updated simultaneously with the wire version upgrade.
Alternatively, maybe we could preserve the old overload and have it delegate to the new one with oneofMode = OneofMode.FLAT?
There was a problem hiding this comment.
Addressed by adding a hidden constructor
1af547d to
8e123e0
Compare
| ) : FieldOrOneOfBinding<M, B>() { | ||
|
|
||
| private val builderField: Field = | ||
| builderType.getDeclaredField(messageField.name).also { it.isAccessible = true } |
There was a problem hiding this comment.
Code has been updated here
| buildersOnly: Boolean = false, | ||
| escapeKotlinKeywords: Boolean = false, | ||
| enumMode: EnumMode = ENUM_CLASS, | ||
| oneofMode: OneofMode = OneofMode.FLAT, |
| buildersOnly: Boolean = false, | ||
| escapeKotlinKeywords: Boolean = false, | ||
| enumMode: EnumMode = ENUM_CLASS, | ||
| oneofMode: OneofMode = OneofMode.FLAT, |
There was a problem hiding this comment.
Addressed by adding a hidden constructor
Apologies for the long PR. I wanted to make everything sweet, and it's split into 4 commits.
Golden files + the interop test is the meat of the end result.
Fixes #2749