Skip to content

WIP SealedClass for oneofs#3581

Draft
oldergod wants to merge 1 commit intomasterfrom
bquenaudon.2026-04-27.sealedclass
Draft

WIP SealedClass for oneofs#3581
oldergod wants to merge 1 commit intomasterfrom
bquenaudon.2026-04-27.sealedclass

Conversation

@oldergod
Copy link
Copy Markdown
Member

Fixes #2749

@oldergod oldergod force-pushed the bquenaudon.2026-04-27.sealedclass branch from 31952a4 to 03e7232 Compare April 27, 2026 15:43
Copy link
Copy Markdown

@scmorse scmorse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.kt
  • wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireOutput.kt
  • wire-gradle-plugin/api/wire-gradle-plugin.api
  • wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt
  • docs/wire_compiler.md

* Converts a snake_case field name to PascalCase for use as a sealed class subtype name.
* For example: `card_id` → `CardId`, `bank_account` → `BankAccount`.
*/
private fun String.toSealedSubclassName(): String = split("_").joinToString("") { part -> part.replaceFirstChar { it.uppercaseChar() } }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should sealed subtype names go through NameAllocator / existing Wire casing helpers instead of a custom split("_") conversion?

.build(),
)
.addProperty(
PropertySpec.builder("value", valueType)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worthwhile to include field options on the value property? e.g. deprecated/redacted/etc

val subclass = TypeSpec.classBuilder(subclassName)
.addModifiers(DATA)
.superclass(sealedClassName)
.primaryConstructor(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the sealed class instances per-field use the builder pattern if buildersOnly is configured?

@oldergod oldergod force-pushed the bquenaudon.2026-04-27.sealedclass branch 2 times, most recently from 55ce945 to 7c70231 Compare April 27, 2026 21:06
@oldergod oldergod force-pushed the bquenaudon.2026-04-27.sealedclass branch from 7c70231 to fad4166 Compare April 27, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exhaustive checks in oneof fields

2 participants