Skip to content

Only reflow long strings in the requested lines when partially formatting. - #1514

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1009611289
Oct 30, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1009611289

Conversation

@copybara-service

Copy link
Copy Markdown

Only reflow long strings in the requested lines when partially formatting.

With --lines, --offset/--length, or the equivalent library APIs, google-java-format only reformats the requested ranges, but it still reflowed every long string literal in the file. google-java-format-diff.py users and editor integrations that format only changed lines got unrelated edits elsewhere in the file.

The requested ranges are now mapped onto the formatted output and passed to StringWrapper, which only reflows string literals that intersect them. The offset mapping that Cleanups already used is extracted into a shared Edit class for this. StringWrapper's preliminary pass over the strings it will reflow now uses whitespace-only getFormatReplacements instead of formatSource, so the ranges can be mapped through it too; the cleanup passes have already run by that point.

Fixes #1114

…ting.

With `--lines`, `--offset`/`--length`, or the equivalent library APIs, `google-java-format` only reformats the requested ranges, but it still reflowed every long string literal in the file. `google-java-format-diff.py` users and editor integrations that format only changed lines got unrelated edits elsewhere in the file.

The requested ranges are now mapped onto the formatted output and passed to `StringWrapper`, which only reflows string literals that intersect them. The offset mapping that `Cleanups` already used is extracted into a shared `Edit` class for this. `StringWrapper`'s preliminary pass over the strings it will reflow now uses whitespace-only `getFormatReplacements` instead of `formatSource`, so the ranges can be mapped through it too; the cleanup passes have already run by that point.

Fixes #1114

PiperOrigin-RevId: 1010285643
@copybara-service
copybara-service Bot merged commit e01cd02 into master Oct 30, 2026
12 checks passed
@copybara-service
copybara-service Bot deleted the test_1009611289 branch October 30, 2026 07:20
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.

Formatting overly long lines does not respect --lines range restriction

1 participant