Skip to content
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

ParameterSpec.addKdoc without class Kdoc generates extra leading new line #843

Closed
reneeleung opened this issue Dec 18, 2019 · 2 comments · Fixed by #844
Closed

ParameterSpec.addKdoc without class Kdoc generates extra leading new line #843

reneeleung opened this issue Dec 18, 2019 · 2 comments · Fixed by #844

Comments

@reneeleung
Copy link

No description provided.

@Egorand
Copy link
Collaborator

Egorand commented Dec 18, 2019

Need more info: what's the output, what's expected, ideally a reproducible test case.

@reneeleung reneeleung changed the title ParameterSpec.addKdoc twice generates unexpected output ParameterSpec.addKdoc without class Kdoc generates extra leading new line Dec 18, 2019
@reneeleung
Copy link
Author

reneeleung commented Dec 18, 2019

Expected output:

     /**
      * @param mild Whether the taco is mild (ew) or crunchy (ye).
      */
     class Taco(

Actual output:

     /**
      *
      * @param mild Whether the taco is mild (ew) or crunchy (ye).
      */
     class Taco(

A unit test for this test case:

  @Test fun kdocWithParametersWithoutClassKdoc() {
    val taco = TypeSpec.classBuilder("Taco")
        .primaryConstructor(FunSpec.constructorBuilder()
            .addParameter(ParameterSpec.builder("mild", Boolean::class)
                .addKdoc(CodeBlock.of("%L", "Whether the taco is mild (ew) or crunchy (ye).\n"))
                .build())
            .build())
        .addProperty(PropertySpec.builder("mild", Boolean::class)
            .addKdoc("No one likes mild tacos.")
            .initializer("mild")
            .build())
        .build()
    assertThat(toString(taco)).isEqualTo("""
        |package com.squareup.tacos
        |
        |import kotlin.Boolean
        |
        |/**
        | * @param mild Whether the taco is mild (ew) or crunchy (ye).
        | */
        |class Taco(
        |  /**
        |   * No one likes mild tacos.
        |   */
        |  val mild: Boolean
        |)
        |""".trimMargin())
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants