Skip to content

Preserve /// markers when wrapping long line comments - #1434

Open
arimu1 wants to merge 1 commit into
google:masterfrom
arimu1:fix/1369-markdown-link-wrap
Open

Preserve /// markers when wrapping long line comments#1434
arimu1 wants to merge 1 commit into
google:masterfrom
arimu1:fix/1369-markdown-link-wrap

Conversation

@arimu1

@arimu1 arimu1 commented Aug 1, 2026

Copy link
Copy Markdown

Summary

Fixes #1369

wrapLineComments always continued wrapped line comments with //, and treated the non-breakable prefix as length 2. For /// comments that meant:

  1. Long wrappable text continued with // in the middle of a /// block.
  2. Long unbreakable tokens (e.g. markdown links with only a space after ///) were split into a bare /// line plus a // ... line containing the link.

Fix

In JavaCommentsHelper.wrapLineComments:

  • Detect the leading slash run (//, ///, …) and reuse that marker on continuations.
  • Treat the full marker length as non-breakable, matching existing // behavior so unbreakable content after /// is left as a single over-length line rather than mangled.

Tests

  • FormatterTest.wrapTripleSlashLineCommentPreservesPrefix — wrappable /// text continues with ///
  • FormatterTest.doNotBreakLongUnbreakableTripleSlashLink — regression for the issue example (100/101-char markdown links)
  • Updated JavadocFormattingTest.simpleMarkdown expected output for non-javadoc /// lines (previously encoded the buggy // wrap)

Test plan

  • mvn -pl core test on Temurin 25 — 1624 tests, 0 failures
  • Targeted wrap tests on Temurin 21 — green
  • Manual repro of issue sample (links inside method body) no longer injects //

When wrapping line comments that start with ///, reuse that marker on
continuation lines instead of hardcoding //. Also treat the full marker
length as non-breakable so long unbreakable tokens (e.g. markdown links)
are left intact rather than splitting after the leading ///.

Fixes google#1369
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.

Link lines longer than 100 chars are malformed in ///

1 participant