Skip to content

Reflow long strings in Eclipse's Format, as on the command line - #235

Merged
abashev merged 1 commit into
21.X.Xfrom
abashev/Eclipse-range-reflow
Nov 18, 2026
Merged

abashev merged 1 commit into
21.X.Xfrom
abashev/Eclipse-range-reflow

Conversation

@abashev

@abashev abashev commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Builds on #233; merge that first. Independent of #234.

Eclipse's Format of a Java editor now reflows the long strings in the selected code, as the command line, formatDiff and IntelliJ IDEA do (ADR-001). It formats the compilation unit with its comments over the selected ranges, and went through Formatter.getFormatReplacements, which never reflows (#219). It now calls getFormatAndReflowReplacements, the method --output-replacements and the in-process service share since #232, which after #233 reflows only the strings in the code that formatting the ranges rewrites.

What changes for users

  • Format in a Java editor: a long string in the selection is wrapped, as open-java-format --character-ranges wraps it. Strings outside the selection stay as they are. Imports are not touched, as before.
  • Snippets: nothing. The code Eclipse formats when it inserts something (statements, expressions, class bodies) is wrapped in a dummy class, and toReplacements accepts only changes to whitespace, which reflowing a string is not.

Tests

The plugin had no tests; it gets JUnit and AssertJ for SnippetFormatterTest:

JDK 21: ./gradlew check passes. JDK 25: :open-java-format-eclipse-plugin:test passes.

@abashev
abashev force-pushed the abashev/Range-reflow-inside branch from 2897566 to 2e3876f Compare November 16, 2026 20:03
@abashev
abashev force-pushed the abashev/Eclipse-range-reflow branch from aa291bb to c36e9b1 Compare November 16, 2026 20:04
@abashev
abashev force-pushed the abashev/Range-reflow-inside branch from 2e3876f to 6e28b71 Compare November 16, 2026 20:05
@abashev
abashev force-pushed the abashev/Eclipse-range-reflow branch from c36e9b1 to 5894a4f Compare November 16, 2026 20:05
@abashev
abashev force-pushed the abashev/Range-reflow-inside branch from 6e28b71 to 3c36af2 Compare November 16, 2026 20:22
@abashev
abashev force-pushed the abashev/Eclipse-range-reflow branch from 5894a4f to 86741cf Compare November 16, 2026 20:26
@abashev
abashev force-pushed the abashev/Range-reflow-inside branch from 3c36af2 to c799977 Compare November 17, 2026 18:45
… line

Eclipse's Format of a Java editor formats the whole compilation unit
with its comments over the selected ranges. It went through
Formatter.getFormatReplacements, which never reflows, so a long string
in the selection stayed on one line where the command line, formatDiff
and IntelliJ IDEA wrap it (#219). It now goes through
getFormatAndReflowReplacements, which reflows only the strings in the
code that formatting the ranges rewrites.

Snippets, which Eclipse formats when it inserts code, stay as they
are: they are wrapped in a dummy class, and toReplacements accepts
only changes to whitespace, which reflowing a string is not.

The plugin had no tests; it gets JUnit and AssertJ for SnippetFormatterTest.
@abashev
abashev force-pushed the abashev/Eclipse-range-reflow branch from 86741cf to 6dcf057 Compare November 17, 2026 18:45
Base automatically changed from abashev/Range-reflow-inside to 21.X.X November 18, 2026 07:09
@abashev
abashev merged commit 48ebc8a into 21.X.X Nov 18, 2026
21 of 23 checks passed
@abashev
abashev deleted the abashev/Eclipse-range-reflow branch November 18, 2026 07:11
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