Skip to content

Join hyphenated words across Javadoc line breaks; no blank lines before a leading block tag - #116

Open
abashev wants to merge 2 commits into
mainfrom
gjf-1475-hyphen-join
Open

abashev wants to merge 2 commits into
mainfrom
gjf-1475-hyphen-join

Conversation

@abashev

@abashev abashev commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Two commits, each a port with the upstream author kept, each done test-first.

1. google/google-java-format#1475 (Liam Miller-Cushon, still open upstream). With Javadoc formatting on, infinite- at a line end followed by precision came out as infinite- precision. The lexer now joins a literal ending in a word character plus - with a word literal on the next line, unless it is and/or (pre- and post-processing stays) or a paragraph break sits between them. Adapted to this fork's Token API; the /// markdown test is upstream-only. Tests: hyphenatedLineBreakJoined failed before the change; suspendedHyphenPreserved and hyphenBeforeParagraphBreakNotJoined guard what must not change.

2. Two empty lines at the top of a comment that starts with a block tag. Found while checking palantir#1476: /**\n * <pre>{@code ... (and <ul>, <blockquote>, <h1>, <table>) came out with two * lines after /**, because the tag's blank-line request was honoured right after the opening line. The writer now ignores whitespace requests while nothing significant has been written, the classic-Javadoc half of upstream commit e4cef582 (cpovirk); the footer-tag special case for the same situation is removed as redundant. Tests: preBlockAsFirstContentGetsNoBlankLines, listAsFirstContentGetsNoBlankLines, both failed before the fix.

Full module suite: 1614 tests, 0 failures. Only reachable through JavaFormatterOptions.formatJavadoc(true); the CLI and plugins are unaffected.

cushon and others added 2 commits October 8, 2026 21:33
When a compound word was hyphenated across a line break in Javadoc
(e.g., `infinite-\n * precision`), the formatter previously joined the
tokens with a space, resulting in `infinite- precision`.

Join adjacent word literals across a line break when the preceding literal ends
in a hyphen following a word character, while preserving spaces after suspended
hyphens (e.g., `pre- and post-`).

Ported from google/google-java-format#1475 (commit 55863463), adapted to this
fork's Token API. The markdown `///` test does not apply here. The tests were
written first: hyphenatedLineBreakJoined failed with `infinite- precision`,
suspendedHyphenPreserved and hyphenBeforeParagraphBreakNotJoined guard the
cases that must stay as they are.
A block-level tag as the first content of a comment (<pre>, <ul>, <blockquote>,
<h1>, <table>, {@snippet}) requests a blank line before itself, and the writer
honoured it right after the opening `/**` line, producing two empty ` *` lines
at the top of the comment. Ignore any whitespace request while nothing
significant has been written yet; the footer-tag special case for the same
situation becomes redundant and goes.

Ported from the classic-Javadoc part of google/google-java-format commit
e4cef582 ("Improve interactions between wroteAnythingSignificant and
whitespace requests"). Tests first: preBlockAsFirstContentGetsNoBlankLines and
listAsFirstContentGetsNoBlankLines both failed with the two empty lines.
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.

3 participants