-
Notifications
You must be signed in to change notification settings - Fork 0
Language Kotlin
The Kotlin generator emits a stand-alone .kt file. It does not require a Kotlin Lexicon runtime package.
swift run lexicon-generate commerce.lexicon --type kotlin -o app/src/main/kotlin/com/example/commerce/LexiconThis writes:
app/src/main/kotlin/com/example/commerce/Lexicon.kt
Add a package declaration yourself if your project requires one:
package com.example.commercePlace it at the top of the generated file or wrap generation with a build step that prepends it.
Generated Kotlin defines:
-
I, the shared vocabulary interface. -
TypeLocalized, for localized display strings. -
SourceCodeIdentifiable, for exact IDs. -
L, the base class. - one generated data class per concrete lemma.
- one generated interface per semantic type.
- extension properties for children and inherited children.
Example access:
val submit = commerce.api.order.submit
val button = commerce.ui.checkout.button.primary
println(submit.identifier)
println(button.localized)The identifier value is the exact lemma ID.
Kotlin generated accessors use backticks:
val type = commerce.`type`This keeps generated code valid when a lemma name conflicts with a Kotlin keyword.
A synonym becomes a typealias or property pointing at the resolved source. Given:
state:
enabled:
active:
= enabled
Use the generated accessors as normal:
val enabled = commerce.state.enabled
val active = commerce.state.active
check(enabled.identifier == active.identifier)Use an Exec task when the Kotlin project can run Swift during generation:
tasks.register<Exec>("generateLexicon") {
workingDir = rootProject.projectDir
commandLine(
"swift", "run", "lexicon-generate",
"lexicons/commerce.lexicon",
"--type", "kotlin",
"-o", "app/src/main/kotlin/com/example/commerce/Lexicon"
)
}
tasks.named("compileKotlin") {
dependsOn("generateLexicon")
}If Swift should not be required in normal Kotlin builds, generate the file in a docs/tooling workflow and commit the generated .kt.
Use generated Kotlin for:
- stable IDs in analytics events
- typed feature-flag names
- shared UI state vocabulary
- data-mapping keys that must match API and documentation vocabulary
Prefer identifier for persistence, logging, and protocol boundaries. Prefer generated accessors in source code so refactors fail at compile time.