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()
Vendor-agnostic assembler (
-- and /* comments only). |
RegionAssembler(EDbVendor vendor)
Assembler that recognises
vendor's line-comment syntax when
deciding whether a region begins with a (trailing) comment. |
| Modifier and Type | Method and Description |
|---|---|
String |
assemble(List<RenderedRegion> regions,
SourceSpanLedger ledger,
Pp2FormatOptions opts)
Assemble rendered regions into a final output string.
|
String |
assemble(List<RenderedRegion> regions,
SourceSpanLedger ledger,
Pp2FormatOptions opts,
boolean breakStatements)
Assemble rendered regions, with explicit control over statement-break
normalization.
|
public RegionAssembler()
-- and /* comments only).public RegionAssembler(EDbVendor vendor)
vendor's line-comment syntax when
deciding whether a region begins with a (trailing) comment. In
particular # is treated as a line comment for every dialect
except the SQL Server family, where #name is a temp-table
identifier rather than a comment.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 nullpublic String assemble(List<RenderedRegion> regions, SourceSpanLedger ledger, Pp2FormatOptions opts, boolean breakStatements)
assemble(List, SourceSpanLedger,
Pp2FormatOptions) except breakStatements overrides
Pp2FormatOptions.breakStatementsOnNewLine. The engine uses this
overload to re-assemble verbatim (breakStatements=false) as a
content-preservation fallback when a break would alter the token stream.breakStatements - when true, whitespace-only line-break-free
gaps between statements become a single newline;
when false, all inter-region trivia is
emitted verbatim