public final class ClauseScopeAnnotator extends Object
ClausePart) and
marks master/clause keyword roles, by walking the token stream left-to-right
and tracking the current clause per SQL scope level.
The annotator consumes SqlScopeDetector.SqlScopeResult (S20) so a subquery's
clauses do not leak into the enclosing query: the "current clause" is tracked
independently per scope level. When the walk descends into a deeper scope,
that level's clause state starts fresh; when it returns, the enclosing level's
clause (e.g. FROM around a derived-table subquery) is intact.
A clause keyword only changes the current clause when it appears at the
query block's own paren depth — not inside a nested expression. This stops
window specs (OVER (ORDER BY a)), aggregate filters
(FILTER (WHERE ...)), and parenthesised predicates from corrupting
the clause state. The function-form keywords LEFT( / RIGHT(
are also recognised as function calls (not JOIN keywords) when immediately
followed by an open paren.
S21 is one of the designated role-annotator stages (plan forbidden #6), so
it sets TokenRole.KEYWORD_MASTER on master keywords
(SELECT/INSERT/UPDATE/DELETE/MERGE) and TokenRole.KEYWORD_CLAUSE on
recognised clause keywords. It never mutates the wrapped TSourceToken.
The per-token clause membership is returned as a ClauseScopeAnnotator.ClauseScopeResult
side structure (a token belongs to exactly one clause, so a small enum is
clearer than seven boolean roles).
Iterative single pass; no recursion. Plan reference: §7.3/S21, §7.4/S21.
| Modifier and Type | Class and Description |
|---|---|
static class |
ClauseScopeAnnotator.ClauseScopeResult
Per-token clause membership plus the master-keyword token indices.
|
| Constructor and Description |
|---|
ClauseScopeAnnotator() |
| Modifier and Type | Method and Description |
|---|---|
ClauseScopeAnnotator.ClauseScopeResult |
annotate(Pp2TokenStream stream,
SqlScopeDetector.SqlScopeResult sqlScope)
Annotate
stream clause membership using the SQL scope levels. |
public ClauseScopeAnnotator()
public ClauseScopeAnnotator.ClauseScopeResult annotate(Pp2TokenStream stream, SqlScopeDetector.SqlScopeResult sqlScope)
stream clause membership using the SQL scope levels.stream - the token stream; must not be nullsqlScope - the S20 scope result for the same stream; must not be null
and must cover the same token countClauseScopeAnnotator.ClauseScopeResult; never nullNullPointerException - if any argument is nullIllegalArgumentException - if sqlScope.size() != stream size