Skip to content

Always include parameter docs in the type header #1800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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()
Expand All @@ -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())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
| /**
Expand Down Expand Up @@ -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,
|)
|
Expand Down