Skip to content

Reflow long strings in formatDiff on the JVM, as with the native binary - #232

Merged
abashev merged 2 commits into
21.X.Xfrom
abashev/Range-reflow-in-process
Nov 17, 2026
Merged

abashev merged 2 commits into
21.X.Xfrom
abashev/Range-reflow-in-process

Conversation

@abashev

@abashev abashev commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Builds on #231; merge that first. Part of #219.

formatDiff on the JVM now reflows long strings as it does with the native binary, and as IntelliJ IDEA does: the in-process FormatterServiceImpl.getFormatReplacements returns what Main --output-replacements prints.

  • One method. What FormatFileCallable did for --output-replacements moves, unchanged, to the package-private Formatter.getFormatAndReflowReplacements; FormatFileCallable and FormatterServiceImpl call it. The command line's output does not change.
  • The check. Each case of FormatterCasesTest, which Run tests that need a newer JDK in classes and folders of their own #231's FormatterCasesJava21Test, Java25Test and Java28Test run, also gives the lines that formatting changes, taken as a range, to the service and to Main, and expects the same replacements. On the code of Run tests that need a newer JDK in classes and folders of their own #231, 78 of the 915 cases fail on it, the stringwrapper ones among them.
  • The services. FormatDiffTest runs the in-process formatter next to the bootstrapping and native ones, and FormatterServicesTest and FormatDiffTest reflow a long string on a changed line with each of the three.

Not here: a long string outside the ranges is still reflowed once one in them needs it, on every surface alike now; that is the next pull request.

Tests

  • JDK 21: ./gradlew check passes; 1,419 tests in :open-java-format. JDK 25 and JDK 28 (28+23-ea): :open-java-format:test passes.
  • JDK 25: :open-java-format:test passes, with the JDK 25 cases; JDK 28 (28+23-ea) too, with the JDK 28 ones.
  • -PnativeImage=true (macOS aarch64, GraalVM 25): FormatterServicesTest 11 of 11, FormatDiffTest 7 of 7.

Base automatically changed from abashev/JDK-split-tests to 21.X.X November 15, 2026 20:57
@abashev
abashev force-pushed the abashev/Range-reflow-in-process branch 2 times, most recently from ed3bcf8 to 33fe8c1 Compare November 16, 2026 20:05
formatDiff on the JVM loads FormatterServiceImpl into the build's JVM,
and its getFormatReplacements called Formatter.getFormatReplacements,
which never reflows strings. With the native binary, and in IntelliJ
IDEA, the bootstrapping and native services run Main
--output-replacements, which does. A long string on a changed line
stayed on one line on the JVM only, and the GitHub Action failed on
the result (#219).

What FormatFileCallable did for --output-replacements moves, as it
is, to Formatter.getFormatAndReflowReplacements, and
FormatterServiceImpl.getFormatReplacements returns what it gives.

Each case of FormatterCasesTest now also holds the two to each other:
the lines formatting changes, taken as a range, get the same
replacements from the service and from Main. On the code before, 78
of the 915 cases fail.
Both tested the bootstrapping and native services only, never the one
formatDiff loads on the JVM. FormatDiffTest runs it next to them, and
both reflow a long string on a changed line with each of the three.
@abashev
abashev force-pushed the abashev/Range-reflow-in-process branch from 33fe8c1 to 94e5117 Compare November 16, 2026 20:18
@abashev
abashev merged commit c5d22d7 into 21.X.X Nov 17, 2026
61 of 67 checks passed
@abashev
abashev deleted the abashev/Range-reflow-in-process branch November 17, 2026 18:01
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.

1 participant