Skip to content

refactor(engine): extract the splittable-leaf placement into its own compiler#360

Merged
DemchaAV merged 1 commit into
2.0-devfrom
refactor/extract-splittable-leaf-compiler
Jul 11, 2026
Merged

refactor(engine): extract the splittable-leaf placement into its own compiler#360
DemchaAV merged 1 commit into
2.0-devfrom
refactor/extract-splittable-leaf-compiler

Conversation

@DemchaAV

Copy link
Copy Markdown
Owner

Why

LayoutCompiler.compileSplittableLeaf (~150 lines) carried the trickiest pagination
logic — the loop that splits a SPLITTABLE leaf across pages via NodeDefinition.split,
emits each piece on the page it lands on, advances the page cursor, and guards against a
non-advancing split. It's self-contained (no recursion into other compile*), so it belongs
in its own file where it can be read and tested apart from the rest of the compiler. This is
the substantive step of the ongoing LayoutCompiler breakdown (#356#359).

What

  • Added a package-private SplittableLeafCompiler with a static compile(...) holding the
    split loop verbatim; LayoutCompiler dispatches to it and drops the private method
    (−165 LOC, 1361 → 1196).
  • The one rewrite is addPlacedFragments(...)fragments.addAll(CompositeDecoration.toPlacedFragments(...)),
    which is that helper's exact body — so the collaborator needs nothing private from
    LayoutCompiler (it throws via the AtomicNodeTooLargeException.forNode factory from refactor(engine): give AtomicNodeTooLargeException its own message factory #359).
  • Added SplittableLeafCompilerTest: drives the whole-fit single-page placement, the
    no-progress split guard (IllegalStateException), and the un-splittable-on-empty-page
    too-large throw with a stub NodeDefinition — branches the qa corpus doesn't reliably reach.

Tests

  • ./mvnw -f aggregator/pom.xml verify -pl :graph-compose-qa -am — full compile + javadoc
    gate + the qa visual/parity byte-identity suite (643): green. Pagination of splittable
    leaves (long tables / paragraphs) renders identically.
  • SplittableLeafCompilerTest: 3 tests, 0 failures.

Byte-identical lift — the split loop is unchanged, now isolated and directly tested. The
14-parameter compile(...) signature is inherited from the private method as-is; bundling
its shared context is a possible follow-up, kept out of this byte-identical move.

…compiler

compileSplittableLeaf held the trickiest pagination code — the loop that
splits a leaf across pages through NodeDefinition.split, emitting each piece
and advancing the page cursor — inline in LayoutCompiler. Move it verbatim to a
package-private SplittableLeafCompiler.compile, trimming LayoutCompiler by ~165
lines and giving the split loop a home and a direct test surface.

Byte-identical: the body is unchanged except addPlacedFragments(...) is inlined
to fragments.addAll(CompositeDecoration.toPlacedFragments(...)) (its exact
definition) so the collaborator needs nothing private from LayoutCompiler. New
SplittableLeafCompilerTest drives the whole-fit, no-progress-guard, and
too-large branches in isolation with a stub NodeDefinition.
@DemchaAV DemchaAV force-pushed the refactor/extract-splittable-leaf-compiler branch from 7e70ac5 to 13386ef Compare July 11, 2026 01:37
@DemchaAV DemchaAV merged commit cdff5d6 into 2.0-dev Jul 11, 2026
12 checks passed
@DemchaAV DemchaAV deleted the refactor/extract-splittable-leaf-compiler branch July 11, 2026 07:45
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