diff --git a/docs/modules/java-binding/pages/codegen.adoc b/docs/modules/java-binding/pages/codegen.adoc index 91f3372d5..df04cc8cc 100644 --- a/docs/modules/java-binding/pages/codegen.adoc +++ b/docs/modules/java-binding/pages/codegen.adoc @@ -145,23 +145,27 @@ Flag that indicates to generate private final fields and public getter methods i [%collapsible] ==== Default: (flag not set) + -Flag that indicates to generate Javadoc based on doc comments for Pkl modules, classes, and properties. +Flag that indicates to preserve Pkl doc comments by generating Javadoc comments. ==== .--params-annotation [%collapsible] ==== -Default: `org.pkl.config.java.mapper.Named` + -Fully qualified name of the annotation to use on constructor parameters. +Default: `none` if `--generate-spring-boot` is set, `org.pkl.config.java.mapper.Named` otherwise + +Fully qualified name of the annotation type to use for annotating constructor parameters with their name. + +The specified annotation type must have a `value` parameter of type `String` or the generated code may not compile. +If set to `none`, constructor parameters are not annotated. +Whether and how constructor parameters should be annotated depends on the library that instantiates the generated classes. +For Spring Boot applications, and for users of `pkl-config-java` compiling the generated classes with `-parameters`, no annotation is required. ==== .--non-null-annotation [%collapsible] ==== Default: `org.pkl.config.java.mapper.NonNull` + -Fully qualified named of the annotation class to use for non-null types. + -This annotation is required to have `java.lang.annotation.ElementType.TYPE_USE` as a `@Target` -or it may generate code that does not compile. +Fully qualified name of the annotation type to use for annotating non-null types. + +The specified annotation type must be annotated with `@java.lang.annotation.Target(ElementType.TYPE_USE)` +or the generated code may not compile. ==== Common code generator options: diff --git a/docs/modules/java-binding/partials/cli-codegen-options.adoc b/docs/modules/java-binding/partials/cli-codegen-options.adoc index 4aab11f59..c3c130245 100644 --- a/docs/modules/java-binding/partials/cli-codegen-options.adoc +++ b/docs/modules/java-binding/partials/cli-codegen-options.adoc @@ -26,7 +26,7 @@ Flag that indicates to generate config classes for use with Spring Boot. [%collapsible] ==== Default: (not set) + -Whether to make generated classes implement `java.io.Serializable`. +Flag that indicates to generate classes that implement `java.io.Serializable`. ==== .--rename diff --git a/docs/modules/kotlin-binding/pages/codegen.adoc b/docs/modules/kotlin-binding/pages/codegen.adoc index 7866e5033..0f69b6563 100644 --- a/docs/modules/kotlin-binding/pages/codegen.adoc +++ b/docs/modules/kotlin-binding/pages/codegen.adoc @@ -118,7 +118,7 @@ Relative URIs are resolved against the working directory. [%collapsible] ==== Default: (flag not set) + -Flag that indicates to generate Kdoc based on doc comments for Pkl modules, classes, and properties. +Flag that indicates to preserve Pkl doc comments by generating KDoc comments. ==== Common code generator options: diff --git a/docs/modules/pkl-gradle/pages/index.adoc b/docs/modules/pkl-gradle/pages/index.adoc index 373e5ba1e..118c51545 100644 --- a/docs/modules/pkl-gradle/pages/index.adoc +++ b/docs/modules/pkl-gradle/pages/index.adoc @@ -373,14 +373,26 @@ Example: `generateGetters = true` + Whether to generate private final fields and public getter methods rather than public final fields. ==== -// TODO: fixme (paramsAnnotation, nonNullAnnotation) -.preferJavaxInjectAnnotation: Boolean +.paramsAnnotation: Property [%collapsible] ==== -Default: `false` + -Example: `preferJavaxInjectAnnotation = true` + -Whether to annotate constructor parameters with `@javax.inject.Named` instead of `@org.pkl.config.java.mapper.Named`. -If `true`, the generated code will have a compile dependency on `javax.inject:javax.inject:1`. +Default: `null` if `generateSpringBootConfig` is `true`, `"org.pkl.config.java.mapper.Named"` otherwise+ +Example: `paramsAnnotation = "org.project.MyAnnotation"` + +Fully qualified name of the annotation type to use for annotating constructor parameters with their name. + +The specified annotation type must have a `value` parameter of type `String` or the generated code may not compile. +If set to `null`, constructor parameters are not annotated. +Whether and how constructor parameters should be annotated depends on the library that instantiates the generated classes. +For Spring Boot applications, and for users of `pkl-config-java` compiling the generated classes with `-parameters`, no annotation is required. + +==== +.nonNullAnnotation: Property +[%collapsible] +==== +Default: `"org.pkl.config.java.mapper.NonNull"` + +Example: `nonNullAnnotation = "org.project.MyAnnotation"` + +Fully qualified name of the annotation type to use for annotating non-null types. + +The specified annotation type must be annotated with `@java.lang.annotation.Target(ElementType.TYPE_USE)` +or the generated code may not compile. ==== Common code generation properties: @@ -443,8 +455,15 @@ see link:{uri-codegen-kotlin-example}[codegen-kotlin] in the _pkl/pkl-examples_ === Configuration Options -// TODO: fixme (generateKdoc) -(None) +=== Configuration Options + +.generateKdoc: Property +[%collapsible] +==== +Default: `false` + +Example: `generateKdoc = true` + +Whether to preserve Pkl doc comments by generating KDoc comments. +==== Common code generation properties: diff --git a/docs/modules/pkl-gradle/partials/gradle-codegen-properties.adoc b/docs/modules/pkl-gradle/partials/gradle-codegen-properties.adoc index 1619c3196..19130682d 100644 --- a/docs/modules/pkl-gradle/partials/gradle-codegen-properties.adoc +++ b/docs/modules/pkl-gradle/partials/gradle-codegen-properties.adoc @@ -36,6 +36,14 @@ Example: `generateSpringBootConfig = true` + Whether to generate config classes for use with Spring Boot. ==== +.implementSerializable: Property +[%collapsible] +==== +Default: `false` + +Example: `implementSerializable = true` + +Whether to generate classes that implement `java.io.Serializable`. +==== + .renames: MapProperty [%collapsible] ==== @@ -86,4 +94,3 @@ Keys in this mapping can be arbitrary strings, including an empty string. Values must be valid dot-separated fully qualifed class name prefixes, possibly terminated by a dot. ==== -// TODO: fixme (implementSerializable) diff --git a/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/CliJavaCodeGeneratorOptions.kt b/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/CliJavaCodeGeneratorOptions.kt index 47c882030..fe8bd4ff6 100644 --- a/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/CliJavaCodeGeneratorOptions.kt +++ b/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/CliJavaCodeGeneratorOptions.kt @@ -35,25 +35,35 @@ data class CliJavaCodeGeneratorOptions( */ val generateGetters: Boolean = false, - /** Whether to generate Javadoc based on doc comments for Pkl modules, classes, and properties. */ + /** Whether to preserve Pkl doc comments by generating Javadoc comments. */ val generateJavadoc: Boolean = false, /** Whether to generate config classes for use with Spring Boot. */ val generateSpringBootConfig: Boolean = false, /** - * Fully qualified name of the annotation to use on constructor parameters. If this options is not - * set, [org.pkl.config.java.mapper.Named] will be used. + * Fully qualified name of the annotation type to use for annotating constructor parameters with + * their name. + * + * The specified annotation type must have a `value` parameter of type [java.lang.String] or the + * generated code may not compile. + * + * If set to `null`, constructor parameters are not annotated. The default value is `null` if + * [generateSpringBootConfig] is `true` and `"org.pkl.config.java.mapper.Named"` otherwise. */ - val paramsAnnotation: String? = null, + val paramsAnnotation: String? = + if (generateSpringBootConfig) null else "org.pkl.config.java.mapper.Named", /** - * Fully qualified name of the annotation to use on non-null properties. If this option is not - * set, [org.pkl.config.java.mapper.NonNull] will be used. + * Fully qualified name of the annotation type to use for annotating non-null types. + * + * The specified annotation type must have a [java.lang.annotation.Target] of + * [java.lang.annotation.ElementType.TYPE_USE] or the generated code may not compile. If set to + * `null`, [org.pkl.config.java.mapper.NonNull] will be used. */ val nonNullAnnotation: String? = null, - /** Whether to make generated classes implement [java.io.Serializable] */ + /** Whether to generate classes that implement [java.io.Serializable]. */ val implementSerializable: Boolean = false, /** diff --git a/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt b/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt index d7d6489e8..30d9db312 100644 --- a/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt +++ b/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt @@ -54,25 +54,35 @@ data class JavaCodeGeneratorOptions( */ val generateGetters: Boolean = false, - /** Whether to generate Javadoc based on doc comments for Pkl modules, classes, and properties. */ + /** Whether to preserve Pkl doc comments by generating Javadoc comments. */ val generateJavadoc: Boolean = false, /** Whether to generate config classes for use with Spring Boot. */ val generateSpringBootConfig: Boolean = false, /** - * Fully qualified name of the annotation to use on constructor parameters. If this options is not - * set, [org.pkl.config.java.mapper.Named] will be used. + * Fully qualified name of the annotation type to use for annotating constructor parameters with + * their name. + * + * The specified annotation type must have a `value` parameter of type [java.lang.String] or the + * generated code may not compile. + * + * If set to `null`, constructor parameters are not annotated. The default value is `null` if + * [generateSpringBootConfig] is `true` and `"org.pkl.config.java.mapper.Named"` otherwise. */ - val paramsAnnotation: String? = null, + val paramsAnnotation: String? = + if (generateSpringBootConfig) null else "org.pkl.config.java.mapper.Named", /** - * Fully qualified name of the annotation to use on non-null properties. If this option is not - * set, [org.pkl.config.java.mapper.NonNull] will be used. + * Fully qualified name of the annotation type to use for annotating non-null types. + * + * The specified annotation type must have a [java.lang.annotation.Target] of + * [java.lang.annotation.ElementType.TYPE_USE] or the generated code may not compile. If set to + * `null`, [org.pkl.config.java.mapper.NonNull] will be used. */ val nonNullAnnotation: String? = null, - /** Whether to make generated classes implement [java.io.Serializable] */ + /** Whether to generate classes that implement [java.io.Serializable]. */ val implementSerializable: Boolean = false, /** @@ -232,15 +242,15 @@ class JavaCodeGenerator( propJavaName: String, property: PClass.Property ) { - builder.addParameter( - ParameterSpec.builder(property.type.toJavaPoetName(), propJavaName) - .addAnnotation( - AnnotationSpec.builder(namedAnnotationName) - .addMember("value", "\$S", property.simpleName) - .build() - ) - .build() - ) + val paramBuilder = ParameterSpec.builder(property.type.toJavaPoetName(), propJavaName) + if (paramsAnnotationName != null) { + paramBuilder.addAnnotation( + AnnotationSpec.builder(paramsAnnotationName) + .addMember("value", "\$S", property.simpleName) + .build() + ) + } + builder.addParameter(paramBuilder.build()) } fun generateConstructor(isInstantiable: Boolean): MethodSpec { @@ -670,12 +680,8 @@ class JavaCodeGenerator( return builder } - private val namedAnnotationName = - if (codegenOptions.paramsAnnotation != null) { - toClassName(codegenOptions.paramsAnnotation) - } else { - ClassName.get("org.pkl.config.java.mapper", "Named") - } + private val paramsAnnotationName: ClassName? = + codegenOptions.paramsAnnotation?.let { toClassName(it) } private fun appendPropertyMethod() = MethodSpec.methodBuilder("appendProperty") diff --git a/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/Main.kt b/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/Main.kt index a132f1782..d300caf7f 100644 --- a/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/Main.kt +++ b/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/Main.kt @@ -17,10 +17,7 @@ package org.pkl.codegen.java -import com.github.ajalt.clikt.parameters.options.associate -import com.github.ajalt.clikt.parameters.options.default -import com.github.ajalt.clikt.parameters.options.flag -import com.github.ajalt.clikt.parameters.options.option +import com.github.ajalt.clikt.parameters.options.* import com.github.ajalt.clikt.parameters.types.path import java.nio.file.Path import org.pkl.commons.cli.CliBaseOptions @@ -71,33 +68,37 @@ class PklJavaCodegenCommand : private val generateJavadoc: Boolean by option( names = arrayOf("--generate-javadoc"), - help = - "Whether to generate Javadoc based on doc comments " + - "for Pkl modules, classes, and properties." + help = "Whether to preserve Pkl doc comments by generating Javadoc comments." ) .flag() - private val generateSpringboot: Boolean by + private val generateSpringBoot: Boolean by option( names = arrayOf("--generate-spring-boot"), - help = "Whether to generate config classes for use with Spring boot." + help = "Whether to generate config classes for use with Spring Boot." ) .flag() - private val paramsAnnotation: String? by + private val paramsAnnotation: String by option( - names = arrayOf("--params-annotation"), - help = "Fully qualified name of the annotation to use on constructor parameters." - ) + names = arrayOf("--params-annotation"), + help = + "Fully qualified name of the annotation type to use for annotating constructor parameters with their name." + ) + .defaultLazy( + "`none` if `--generate-spring-boot` is set, `org.pkl.config.java.mapper.Named` otherwise" + ) { + if (generateSpringBoot) "none" else "org.pkl.config.java.mapper.Named" + } private val nonNullAnnotation: String? by option( names = arrayOf("--non-null-annotation"), help = """ - Fully qualified named of the annotation class to use for non-null types. - This annotation is required to have `java.lang.annotation.ElementType.TYPE_USE` as a `@Target` - or it may generate code that does not compile. + Fully qualified name of the annotation type to use for annotating non-null types. + The specified annotation type must be annotated with `@java.lang.annotation.Target(ElementType.TYPE_USE)` + or the generated code may not compile. """ .trimIndent() ) @@ -105,7 +106,7 @@ class PklJavaCodegenCommand : private val implementSerializable: Boolean by option( names = arrayOf("--implement-serializable"), - help = "Whether to make generated classes implement java.io.Serializable." + help = "Whether to generate classes that implement java.io.Serializable." ) .flag() @@ -117,7 +118,7 @@ class PklJavaCodegenCommand : """ Replace a prefix in the names of the generated Java classes (repeatable). By default, the names of generated classes are derived from the Pkl module names. - With this option, you can override the modify the default names, renaming entire + With this option, you can override or modify the default names, renaming entire classes or just their packages. """ .trimIndent() @@ -132,8 +133,8 @@ class PklJavaCodegenCommand : indent = indent, generateGetters = generateGetters, generateJavadoc = generateJavadoc, - generateSpringBootConfig = generateSpringboot, - paramsAnnotation = paramsAnnotation, + generateSpringBootConfig = generateSpringBoot, + paramsAnnotation = if (paramsAnnotation == "none") null else paramsAnnotation, nonNullAnnotation = nonNullAnnotation, implementSerializable = implementSerializable, renames = renames diff --git a/pkl-codegen-java/src/test/kotlin/org/pkl/codegen/java/JavaCodeGeneratorTest.kt b/pkl-codegen-java/src/test/kotlin/org/pkl/codegen/java/JavaCodeGeneratorTest.kt index 76daaeaea..a744293bd 100644 --- a/pkl-codegen-java/src/test/kotlin/org/pkl/codegen/java/JavaCodeGeneratorTest.kt +++ b/pkl-codegen-java/src/test/kotlin/org/pkl/codegen/java/JavaCodeGeneratorTest.kt @@ -104,26 +104,10 @@ class JavaCodeGeneratorTest { private fun generateJavaCode( pklCode: String, - generateGetters: Boolean = false, - generateJavadoc: Boolean = false, - generateSpringBootConfig: Boolean = false, - nonNullAnnotation: String? = null, - implementSerializable: Boolean = false, - renames: Map = emptyMap() + options: JavaCodeGeneratorOptions = JavaCodeGeneratorOptions() ): JavaSourceCode { val module = Evaluator.preconfigured().evaluateSchema(text(pklCode)) - val generator = - JavaCodeGenerator( - module, - JavaCodeGeneratorOptions( - generateGetters = generateGetters, - generateJavadoc = generateJavadoc, - generateSpringBootConfig = generateSpringBootConfig, - nonNullAnnotation = nonNullAnnotation, - implementSerializable = implementSerializable, - renames = renames - ) - ) + val generator = JavaCodeGenerator(module, options) return JavaSourceCode(generator.javaFile) } } @@ -235,7 +219,7 @@ class JavaCodeGeneratorTest { } """ .trimIndent(), - generateJavadoc = true + JavaCodeGeneratorOptions(generateJavadoc = true) ) assertThat(javaCode) .contains( @@ -274,8 +258,7 @@ class JavaCodeGeneratorTest { } """ .trimIndent(), - generateGetters = true, - generateJavadoc = true + JavaCodeGeneratorOptions(generateGetters = true, generateJavadoc = true) ) assertThat(javaCode) .contains( @@ -322,7 +305,7 @@ class JavaCodeGeneratorTest { } """ .trimIndent(), - generateJavadoc = true + JavaCodeGeneratorOptions(generateJavadoc = true) ) assertThat(javaCode) .contains( @@ -349,7 +332,7 @@ class JavaCodeGeneratorTest { propertyInDeprecatedModuleClass : Int = 42 """ .trimIndent(), - generateJavadoc = generateJavadoc + JavaCodeGeneratorOptions(generateJavadoc = generateJavadoc) ) assertThat(javaCode) @@ -389,7 +372,7 @@ class JavaCodeGeneratorTest { """ .trimIndent(), // no message, so no Javadoc, regardless of flag - generateJavadoc = generateJavadoc + JavaCodeGeneratorOptions(generateJavadoc = generateJavadoc) ) assertThat(javaCode) @@ -424,7 +407,7 @@ class JavaCodeGeneratorTest { } """ .trimIndent(), - generateGetters = true + JavaCodeGeneratorOptions(generateGetters = true) ) assertThat(javaCode) @@ -513,7 +496,7 @@ class JavaCodeGeneratorTest { @Deprecated { message = "property is deprecated" } deprecatedProperty: Int """, - generateJavadoc = true + JavaCodeGeneratorOptions(generateJavadoc = true) ) assertThat(javaCode) @@ -735,7 +718,7 @@ class JavaCodeGeneratorTest { } """ .trimIndent(), - generateGetters = true + JavaCodeGeneratorOptions(generateGetters = true) ) assertThat(javaCode) @@ -889,7 +872,7 @@ class JavaCodeGeneratorTest { } """ .trimIndent(), - generateGetters = true + JavaCodeGeneratorOptions(generateGetters = true) ) assertThat(javaCode).compilesSuccessfully().isEqualToResourceFile("GenerateGetters.jva") @@ -1002,7 +985,7 @@ class JavaCodeGeneratorTest { } """ .trimIndent(), - generateJavadoc = true + JavaCodeGeneratorOptions(generateJavadoc = true) ) assertThat(javaCode).compilesSuccessfully().isEqualToResourceFile("Javadoc.jva") @@ -1026,8 +1009,7 @@ class JavaCodeGeneratorTest { } """ .trimIndent(), - generateGetters = true, - generateJavadoc = true + JavaCodeGeneratorOptions(generateGetters = true, generateJavadoc = true) ) assertThat(javaCode) @@ -1169,7 +1151,7 @@ class JavaCodeGeneratorTest { foo: String """ .trimIndent(), - nonNullAnnotation = "com.example.Annotations\$NonNull" + JavaCodeGeneratorOptions(nonNullAnnotation = "com.example.Annotations\$NonNull") ) assertThat(javaCode) @@ -1463,6 +1445,40 @@ class JavaCodeGeneratorTest { .contains("public final @NonNull String v6;") } + @Test + fun `custom constructor parameter annotation`() { + val javaCode = + generateJavaCode( + """ + module my.mod + + name: String + """ + .trimIndent(), + JavaCodeGeneratorOptions(paramsAnnotation = "org.project.MyAnnotation") + ) + + assertThat(javaCode) + .contains("import org.project.MyAnnotation;") + .contains("public Mod(@MyAnnotation(\"name\") @NonNull String name)") + } + + @Test + fun `no constructor parameter annotation`() { + val javaCode = + generateJavaCode( + """ + module my.mod + + name: String + """ + .trimIndent(), + JavaCodeGeneratorOptions(paramsAnnotation = null) + ) + + assertThat(javaCode).contains("public Mod(@NonNull String name)") + } + @Test fun `spring boot config`() { val javaCode = @@ -1478,7 +1494,7 @@ class JavaCodeGeneratorTest { } """ .trimIndent(), - generateSpringBootConfig = true + JavaCodeGeneratorOptions(generateSpringBootConfig = true) ) assertThat(javaCode) @@ -1511,6 +1527,7 @@ class JavaCodeGeneratorTest { .trimMargin() ) .doesNotContain("@ConstructorBinding") + .doesNotContain("@Named") // not worthwhile to add spring & spring boot dependency just so that this test can compile // their annotations @@ -1765,7 +1782,7 @@ class JavaCodeGeneratorTest { typealias Direction = "north"|"east"|"south"|"west" """ .trimIndent(), - implementSerializable = true + JavaCodeGeneratorOptions(implementSerializable = true) ) assertThat(javaCode) @@ -1846,7 +1863,7 @@ class JavaCodeGeneratorTest { abstract class Foo { str: String } """ .trimIndent(), - implementSerializable = true + JavaCodeGeneratorOptions(implementSerializable = true) ) assertThat(javaCode).doesNotContain("Serializable") @@ -1857,7 +1874,7 @@ class JavaCodeGeneratorTest { module my.mod """ .trimIndent(), - implementSerializable = true + JavaCodeGeneratorOptions(implementSerializable = true) ) assertThat(javaCode).doesNotContain("Serializable") @@ -1874,7 +1891,7 @@ class JavaCodeGeneratorTest { class Address { city: String } """ .trimIndent(), - implementSerializable = true + JavaCodeGeneratorOptions(implementSerializable = true) ) assertThat(javaCode) @@ -1960,7 +1977,7 @@ class JavaCodeGeneratorTest { } """ .trimIndent(), - generateGetters = true + JavaCodeGeneratorOptions(generateGetters = true) ) assertThat(javaCode) diff --git a/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/CliKotlinCodeGeneratorOptions.kt b/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/CliKotlinCodeGeneratorOptions.kt index 1a1ef6075..80c57e954 100644 --- a/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/CliKotlinCodeGeneratorOptions.kt +++ b/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/CliKotlinCodeGeneratorOptions.kt @@ -29,13 +29,13 @@ data class CliKotlinCodeGeneratorOptions( /** The characters to use for indenting generated source code. */ val indent: String = " ", - /** Whether to generate Kdoc based on doc comments for Pkl modules, classes, and properties. */ + /** Whether to preserve Pkl doc comments by generating KDoc comments. */ val generateKdoc: Boolean = false, /** Whether to generate config classes for use with Spring Boot. */ val generateSpringBootConfig: Boolean = false, - /** Whether to make generated classes implement [java.io.Serializable] */ + /** Whether generated classes should implement [java.io.Serializable]. */ val implementSerializable: Boolean = false, /** diff --git a/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/KotlinCodeGenerator.kt b/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/KotlinCodeGenerator.kt index d3a2f2e10..51b9083e4 100644 --- a/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/KotlinCodeGenerator.kt +++ b/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/KotlinCodeGenerator.kt @@ -32,13 +32,13 @@ data class KotlinCodeGeneratorOptions( /** The characters to use for indenting generated Kotlin code. */ val indent: String = " ", - /** Whether to generate KDoc based on doc comments for Pkl modules, classes, and properties. */ + /** Whether to preserve Pkl doc comments by generating KDoc comments. */ val generateKdoc: Boolean = false, /** Whether to generate config classes for use with Spring Boot. */ val generateSpringBootConfig: Boolean = false, - /** Whether to make generated classes implement [java.io.Serializable] */ + /** Whether to generate classes that implement [java.io.Serializable]. */ val implementSerializable: Boolean = false, /** diff --git a/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/Main.kt b/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/Main.kt index 2a664b3cc..bcaea57b3 100644 --- a/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/Main.kt +++ b/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/Main.kt @@ -62,23 +62,21 @@ class PklKotlinCodegenCommand : private val generateKdoc: Boolean by option( names = arrayOf("--generate-kdoc"), - help = - "Whether to generate Kdoc based on doc comments " + - "for Pkl modules, classes, and properties." + help = "Whether to preserve Pkl doc comments by generating KDoc comments." ) .flag() private val generateSpringboot: Boolean by option( names = arrayOf("--generate-spring-boot"), - help = "Whether to generate config classes for use with Spring boot." + help = "Whether to generate config classes for use with Spring Boot." ) .flag() private val implementSerializable: Boolean by option( names = arrayOf("--implement-serializable"), - help = "Whether to make generated classes implement java.io.Serializable" + help = "Whether to generate classes that implement java.io.Serializable." ) .flag() @@ -90,7 +88,7 @@ class PklKotlinCodegenCommand : """ Replace a prefix in the names of the generated Kotlin classes (repeatable). By default, the names of generated classes are derived from the Pkl module names. - With this option, you can override the modify the default names, renaming entire + With this option, you can override or modify the default names, renaming entire classes or just their packages. """ .trimIndent() diff --git a/pkl-gradle/src/main/java/org/pkl/gradle/PklPlugin.java b/pkl-gradle/src/main/java/org/pkl/gradle/PklPlugin.java index 86a0c2342..cb2abdc89 100644 --- a/pkl-gradle/src/main/java/org/pkl/gradle/PklPlugin.java +++ b/pkl-gradle/src/main/java/org/pkl/gradle/PklPlugin.java @@ -189,6 +189,15 @@ private void configureJavaCodeGenTasks(NamedDomainObjectContainer + spec.getGenerateSpringBootConfig().get() + ? null + : "org.pkl.config.java.mapper.Named")); createModulesTask(JavaCodeGenTask.class, spec) .configure(