From 9b7f4a24e5a8a62aca9ae9ea28fe3ca04fe7a9d2 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Thu, 26 Nov 2026 06:15:29 -0500 Subject: [PATCH 1/3] refactor(codegen-kotlin): move the Spring controller generator onto KotlinWriter (W-KT-3) KotlinSpringControllerGenerator (the writable, TPH base and read-only controllers, with the filter pipeline, M:N traversal routes, sort surface and credential redactor they share) now writes through KotlinWriter (ADR-0063) instead of hand-indented StringBuilder text. Its entry leaves the Kotlin layout ratchet's allowlist. Generated output changes in layout only: imports in one sorted group, no blank line at the start or end of the controller class, and two bodies the old builder indented one level off (the Exposed 1.x WhereOp loop, and a PATCH handler whose only automatic column is @autoSet) now indented by their blocks. The six controller snapshot goldens are refreshed. The protected open hooks (emitFilterPipeline, emitPerFieldDispatchArm, emitTypedCoercer, emitM2mEndpoint, emitTphSubtypeM2mEndpoint) take a KotlinWriter where they took a StringBuilder; an owned copy ejected at an earlier version carries its own and still compiles. --- CHANGELOG.md | 13 + .../kotlin/KotlinSpringControllerGenerator.kt | 2839 ++++++++--------- .../resources/layout-ratchet/allowlist.json | 1 - .../acme/blog/AuthorController.kt | 30 +- .../acme/catalog/ProductController.kt | 32 +- .../acme/catalog/ProductController.kt | 32 +- .../acme/auth/AuthController.kt | 35 +- .../acme/auth/AuthLineController.kt | 30 +- .../acme/report/SalesReportController.kt | 19 +- 9 files changed, 1512 insertions(+), 1519 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c513150584..b85ae6d8e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1652,6 +1652,19 @@ four `rules.*` and `verify.lifecycle.unreachable` settings, held to `fixtures/ru (`writeInstantTzSupport` and its siblings); an owned copy ejected at an earlier version carries its own and still compiles (`EjectedAtBaseGeneratorsCompatTest`). +- **The Kotlin Spring controller writes through `KotlinWriter`** (ADR-0063): the writable + controller, the TPH base controller and the read-only (projection and report) controller, with + the filter pipeline, the M:N traversal routes, the sort surface and the credential redactor they + share. Its entry leaves the layout ratchet's allowlist. **Its output changes in layout only:** + imports in one sorted group, no blank line at the start or end of the controller class, and two + bodies the old text builder indented one level off now indented by their blocks (the Exposed 1.x + `WhereOp` loop, and a PATCH handler whose only automatic column is an `@autoSet` one). + Regenerating shows those diffs and nothing else. The `protected open` hooks an `open` subclass + overrides (`emitFilterPipeline`, `emitPerFieldDispatchArm`, `emitTypedCoercer`, + `emitM2mEndpoint`, `emitTphSubtypeM2mEndpoint`) now take a `KotlinWriter` where they took a + `StringBuilder`; an owned copy ejected at an earlier version carries its own and still compiles + (`EjectedAtBaseGeneratorsCompatTest`). + - **Python publishes a shared model (FR-023).** A `shared-model` generator, wired in `metaobjects.config.yaml` like any other (`metaobjects gen --list` names its options), writes `.metaobjects.json` and `metaobjects.pkg.json` for a consumer's `deps sync`: `name` and diff --git a/server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinSpringControllerGenerator.kt b/server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinSpringControllerGenerator.kt index e8ff2c477e..8577752843 100644 --- a/server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinSpringControllerGenerator.kt +++ b/server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinSpringControllerGenerator.kt @@ -16,6 +16,7 @@ import com.metaobjects.generator.kotlin.KotlinNaming import com.metaobjects.generator.kotlin.KotlinTphPlan import com.metaobjects.generator.kotlin.KotlinTypeMapper import com.metaobjects.generator.kotlin.PackageMapping +import com.metaobjects.generator.kotlin.writer.KotlinWriter import com.metaobjects.field.BooleanField import com.metaobjects.field.CurrencyField @@ -93,12 +94,9 @@ import com.metaobjects.generator.util.GeneratedFileWriter * {@link KotlinSpringConfigGenerator}) wires {@code Database.connect()}; the controller * does not own a {@code DataSource} itself. * - *

Substrate justification (hand-rolled string builder rather than KotlinPoet): same - * trade-off as {@link KotlinExposedTableGenerator}. Spring annotations + the Exposed DSL - * (e.g. {@code AuthorTable.selectAll().where { AuthorTable.id eq id }}) don't translate - * cleanly to KotlinPoet's {@code PropertySpec}/{@code FunSpec} APIs without a verbose - * dance of {@code %T} placeholders; the syntactic surface is small (~80 lines per file) - * and matches the idiomatic Kotlin/Spring style. + *

The file is written through [KotlinWriter] (ADR-0063): the generator states each line and + * opens and closes each block, and the writer owns the indentation, the blank lines and the + * import section. * *

Args: *