Skip to content

Commit

Permalink
Remove superfluous newline
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed Nov 18, 2023
1 parent 6e302a9 commit e0911f8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,16 @@ public class TypeSpec private constructor(
parameter.kdoc != propertyKdoc
}
return with(kdoc.ensureEndsWithNewLine().toBuilder()) {
if (kdoc.isNotEmpty()) add("\n")
if (primaryConstructor.kdoc.isNotEmpty()) {
add("@constructor %L", primaryConstructor.kdoc.ensureEndsWithNewLine())
}
parametersWithKdoc.forEach { parameter ->
add("@param %L %L", parameter.name, parameter.kdoc.ensureEndsWithNewLine())
if (primaryConstructor.kdoc.isNotEmpty() || parametersWithKdoc.isNotEmpty()) {
if (isNotEmpty()) {
add("\n")
}
if (primaryConstructor.kdoc.isNotEmpty()) {
add("@constructor %L", primaryConstructor.kdoc.ensureEndsWithNewLine())
}
parametersWithKdoc.forEach { parameter ->
add("@param %L %L", parameter.name, parameter.kdoc.ensureEndsWithNewLine())
}
}
build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5615,6 +5615,27 @@ class TypeSpecTest {
)
}

@Test fun classKdoc() {
val type = TypeSpec.classBuilder("MyClass")
.addKdoc("This is my class")
.primaryConstructor(
FunSpec.constructorBuilder()
.build(),
)
.build()

//language=kotlin
assertThat(type.toString()).isEqualTo(
"""
/**
* This is my class
*/
public class MyClass()
""".trimIndent(),
)
}

// https://github.com/square/kotlinpoet/issues/1630
@Test fun primaryConstructorKDoc() {
val type = TypeSpec.classBuilder("MyClass")
Expand Down

0 comments on commit e0911f8

Please sign in to comment.