Skip to content

Javadoc: preserve multi-line HTML comments inside block tags#7500

Merged
timtebeek merged 1 commit intomainfrom
tim/javadoc-xml-comment
Apr 28, 2026
Merged

Javadoc: preserve multi-line HTML comments inside block tags#7500
timtebeek merged 1 commit intomainfrom
tim/javadoc-xml-comment

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented Apr 28, 2026

Summary

  • A multi-line <!-- ... --> HTML comment inside a Javadoc block tag (e.g. @version, @param, @return) was printed back with the leading * margin missing on interior lines and with orphan * lines appended after the comment.
  • convertMultiline already routed DCText through visitText (which consumes a LineBreak per newline). DCComment fell through to scan -> visitComment, which bumped the cursor by the body length in one shot and wrapped the multi-line body in a single Javadoc.Text — so interior margins were dropped and the unconsumed LineBreaks spilled out at the end of the doc.
  • Mirror the DCText handling for DCComment in convertMultiline across rewrite-java-{8,11,17,21,25} and add a regression test.
  • Closes https://github.com/moderneinc/customer-requests/issues/2277

Test plan

  • ./gradlew :rewrite-java-21:compatibilityTest --tests "*JavadocTest*"
  • ./gradlew :rewrite-java-{8,11,17,25}:compatibilityTest

`convertMultiline` already routed `DCText` through `visitText` so that
each newline consumes the corresponding `LineBreak` (with its `*` margin)
from the lineBreaks map. `DCComment` fell through to `scan`/`visitComment`,
which bumped the cursor by the body length in one shot and wrapped the
multi-line body in a single `Javadoc.Text`. The result was that interior
`*` margins were dropped and orphan `LineBreak`s were appended at the end
of the doc as extra blank `*` lines. Mirror the `DCText` handling for
`DCComment` across all version-specific visitors.
@timtebeek timtebeek added bug Something isn't working java javadoc parser labels Apr 28, 2026
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Apr 28, 2026
@timtebeek timtebeek merged commit 7fb338d into main Apr 28, 2026
1 check passed
@timtebeek timtebeek deleted the tim/javadoc-xml-comment branch April 28, 2026 15:31
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working java javadoc parser

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants