Add Kotlin support for "addGeneratedAnnotation" flag (#1115)

This adds logic so that the Kotlin code generator also supports the
"addGeneratedAnnotation" flag.

Also:
* Add Antora documentation
* Adjust names (generated-annotation -> add-generated-annotation)
* Adjust doc comments
This commit is contained in:
Daniel Chao
2025-07-08 14:05:15 -07:00
committed by GitHub
parent 3a35be6311
commit 48ad4386c8
14 changed files with 76 additions and 15 deletions

View File

@@ -2029,6 +2029,30 @@ class KotlinCodeGeneratorTest {
)
}
@Test
fun `add generated annotation`() {
val files =
KotlinCodeGeneratorOptions(addGeneratedAnnotation = true)
.generateFiles("com.example.MyModule" to "foo: String")
assertThat(files).containsKey("kotlin/com/example/MyModule.kt")
assertThat(files["kotlin/com/example/MyModule.kt"])
.isEqualTo(
"""
package com.example
import kotlin.String
import org.pkl.config.java.Generated
@Generated
data class MyModule(
val foo: String
)
"""
.trimIndent()
)
}
private fun Map<String, String>.validateContents(
vararg assertions: kotlin.Pair<String, List<String>>
) {