11package com.metaobjects.generator.kotlin
22
3- import com.metaobjects.field.BooleanField
4- import com.metaobjects.field.DoubleField
53import com.metaobjects.field.EnumField
6- import com.metaobjects.field.IntegerField
7- import com.metaobjects.field.LongField
84import com.metaobjects.field.MetaField
95import com.metaobjects.field.ObjectField
10- import com.metaobjects.field.StringField
116import com.metaobjects.`object`.MetaObject
127import com.metaobjects.template.MetaTemplate
138import com.metaobjects.template.OutputTemplate
@@ -32,8 +27,8 @@ import java.util.Properties
3227 * - [BooleanField] → `FieldKind.BOOLEAN`
3328 * - [ObjectField] → `FieldKind.OBJECT`, nested arg `null` (FR-010: nested prompt deferred)
3429 *
35- * String escaping delegates to [KotlinRecoverSchemaEmitter.kotlinStringLiteral], which
36- * is also used by [KotlinRecoverSchemaEmitter] for the recover-schema paths .
30+ * String escaping, scalar-kind mapping, required-field resolution, and map-literal
31+ * building all delegate to [KotlinRecoverSchemaEmitter] (shared helpers, same package) .
3732 *
3833 * This object is internal; generators delegate here.
3934 */
@@ -105,7 +100,7 @@ internal object KotlinOutputFormatSpecEmitter {
105100 */
106101 private fun promptFieldLiteral (field : MetaField <* >): String {
107102 val name = field.name
108- val required = isRequired(field)
103+ val required = KotlinRecoverSchemaEmitter . isRequired(field)
109104 val array = field.isArray
110105
111106 // Nested object — bounded deferral (mirrors Java plan 3.1).
@@ -119,7 +114,7 @@ internal object KotlinOutputFormatSpecEmitter {
119114 }
120115
121116 // Scalar — resolve @example and @instruction.
122- val kindName = scalarKind(field) ? : " STRING" // Unknown type: fall back to STRING.
117+ val kindName = KotlinRecoverSchemaEmitter . scalarKind(field) ? : " STRING" // Unknown type: fall back to STRING.
123118 val exampleLit = optStringAttr(field, MetaField .ATTR_EXAMPLE )
124119 val instructionLit = optStringAttr(field, MetaField .ATTR_INSTRUCTION )
125120
@@ -144,7 +139,7 @@ internal object KotlinOutputFormatSpecEmitter {
144139 val enumDocLit: String = run {
145140 if (! field.hasMetaAttr(EnumField .ATTR_ENUM_DOC , false )) return @run " null"
146141 val v = field.getMetaAttr(EnumField .ATTR_ENUM_DOC , false ).value
147- if (v is Properties && v.isNotEmpty()) buildMapOfLiteral(v) else " null"
142+ if (v is Properties && v.isNotEmpty()) KotlinRecoverSchemaEmitter . buildMapOfLiteral(v) else " null"
148143 }
149144
150145 val exampleLit = optStringAttr(field, MetaField .ATTR_EXAMPLE )
@@ -168,44 +163,4 @@ internal object KotlinOutputFormatSpecEmitter {
168163 return " \" ${KotlinRecoverSchemaEmitter .kotlinStringLiteral(v)} \" "
169164 }
170165
171- /* *
172- * Returns `true` when the field carries `@required: true`.
173- * Mirrors [KotlinRecoverSchemaEmitter]'s `isRequired` helper.
174- */
175- private fun isRequired (field : MetaField <* >): Boolean =
176- field.hasMetaAttr(MetaField .ATTR_REQUIRED )
177- && " true" .equals(field.getMetaAttr(MetaField .ATTR_REQUIRED ).valueAsString, ignoreCase = true )
178-
179- /* *
180- * Return the `FieldKind` enum member name for a scalar field, or `null` when the
181- * field type is not a known scalar. Matches the same instanceof order as
182- * [KotlinRecoverSchemaEmitter.scalarKind].
183- */
184- private fun scalarKind (field : MetaField <* >): String? = when (field) {
185- is StringField -> " STRING"
186- is IntegerField -> " INT"
187- is LongField -> " LONG"
188- is DoubleField -> " DOUBLE"
189- is BooleanField -> " BOOLEAN"
190- else -> null
191- }
192-
193- // -------------------------------------------------------------------------
194- // Private helpers — source literal builders
195- // -------------------------------------------------------------------------
196-
197- /* *
198- * Emit a `mapOf(k to v, ...)` literal from a [Properties]. Entries are sorted by key
199- * for deterministic output. Keys and values are escaped via
200- * [KotlinRecoverSchemaEmitter.kotlinStringLiteral]. Kotlin's `mapOf` has no arity cap
201- * (unlike `java.util.Map.of` which is limited to 10 pairs).
202- */
203- private fun buildMapOfLiteral (props : Properties ): String {
204- val keys = props.keys.map { it.toString() }.sorted()
205- val entries = keys.joinToString(" , " ) { k ->
206- val v = props.getProperty(k)
207- " \" ${KotlinRecoverSchemaEmitter .kotlinStringLiteral(k)} \" to \" ${KotlinRecoverSchemaEmitter .kotlinStringLiteral(v)} \" "
208- }
209- return " mapOf($entries )"
210- }
211166}
0 commit comments