Java: fix Javadoc roundtrip for multi-line HTML comments inside block tags#7539
Closed
knutwannheden wants to merge 2 commits intomainfrom
Closed
Java: fix Javadoc roundtrip for multi-line HTML comments inside block tags#7539knutwannheden wants to merge 2 commits intomainfrom
knutwannheden wants to merge 2 commits intomainfrom
Conversation
… tags `visitComment` consumed `node.getBody().length()` characters of cursor and emitted a single `Javadoc.Text` containing the entire body. For multi-line HTML comments this dropped the leading-line `*` margins on print and left the corresponding `LineBreak` markers stranded in the `lineBreaks` map, where they leaked out as trailing `*` lines before `**/`. Route `DCComment` through the same `visitText(body)` path that `visitDocComment` already uses for top-level HTML comments, so the body's newlines are processed and the margin `LineBreak`s are consumed.
Contributor
Author
|
Looks like this was fixed already. Just found this old branch on my computer... |
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
@versionblock tag fails to parse-and-print back to the original source. The leading*margins on the inner lines of the HTML comment are dropped, and stray*lines appear before the closing**/.The root cause is in
ReloadableJava{8,11,17,21,25}JavadocVisitor.convertMultiline. Block-tag bodies (@version,@author,@deprecated,@since,@hidden,@return,@param,@throws,@serial, …) flow throughconvertMultiline, which dispatches non-text children viascan(dt, emptyList()). For an HTML comment that lands invisitComment, which only handles single-line bodies — it doescursor += node.getBody().length()and emits a singleJavadoc.Textwith the entire body inline. For a multi-line body this:LineBreakmarkers in the visitor'slineBreaksmap are never consumed and leak out at the end ofvisitDocCommentas the extra*lines before**/;Textwith embedded\ns, so the printer never re-emits the per-line*margin.visitDocCommentalready special-casesDCCommentat the top level and routes it throughvisitText(body), which handles newlines correctly. The fix extends that routing toconvertMultilineso block-tag bodies behave the same.Summary
convertMultilinenow dispatchesDCTree.DCCommenttovisitText(body), mirroring the existing handling forDCText(andDCRawTexton Java 25).rewrite-java-8/11/17/21/25).JavadocTest.htmlCommentNestedAfterVersionTagcovering the customer's input.Test plan
./gradlew :rewrite-java-8:compatibilityTest :rewrite-java-11:compatibilityTest :rewrite-java-17:compatibilityTest :rewrite-java-21:compatibilityTest :rewrite-java-25:compatibilityTest --tests "org.openrewrite.java.tree.JavadocTest"— all pass on every version, including the new regression test.