public final class TokenEquivalence extends Object
The contract — verified by 12 hand-built cases in
TokenEquivalenceTest — is that two SQL strings are equivalent
when:
caseInsensitive=true. Quoted identifiers, string
literals, and operator/punctuation tokens are always compared
byte-exact because case changes there alter semantics.This helper is the safety net for several downstream slices:
GuardedAstDelegate) — verifies that
FormatterFactory.pp()'s output preserves every solid
input token.The helper deliberately operates on raw SQL strings (not
Pp2TokenStream instances) because the comparison is between an
arbitrary input and an arbitrary output — there is no single pp2 stream
shared between the two. The internal tokenization uses the GSP lexer
directly with the same overlap-skip discipline as
Pp2TokenStreamBuilder.
Changes the user explicitly asked for (variable or delimited-name case,
compact mode's comment rewrite, comment removal) are accepted in their exact
expected form when a TransformPolicy allows them; see that class.
Pp2FormatOptions.transformPolicy carries it to pp2's guards.
Plan reference: §7.3/S10, §7.4/S10, Q8.
| Modifier and Type | Method and Description |
|---|---|
static boolean |
commentsPreserved(String left,
String right,
EDbVendor vendor)
The comment half of
equalsModuloFormatting(String, String,
Pp2FormatOptions, EDbVendor, boolean): the comments of left
appear in right in the same relative order with byte-exact
text; their position relative to the solid tokens may differ. |
static boolean |
commentsPreserved(String left,
String right,
EDbVendor vendor,
TransformPolicy policy)
commentsPreserved(String, String, EDbVendor) that also accepts
the comment transformations policy allows. |
static boolean |
equalsModuloFormatting(String left,
String right,
Pp2FormatOptions opts)
Case-insensitive comparison using the default Oracle dialect.
|
static boolean |
equalsModuloFormatting(String left,
String right,
Pp2FormatOptions opts,
EDbVendor vendor,
boolean caseInsensitive)
Full-control comparison.
|
static boolean |
equalsModuloFormatting(String left,
String right,
Pp2FormatOptions opts,
EDbVendor vendor,
boolean caseInsensitive,
boolean stringsAtStart)
equalsModuloFormatting(String, String, Pp2FormatOptions, EDbVendor, boolean) for two
texts that follow other statements: stringsAtStart is true when one of those turned
the quoted-identifier option off, so that every double-quoted text of both may be a string
(see DoubleQuotedStrings). |
static boolean |
solidTokensEquivalent(String left,
String right,
EDbVendor vendor,
boolean caseInsensitive)
The solid-token half of
equalsModuloFormatting(String, String,
Pp2FormatOptions, EDbVendor, boolean): every non-comment token of
left appears in right once, in order, with the same
type and (case-insensitively for keywords and unquoted identifiers
when caseInsensitive) the same text. |
static boolean |
solidTokensEquivalent(String left,
String right,
EDbVendor vendor,
boolean caseInsensitive,
TransformPolicy policy)
solidTokensEquivalent(String, String, EDbVendor, boolean) that
also accepts the solid-token transformations policy allows. |
public static boolean equalsModuloFormatting(String left, String right, Pp2FormatOptions opts)
public static boolean equalsModuloFormatting(String left, String right, Pp2FormatOptions opts, EDbVendor vendor, boolean caseInsensitive)
left - first SQL string; must not be nullright - second SQL string; must not be nullopts - pp2 options; its transformPolicy allows the
requested transformations; may be null (none allowed)vendor - dialect to tokenize with; must not be nullcaseInsensitive - when true, keyword and unquoted
identifier comparisons are case-insensitive;
when false, all comparisons are
byte-exact on texttrue iff the two strings have the same token
sequence under the rules described in the class JavadocNullPointerException - if left, right, or
vendor is nullpublic static boolean equalsModuloFormatting(String left, String right, Pp2FormatOptions opts, EDbVendor vendor, boolean caseInsensitive, boolean stringsAtStart)
equalsModuloFormatting(String, String, Pp2FormatOptions, EDbVendor, boolean) for two
texts that follow other statements: stringsAtStart is true when one of those turned
the quoted-identifier option off, so that every double-quoted text of both may be a string
(see DoubleQuotedStrings).public static boolean solidTokensEquivalent(String left, String right, EDbVendor vendor, boolean caseInsensitive)
equalsModuloFormatting(String, String,
Pp2FormatOptions, EDbVendor, boolean): every non-comment token of
left appears in right once, in order, with the same
type and (case-insensitively for keywords and unquoted identifiers
when caseInsensitive) the same text. Exposed so that callers
reporting the two invariants separately (the format worker) apply the
same policy as the combined check.public static boolean solidTokensEquivalent(String left, String right, EDbVendor vendor, boolean caseInsensitive, TransformPolicy policy)
solidTokensEquivalent(String, String, EDbVendor, boolean) that
also accepts the solid-token transformations policy allows.public static boolean commentsPreserved(String left, String right, EDbVendor vendor)
equalsModuloFormatting(String, String,
Pp2FormatOptions, EDbVendor, boolean): the comments of left
appear in right in the same relative order with byte-exact
text; their position relative to the solid tokens may differ.public static boolean commentsPreserved(String left, String right, EDbVendor vendor, TransformPolicy policy)
commentsPreserved(String, String, EDbVendor) that also accepts
the comment transformations policy allows.