Repository navigation
Only reflow long strings in the requested lines when partially formatting. - #1514
Merged
Merged
Conversation
…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
Bot
force-pushed
the
test_1009611289
branch
from
October 30, 2026 07:20
4ef0b42 to
e01cd02
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Only reflow long strings in the requested lines when partially formatting.
With
--lines,--offset/--length, or the equivalent library APIs,google-java-formatonly reformats the requested ranges, but it still reflowed every long string literal in the file.google-java-format-diff.pyusers 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 thatCleanupsalready used is extracted into a sharedEditclass for this.StringWrapper's preliminary pass over the strings it will reflow now uses whitespace-onlygetFormatReplacementsinstead offormatSource, so the ranges can be mapped through it too; the cleanup passes have already run by that point.Fixes #1114