public final class ProtectedZoneDetector extends Object
Pp2TokenStream and annotates the
affected tokens with the relevant TokenRole flags.
"Protected" here means: pp2 must emit the token's text verbatim. The layout rules in S24–S29 may re-space around a protected token but never alter its contents.
ttsimplecomment, ttCPPComment)
→ TokenRole.COMMENT_LINE.ttbracketedcomment)
→ TokenRole.COMMENT_BLOCK."/*+") → TokenRole.HINT in addition to
COMMENT_BLOCK.ttsqstring)
→ TokenRole.LITERAL.ttdqstring,
ttdbstring, ttbrstring)
→ TokenRole.QUOTED_IDENTIFIER.--BEGIN_NO_FORMAT line comment and a matching
--END_NO_FORMAT line comment is flagged with
TokenRole.NO_FORMAT_ZONE. The markers themselves carry
the flag too.${name}, {{name}}, or #{name}
are flagged TokenRole.TEMPLATE_PLACEHOLDER and
TokenRole.NO_FORMAT_ZONE so layout never reflows
inside them. ${name} arrives from the lexer as a
single identifier-style token and is matched in the per-token
pass; {{name}} and #{name} are tokenized as
multiple tokens (e.g., "{" "{" name "}" "}") and a
second pass walks the stream looking for those sequences. The
second-pass body check rejects shapes whose interior does not
look like a placeholder body, so SQL fragments that happen to
contain isolated braces (e.g., JSON path literals) are not
misflagged.The detector does not consume or produce tokens; it only adds roles
to existing Pp2Tokens. Repeated invocations are idempotent (the
underlying EnumSet is set-typed).
Plan reference: §7.3/S9, §7.4/S9.
| Modifier and Type | Field and Description |
|---|---|
static String |
NO_FORMAT_BEGIN
Marker comment text that opens a no-format block.
|
static String |
NO_FORMAT_END
Marker comment text that closes a no-format block.
|
| Constructor and Description |
|---|
ProtectedZoneDetector() |
| Modifier and Type | Method and Description |
|---|---|
void |
annotate(Pp2TokenStream stream)
Annotate the supplied stream in place.
|
static boolean |
isHintText(String text)
True if the given text is a hint-style block comment, i.e., starts
with
"/*+". |
static boolean |
isNoFormatBeginMarker(ETokenType type,
String text)
True if the given line-comment text opens a no-format block.
|
static boolean |
isNoFormatEndMarker(ETokenType type,
String text)
True if the given line-comment text closes a no-format block.
|
static boolean |
isTemplatePlaceholder(String text)
True if the given text matches a single-token template-placeholder
shape:
${name}, {{name}}, or #{name}. |
public static final String NO_FORMAT_BEGIN
public static final String NO_FORMAT_END
public ProtectedZoneDetector()
public void annotate(Pp2TokenStream stream)
Performed in two passes:
{{name}} and
#{name}, detected by scanning consecutive token text.Idempotent: repeated invocations don't double-flag because the underlying role set is set-typed.
NullPointerException - if stream is nullpublic static boolean isHintText(String text)
"/*+".public static boolean isTemplatePlaceholder(String text)
${name}, {{name}}, or #{name}.public static boolean isNoFormatBeginMarker(ETokenType type, String text)
public static boolean isNoFormatEndMarker(ETokenType type, String text)