aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEgor Andreevich <egor@squareup.com>2024-01-10 11:33:12 +0100
committerEgor Andreevich <github@egorand.dev>2024-01-10 07:08:32 -0500
commit1efd9e6e851b95d37b8fe83ef8be0d7b0a487cb7 (patch)
tree9ff844b2e72afe662a1a7e4fe9d9a5cda2ce5008
parentfaaca40102314432d2281e98084176432105c150 (diff)
downloadkotlinpoet-1efd9e6e851b95d37b8fe83ef8be0d7b0a487cb7.tar.gz
Always include parameter docs in the type header
-rw-r--r--kotlinpoet/src/commonMain/kotlin/com/squareup/kotlinpoet/ParameterSpec.kt2
-rw-r--r--kotlinpoet/src/commonMain/kotlin/com/squareup/kotlinpoet/TypeSpec.kt11
-rw-r--r--kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeSpecTest.kt17
3 files changed, 12 insertions, 18 deletions
diff --git a/kotlinpoet/src/commonMain/kotlin/com/squareup/kotlinpoet/ParameterSpec.kt b/kotlinpoet/src/commonMain/kotlin/com/squareup/kotlinpoet/ParameterSpec.kt
index 15cf4bf0..91dc8b06 100644
--- a/kotlinpoet/src/commonMain/kotlin/com/squareup/kotlinpoet/ParameterSpec.kt
+++ b/kotlinpoet/src/commonMain/kotlin/com/squareup/kotlinpoet/ParameterSpec.kt
@@ -54,10 +54,8 @@ public class ParameterSpec private constructor(
internal fun emit(
codeWriter: CodeWriter,
includeType: Boolean = true,
- emitKdoc: Boolean = false,
inlineAnnotations: Boolean = true,
) {
- if (emitKdoc) codeWriter.emitKdoc(kdoc.ensureEndsWithNewLine())
codeWriter.emitAnnotations(annotations, inlineAnnotations)
codeWriter.emitModifiers(modifiers)
if (name.isNotEmpty()) codeWriter.emitCode("%N", this)
diff --git a/kotlinpoet/src/commonMain/kotlin/com/squareup/kotlinpoet/TypeSpec.kt b/kotlinpoet/src/commonMain/kotlin/com/squareup/kotlinpoet/TypeSpec.kt
index 43ae82a2..af0613b3 100644
--- a/kotlinpoet/src/commonMain/kotlin/com/squareup/kotlinpoet/TypeSpec.kt
+++ b/kotlinpoet/src/commonMain/kotlin/com/squareup/kotlinpoet/TypeSpec.kt
@@ -209,7 +209,7 @@ public class TypeSpec private constructor(
)
param.emitDefaultValue(codeWriter)
} else {
- param.emit(codeWriter, emitKdoc = true, inlineAnnotations = false)
+ param.emit(codeWriter, inlineAnnotations = false)
}
}
@@ -374,10 +374,7 @@ public class TypeSpec private constructor(
/**
* Returns KDoc comments including those of the primary constructor and its parameters.
*
- * If the primary constructor parameter is not mapped to a property, or if the property doesn't
- * have its own KDoc - the parameter's KDoc will be attached to the parameter. Otherwise, if both
- * the parameter and the property have KDoc - the property's KDoc will be attached to the
- * property/parameter, and the parameter's KDoc will be printed in the type header.
+ * Parameters' KDocs, if present, will always be printed in the type header.
*/
private fun kdocWithConstructorDocs(): CodeBlock {
val classKdoc = kdoc.ensureEndsWithNewLine()
@@ -386,10 +383,8 @@ public class TypeSpec private constructor(
if (primaryConstructor.kdoc.isNotEmpty()) {
add("@constructor %L", primaryConstructor.kdoc.ensureEndsWithNewLine())
}
- val constructorProperties = constructorProperties()
primaryConstructor.parameters.forEach { parameter ->
- val propertyKdoc = constructorProperties[parameter.name]?.kdoc ?: CodeBlock.EMPTY
- if (parameter.kdoc.isNotEmpty() && propertyKdoc.isNotEmpty() && parameter.kdoc != propertyKdoc) {
+ if (parameter.kdoc.isNotEmpty()) {
add("@param %L %L", parameter.name, parameter.kdoc.ensureEndsWithNewLine())
}
}
diff --git a/kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeSpecTest.kt b/kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeSpecTest.kt
index 4d8a8369..94732b61 100644
--- a/kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeSpecTest.kt
+++ b/kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeSpecTest.kt
@@ -1975,14 +1975,12 @@ class TypeSpecTest {
| * [random][java.util.Random] tex-mex stuff we could find in the pantry
| * and some [kotlin.String] cheese.
| *
+ | * @param temperature Taco temperature. Can be as cold as the famous ice tacos from
+ | * the Andes, or hot with lava-like cheese from the depths of
+ | * the Ninth Circle.
| * @param mild Whether the taco is mild (ew) or crunchy (ye).
| */
|public class Taco(
- | /**
- | * Taco temperature. Can be as cold as the famous ice tacos from
- | * the Andes, or hot with lava-like cheese from the depths of
- | * the Ninth Circle.
- | */
| temperature: Double,
| /**
| * True for a soft flour tortilla; false for a crunchy corn tortilla.
@@ -4805,6 +4803,9 @@ class TypeSpecTest {
| * This is a thing for stuff.
| *
| * @constructor Construct a thing!
+ | * @param first the first thing
+ | * @param second the second thing
+ | * @param third the third thing
| */
|public class MyType(
| /**
@@ -4839,10 +4840,10 @@ class TypeSpecTest {
.build()
assertThat(typeSpec.toString()).isEqualTo(
"""
+ |/**
+ | * @param first the first thing
+ | */
|public class MyType(
- | /**
- | * the first thing
- | */
| first: kotlin.Int,
|)
|