Skip to content

Commit f01801a

Browse files
committed
refactor: keep the dialect keyword names in a nested class
Signed-off-by: minleejae <mmj9808@gmail.com>
1 parent 1038c30 commit f01801a

1 file changed

Lines changed: 31 additions & 7 deletions

File tree

‎src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt‎

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4674,13 +4674,37 @@ public class CCJSqlParser extends AbstractJSqlParser<CCJSqlParser> {
46744674

46754675
/**
46764676
* Whether the keyword belongs only to clauses of other dialects and the selected dialect does
4677-
* not know it as a keyword at all, so it is a plain identifier there. MySQL 8.4 and
4678-
* PostgreSQL 18 have no PIVOT, MINUS, OUTPUT or SEMI JOIN, MySQL no ILIKE, and PostgreSQL
4679-
* neither XOR, QUALIFY nor MySQL's select modifiers. Without a dialect they stay reserved.
4677+
* not know it as a keyword at all, so it is a plain identifier there. Without a dialect it
4678+
* stays reserved.
46804679
*/
46814680
private boolean isDialectIdentifierKeyword(int kind) {
4682-
String dialect = getAsString(Feature.dialect);
4683-
if (Dialect.MYSQL.name().equals(dialect)) {
4681+
return DialectKeywordNames.isIdentifier(getAsString(Feature.dialect), kind);
4682+
}
4683+
4684+
/**
4685+
* The reserved keywords of this parser that MySQL 8.4 or PostgreSQL 18 reads as names. A nested
4686+
* class keeps these lists out of CCJSqlParser.class, whose constant pool is close to what JaCoCo
4687+
* can still instrument.
4688+
*/
4689+
private static final class DialectKeywordNames {
4690+
private DialectKeywordNames() {}
4691+
4692+
/**
4693+
* Whether the keyword is a name wherever the dialect takes one. MySQL 8.4 and PostgreSQL 18
4694+
* have no PIVOT, MINUS, OUTPUT or SEMI JOIN, MySQL no ILIKE, and PostgreSQL neither XOR,
4695+
* QUALIFY nor MySQL's select modifiers.
4696+
*/
4697+
static boolean isIdentifier(String dialect, int kind) {
4698+
if (Dialect.MYSQL.name().equals(dialect)) {
4699+
return isMySqlIdentifier(kind);
4700+
}
4701+
if (Dialect.POSTGRESQL.name().equals(dialect)) {
4702+
return isPostgreSqlIdentifier(kind);
4703+
}
4704+
return false;
4705+
}
4706+
4707+
private static boolean isMySqlIdentifier(int kind) {
46844708
switch (kind) {
46854709
case K_CONNECT_BY_ROOT: case K_EXCLUDES: case K_FINAL: case K_ILIKE:
46864710
case K_INCLUDES: case K_MINUS: case K_NOCYCLE: case K_OUTPUT: case K_PIVOT:
@@ -4690,7 +4714,8 @@ public class CCJSqlParser extends AbstractJSqlParser<CCJSqlParser> {
46904714
return false;
46914715
}
46924716
}
4693-
if (Dialect.POSTGRESQL.name().equals(dialect)) {
4717+
4718+
private static boolean isPostgreSqlIdentifier(int kind) {
46944719
switch (kind) {
46954720
case K_CONNECT_BY_ROOT: case K_DISTINCTROW: case K_EXCLUDES: case K_FINAL:
46964721
case K_INCLUDES: case K_MINUS: case K_NOCYCLE: case K_OUTPUT: case K_PIVOT:
@@ -4702,7 +4727,6 @@ public class CCJSqlParser extends AbstractJSqlParser<CCJSqlParser> {
47024727
return false;
47034728
}
47044729
}
4705-
return false;
47064730
}
47074731

47084732
/** MySQL's EXPLAIN, PREPARE, EXECUTE, DROP PREPARE and DO: MySQL, MariaDB or no dialect. */

0 commit comments

Comments
 (0)