public final class LayoutContext extends Object
LayoutRulePipeline. Bundles
the token stream and the upstream analyses (S18 multi-word matches, S19 block
scopes, S20 SQL scopes, S21 clause membership, S22 islands), and holds the
evolving per-token LayoutDecisions.
Rules never mutate Pp2Token (its
precedingBlanks/precedingLinebreaks are final). Instead they
call requestLinebreaksBefore(int, int), requestBlanksBefore(int, int), and
requestIndent(int, int) with the value they want for a token's leading
whitespace. Each write is mediated by the LayoutConflictResolver using
the active rule's priority, which LayoutRulePipeline sets before
invoking each rule. Undecided properties stay LayoutDecision.UNSET so
the output writer (S31) falls back to the original whitespace — making the
zero-rule pipeline an identity pass.
Not thread-safe; one context per format call.
Plan reference: §7.3/S23, §7.4/S23.
| Constructor and Description |
|---|
LayoutContext(Pp2TokenStream stream,
Pp2FormatOptions options) |
LayoutContext(Pp2TokenStream stream,
Pp2FormatOptions options,
LayoutConflictResolver resolver) |
public LayoutContext(Pp2TokenStream stream, Pp2FormatOptions options)
public LayoutContext(Pp2TokenStream stream, Pp2FormatOptions options, LayoutConflictResolver resolver)
public Pp2TokenStream getStream()
public Pp2FormatOptions getOptions()
public int size()
public LayoutDecisionView decisionAt(int index)
index. Writes must go through the request*
methods so the LayoutConflictResolver precedence is honoured.public LayoutContext withMultiWordMatches(List<MultiWordKeywordMerger.Match> m)
public LayoutContext withBlockScope(BlockScopeDetector.BlockScopeResult b)
public LayoutContext withSqlScope(SqlScopeDetector.SqlScopeResult s)
public LayoutContext withClauseScope(ClauseScopeAnnotator.ClauseScopeResult c)
public LayoutContext withIslands(List<IslandScope> i)
public LayoutContext withDialect(DialectStrategy d)
public List<MultiWordKeywordMerger.Match> getMultiWordMatches()
public BlockScopeDetector.BlockScopeResult getBlockScope()
public SqlScopeDetector.SqlScopeResult getSqlScope()
public ClauseScopeAnnotator.ClauseScopeResult getClauseScope()
public List<IslandScope> getIslands()
public DialectStrategy getDialect()
public void requestLinebreaksBefore(int index, int count)
count linebreaks before the token at index.public void requestBlanksBefore(int index, int count)
count blank columns before the token at index.public void requestIndent(int index, int level)
level for the token at index.public void requestText(int index, String text)
index be emitted as text instead
of its source text (e.g. keyword case modification). The wrapped
TSourceToken is never changed; this is a render-time override.