mirror of
https://github.com/apple/pkl.git
synced 2026-03-24 01:51:19 +01:00
codegen-java: Support not annotating constructor parameters (#792)
Motivation: Spring Boot configuration classes neither require nor benefit from annotating constructor parameters with their name. The same is true for pkl-config-java configuration classes compiled with `-parameter`. Changes: - Change CLI parameter `--params-annotation` to accept a `none` value. This is recommended in https://clig.dev/#arguments-and-flags and is how the `-F` parameter of the `ssh` command works. - Change `paramsAnnotation` property in Gradle plugin, CliJavaCodeGeneratorOptions, and JavaCodegenOptions as follows: - Change meaning of `null` from "generate org.pkl.java.config.mapper.Named annotations" to "do not generate annotations". This is a breaking change (only) affecting users who explicitly set the property to `null` instead of omitting it. - Change property default from `null` to: `null` if `generateSpringBootConfig` is `true` and `org.pkl.java.config.mapper.Named` otherwise - add tests - update docs of this and other codegen options Result: Generated code does not contain unnecessary annotations.
This commit is contained in:
@@ -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 corresponding 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,
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 corresponding 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,
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 corresponding 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()
|
||||
|
||||
Reference in New Issue
Block a user