From ab962b381a65d6e0fb183eafb95a6d50dfe96aa5 Mon Sep 17 00:00:00 2001 From: DemchaAV Date: Sat, 11 Jul 2026 01:40:43 +0100 Subject: [PATCH] refactor(engine): give AtomicNodeTooLargeException its own message factory The too-large diagnostic was built by a private LayoutCompiler.atomicTooLarge helper. Move the message construction onto a static AtomicNodeTooLargeException.forNode(path, outerHeight, pageHeight) factory so the exception owns its own message, and have the three throw sites call it directly. Byte-identical message; this also lets a future extracted collaborator throw the same exception without reaching into LayoutCompiler. --- .../AtomicNodeTooLargeException.java | 20 +++++++++++++++++++ .../document/layout/LayoutCompiler.java | 15 +++----------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/demcha/compose/document/exceptions/AtomicNodeTooLargeException.java b/src/main/java/com/demcha/compose/document/exceptions/AtomicNodeTooLargeException.java index 2fdc73fd5..d32fe8741 100644 --- a/src/main/java/com/demcha/compose/document/exceptions/AtomicNodeTooLargeException.java +++ b/src/main/java/com/demcha/compose/document/exceptions/AtomicNodeTooLargeException.java @@ -12,5 +12,25 @@ public final class AtomicNodeTooLargeException extends RuntimeException { public AtomicNodeTooLargeException(String message) { super(message); } + + /** + * Creates an exception for a node whose required outer height exceeds a full + * page's capacity, with a diagnostic message that names the offending + * measurements but no user document content. + * + * @param path the node's layout path + * @param outerHeight the node's required outer (margin-box) height + * @param pageHeight the available full-page capacity + * @return the exception, ready to throw + * @since 2.0.0 + */ + public static AtomicNodeTooLargeException forNode(String path, double outerHeight, double pageHeight) { + return new AtomicNodeTooLargeException( + "Node '" + path + "' requires outer height " + outerHeight + + " but page capacity is " + pageHeight + ". " + + "Reduce the node height, split content into multiple atomic blocks, " + + "or increase the page size. Differences under 0.5 pt are tolerated as " + + "rounding noise (v1.6.2+)."); + } } diff --git a/src/main/java/com/demcha/compose/document/layout/LayoutCompiler.java b/src/main/java/com/demcha/compose/document/layout/LayoutCompiler.java index b8e3e8645..2d299ec65 100644 --- a/src/main/java/com/demcha/compose/document/layout/LayoutCompiler.java +++ b/src/main/java/com/demcha/compose/document/layout/LayoutCompiler.java @@ -943,7 +943,7 @@ private void compileSplittableLeaf(PreparedNode prepared, state.newPage(); continue; } - throw atomicTooLarge(path, pieceOuterHeight, fullPageOuterHeight); + throw AtomicNodeTooLargeException.forNode(path, pieceOuterHeight, fullPageOuterHeight); } if (tail != null && tail.equals(current)) { throw new IllegalStateException("Split did not make progress for node '" + path @@ -962,7 +962,7 @@ private void compileSplittableLeaf(PreparedNode prepared, state.newPage(); continue; } - throw atomicTooLarge(path, headOuterHeight, fullPageOuterHeight); + throw AtomicNodeTooLargeException.forNode(path, headOuterHeight, fullPageOuterHeight); } state.touchPage(); @@ -1326,7 +1326,7 @@ private String semanticName(DocumentNode node) { private void admitAtomicBlock(double outerHeight, String path, CompilerState state) { double fullPageHeight = state.activeInnerHeight(); if (outerHeight > fullPageHeight + CAPACITY_TOLERANCE) { - throw atomicTooLarge(path, outerHeight, fullPageHeight); + throw AtomicNodeTooLargeException.forNode(path, outerHeight, fullPageHeight); } if (outerHeight > state.remainingHeight() + EPS && state.usedHeight > EPS) { state.newPage(); @@ -1334,15 +1334,6 @@ private void admitAtomicBlock(double outerHeight, String path, CompilerState sta state.touchPage(); } - private AtomicNodeTooLargeException atomicTooLarge(String path, double outerHeight, double pageHeight) { - return new AtomicNodeTooLargeException( - "Node '" + path + "' requires outer height " + outerHeight - + " but page capacity is " + pageHeight + ". " - + "Reduce the node height, split content into multiple atomic blocks, " - + "or increase the page size. Differences under 0.5 pt are tolerated as " - + "rounding noise (v1.6.2+)."); - } - /** * Identifies the kind of fixed slot a child is being compiled into, * so the validator can distinguish "child of a horizontal row band"