Skip to content

Normalize Kotlin type parameter bound colon spacing - #8558

Merged
timtebeek merged 1 commit into
mainfrom
tim/issue-6613-minimal-fix
Aug 20, 2026
Merged

timtebeek merged 1 commit into
mainfrom
tim/issue-6613-minimal-fix

Conversation

@timtebeek

@timtebeek timtebeek commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

The whitespace before the colon of a type parameter bound was stored in the bounds JContainer.before with an empty TypeReferencePrefix marker, while where constraints on the same J.TypeParameter store it in the marker; since SpacesVisitor only ever looked at the marker, fun <T : Number> was never normalized. The parser now stores that space in the marker in both cases, which prints identically but gives formatters a single place to look.

SpacesVisitor formats type parameter bounds with beforeColonInNewTypeDefinition/afterColonInNewTypeDefinition rather than the declaration-name options, matching Kotlin conventions (val x: Int but fun <T : Number>) and putting those two previously unused style options to work.

The whitespace before the colon of a type parameter bound was stored in
the bounds `JContainer.before` with an empty `TypeReferencePrefix`, while
`where` constraints on the same `J.TypeParameter` store it in the marker.
`SpacesVisitor` only ever looked at the marker, so `fun <T   :   Number>`
was never normalized.

Store the space in the marker in both cases, and format type parameter
bounds with `beforeColonInNewTypeDefinition`/`afterColonInNewTypeDefinition`,
which matches Kotlin conventions (`val x: Int` but `fun <T : Number>`) and
puts those previously unused style options to work.

Fixes #6613
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Aug 19, 2026
@timtebeek timtebeek added kotlin bug Something isn't working labels Aug 19, 2026
@timtebeek timtebeek mentioned this pull request Aug 19, 2026
4 tasks
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Aug 20, 2026
@timtebeek
timtebeek merged commit 2bfe8e9 into main Aug 20, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Aug 20, 2026
@timtebeek
timtebeek deleted the tim/issue-6613-minimal-fix branch August 20, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working kotlin

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Kotlin type reference spacing is stored inconsistently and difficult to modify in recipes

2 participants