Repository navigation
Add a layout solver to google-java-format based on Wadler's prettier printer. - #1482
Merged
Merged
Conversation
…printer. Replace the Oppen-style `Doc.Level` break computation with an immutable document model and a separate solver, based on Philip Wadler's "A prettier printer" (https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf). A `layout.Doc` is built from `text`, `line` and `group`, and `layout.LayoutSolver` lays it out greedily in a single pass: each group is printed flat if it fits (Wadler's `group x = flatten x <|> x`), and otherwise its breaks are taken. Fill breaks correspond to Wadler's `fill`. `layout.LayoutBuilder` bridges the existing visitor to the new model. It provides the same operations as `OpsBuilder`, so `JavaInputAstVisitor` is unchanged apart from the builder type. The builder applies the same rules as the existing engine, for example the group-local fit test and attaching trailing text to the group of the most recent break. All existing formatting is preserved, and every integration test golden is unchanged. PiperOrigin-RevId: 999176908
copybara-service
Bot
force-pushed
the
test_986705449
branch
from
October 14, 2026 07:40
36da4fc to
332bbc2
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.
Add a layout solver to google-java-format based on Wadler's prettier printer.
Replace the Oppen-style
Doc.Levelbreak computation with an immutabledocument model and a separate solver, based on Philip Wadler's "A prettier
printer" (https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf).
A
layout.Docis built fromtext,lineandgroup, andlayout.LayoutSolverlays it out greedily in a single pass: each group isprinted flat if it fits (Wadler's
group x = flatten x <|> x), and otherwiseits breaks are taken. Fill breaks correspond to Wadler's
fill.layout.LayoutBuilderbridges the existing visitor to the new model. Itprovides the same operations as
OpsBuilder, soJavaInputAstVisitorisunchanged apart from the builder type. The builder applies the same rules as
the existing engine, for example the group-local fit test and attaching
trailing text to the group of the most recent break. All existing formatting
is preserved, and every integration test golden is unchanged.