Skip to content

Fix delegated constructor multiline formatting#2332

Open
istvan-florio wants to merge 1 commit into
square:mainfrom
istvan-florio:1762-format-delegated-constructors
Open

Fix delegated constructor multiline formatting#2332
istvan-florio wants to merge 1 commit into
square:mainfrom
istvan-florio:1762-format-delegated-constructors

Conversation

@istvan-florio

Copy link
Copy Markdown

Fixes #1762.

Summary

  • Preserve the existing one-line delegated constructor formatting for simple this(...) / super(...) calls.
  • Expand delegated constructor calls to one argument per line when any delegated constructor argument explicitly emits multiline code.
  • Cover this, super, constructor body formatting, newline string literals, and long single-line arguments with exact output tests.

Note: the multiline predicate intentionally targets explicit emitted newlines in CodeBlock formatting. String literal contents emitted via %S / %P are left on the existing path so raw/string-literal newlines do not force expanded delegated-call formatting.

Test plan

  • ./gradlew :kotlinpoet:jvmTest --tests com.squareup.kotlinpoet.FunSpecTest

  • ./gradlew :kotlinpoet:apiCheck

  • git diff --check

  • ./gradlew clean build

  • docs/changelog.md has been updated if applicable.

    • Changes not visible to library consumers, such as build script, documentation, or test code updates, don't need to
      be added to the changelog.
  • CLA signed.

for (formatPart in formatParts) {
if ('\n' in formatPart) return true

if (formatPart == "%L") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't handle positional format arguments.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we normalize those on the way in. I honestly can't remember...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chained constructor call is not formatted correctly

3 participants