public final class RegionAssembler extends Object
SourceSpanLedger.
Every RegionRenderer intentionally omits the leading whitespace
for the first token of its range (see RenderedRegion).
The bytes between adjacent regions — whitespace, comments, blank lines,
--BEGIN_NO_FORMAT/--END_NO_FORMAT blocks — live in the
original source at positions [r_i.endOffset, r_{i+1}.startOffset).
The assembler is the counterparty that places those bytes into the output,
so they reach the caller byte-for-byte regardless of which renderer handled
the surrounding statements.
Given an ordered, non-overlapping list of RenderedRegions:
source[0, first.startOffset)r_i:
r_i.getText() (the renderer's output)source[r_i.endOffset, r_{i+1}.startOffset)
(inter-region gap; the final region skips this step)source[last.endOffset, source.length())An empty regions list returns the entire source string unchanged — all bytes come from the preamble/trailer path.
Phase-2 MVP implements only CommentPolicy.PRESERVE: inter-region
bytes are always emitted verbatim. CommentPolicy.REANCHOR and
CommentPolicy.REFLOW log a notice and fall back to PRESERVE; the
Phase-3 island pipeline will provide real semantics.
Overlapping or out-of-order region offsets (which should never occur when
StatementBoundaryDetector S11 produces the list) are detected and
logged; overlap bytes are skipped rather than emitted twice. Out-of-bounds
source-slice requests are also guarded — no byte is lost due to an offset
arithmetic bug in the caller.
Plan reference: §7.3/S15, §7.4/S15, §10.4.
| Constructor and Description |
|---|
RegionAssembler() |
| Modifier and Type | Method and Description |
|---|---|
String |
assemble(List<RenderedRegion> regions,
SourceSpanLedger ledger,
Pp2FormatOptions opts)
Assemble rendered regions into a final output string.
|
public RegionAssembler()
public String assemble(List<RenderedRegion> regions, SourceSpanLedger ledger, Pp2FormatOptions opts)
regions - ordered (source position), non-overlapping list of
rendered regions; empty list is allowedledger - the source-span ledger for the original SQL;
SourceSpanLedger.getSource() is the byte authorityopts - pp2 format options;
Pp2FormatOptions.commentPolicy governs how
inter-region trivia is emittedNullPointerException - if any argument is null