From 99d42017301595f192c72bd4ccf3af7f17865b5c Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Mon, 16 Dec 2019 15:17:30 -0600 Subject: [PATCH] Consolidated Antlr grammars into dedicated package --- hibernate-core/hibernate-core.gradle | 8 ++++---- .../parse => grammars/graph}/GraphLanguageLexer.g4 | 2 +- .../parse => grammars/graph}/GraphLanguageParser.g4 | 2 +- .../{query/hql/internal => grammars/hql}/HqlLexer.g4 | 2 +- .../{query/hql/internal => grammars/hql}/HqlParser.g4 | 2 +- .../grammar => grammars/importsql}/SqlStatementLexer.g4 | 3 +-- .../grammar => grammars/importsql}/SqlStatementParser.g4 | 2 +- .../tool/hbm2ddl/grammar/SqlStatementLexer.tokens | 6 ------ .../org/hibernate/graph/internal/parse/GraphParser.java | 3 +++ .../hibernate/query/hql/internal/HqlParseTreeBuilder.java | 2 ++ .../query/hql/internal/SemanticQueryBuilder.java | 4 +++- .../query/hql/internal/StandardHqlTranslator.java | 2 ++ .../tool/hbm2ddl/MultipleLinesSqlCommandExtractor.java | 4 ++-- .../tool/hbm2ddl/SqlStatementParserListenerImpl.java | 4 ++-- .../StatementsWithoutTerminalCharsImportFileTest.java | 1 - 15 files changed, 24 insertions(+), 23 deletions(-) rename hibernate-core/src/main/antlr/org/hibernate/{graph/internal/parse => grammars/graph}/GraphLanguageLexer.g4 (95%) rename hibernate-core/src/main/antlr/org/hibernate/{graph/internal/parse => grammars/graph}/GraphLanguageParser.g4 (94%) rename hibernate-core/src/main/antlr/org/hibernate/{query/hql/internal => grammars/hql}/HqlLexer.g4 (99%) rename hibernate-core/src/main/antlr/org/hibernate/{query/hql/internal => grammars/hql}/HqlParser.g4 (99%) rename hibernate-core/src/main/antlr/org/hibernate/{tool/hbm2ddl/grammar => grammars/importsql}/SqlStatementLexer.g4 (95%) rename hibernate-core/src/main/antlr/org/hibernate/{tool/hbm2ddl/grammar => grammars/importsql}/SqlStatementParser.g4 (90%) delete mode 100644 hibernate-core/src/main/antlr/org/hibernate/tool/hbm2ddl/grammar/SqlStatementLexer.tokens diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index 48f95889fb..003521caf2 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -385,10 +385,10 @@ class Antlr4Plugin implements Plugin { } class Antlr4GenerationTask extends DefaultTask { - static final String HQL_PCKG = 'org.hibernate.query.hql.internal' - static final String IMPORT_SQL_PCKG = 'org.hibernate.tool.hbm2ddl.grammar' - static final String GRAPH_PCKG = 'org.hibernate.graph.internal.parse' - static final String ORDER_PCKG = 'org.hibernate.grammars.ordering' + static final String HQL_PCKG = 'org.hibernate.grammars.hql' + static final String IMPORT_SQL_PCKG = 'org.hibernate.grammars.importsql' + static final String GRAPH_PCKG = 'org.hibernate.grammars.graph' + static final String ORDER_PCKG = 'org.hibernate.grammars.ordering' List grammarDescriptors = [ new GrammarDescriptor( HQL_PCKG, 'HqlLexer' ), diff --git a/hibernate-core/src/main/antlr/org/hibernate/graph/internal/parse/GraphLanguageLexer.g4 b/hibernate-core/src/main/antlr/org/hibernate/grammars/graph/GraphLanguageLexer.g4 similarity index 95% rename from hibernate-core/src/main/antlr/org/hibernate/graph/internal/parse/GraphLanguageLexer.g4 rename to hibernate-core/src/main/antlr/org/hibernate/grammars/graph/GraphLanguageLexer.g4 index 1e7c543f77..2471bdbbad 100644 --- a/hibernate-core/src/main/antlr/org/hibernate/graph/internal/parse/GraphLanguageLexer.g4 +++ b/hibernate-core/src/main/antlr/org/hibernate/grammars/graph/GraphLanguageLexer.g4 @@ -7,7 +7,7 @@ lexer grammar GraphLanguageLexer; * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.graph.internal.parse; +package org.hibernate.grammars.graph; } @members { diff --git a/hibernate-core/src/main/antlr/org/hibernate/graph/internal/parse/GraphLanguageParser.g4 b/hibernate-core/src/main/antlr/org/hibernate/grammars/graph/GraphLanguageParser.g4 similarity index 94% rename from hibernate-core/src/main/antlr/org/hibernate/graph/internal/parse/GraphLanguageParser.g4 rename to hibernate-core/src/main/antlr/org/hibernate/grammars/graph/GraphLanguageParser.g4 index 830e6bdf21..63455deca8 100644 --- a/hibernate-core/src/main/antlr/org/hibernate/graph/internal/parse/GraphLanguageParser.g4 +++ b/hibernate-core/src/main/antlr/org/hibernate/grammars/graph/GraphLanguageParser.g4 @@ -11,7 +11,7 @@ options { * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.graph.internal.parse; +package org.hibernate.grammars.graph; } @members { diff --git a/hibernate-core/src/main/antlr/org/hibernate/query/hql/internal/HqlLexer.g4 b/hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlLexer.g4 similarity index 99% rename from hibernate-core/src/main/antlr/org/hibernate/query/hql/internal/HqlLexer.g4 rename to hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlLexer.g4 index 1f6871541f..9fd4da7c3f 100644 --- a/hibernate-core/src/main/antlr/org/hibernate/query/hql/internal/HqlLexer.g4 +++ b/hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlLexer.g4 @@ -8,7 +8,7 @@ lexer grammar HqlLexer; * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.query.hql.internal; +package org.hibernate.grammars.hql; } WS : ( ' ' | '\t' | '\f' | EOL ) -> skip; diff --git a/hibernate-core/src/main/antlr/org/hibernate/query/hql/internal/HqlParser.g4 b/hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlParser.g4 similarity index 99% rename from hibernate-core/src/main/antlr/org/hibernate/query/hql/internal/HqlParser.g4 rename to hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlParser.g4 index 7b1744064c..0592a731fc 100644 --- a/hibernate-core/src/main/antlr/org/hibernate/query/hql/internal/HqlParser.g4 +++ b/hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlParser.g4 @@ -11,7 +11,7 @@ options { * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.query.hql.internal; +package org.hibernate.grammars.hql; } @members { diff --git a/hibernate-core/src/main/antlr/org/hibernate/tool/hbm2ddl/grammar/SqlStatementLexer.g4 b/hibernate-core/src/main/antlr/org/hibernate/grammars/importsql/SqlStatementLexer.g4 similarity index 95% rename from hibernate-core/src/main/antlr/org/hibernate/tool/hbm2ddl/grammar/SqlStatementLexer.g4 rename to hibernate-core/src/main/antlr/org/hibernate/grammars/importsql/SqlStatementLexer.g4 index 74f7c39d32..7807f4ae3e 100644 --- a/hibernate-core/src/main/antlr/org/hibernate/tool/hbm2ddl/grammar/SqlStatementLexer.g4 +++ b/hibernate-core/src/main/antlr/org/hibernate/grammars/importsql/SqlStatementLexer.g4 @@ -7,8 +7,7 @@ lexer grammar SqlStatementLexer; * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.tool.hbm2ddl.grammar; - +package org.hibernate.grammars.importsql; } STMT_END diff --git a/hibernate-core/src/main/antlr/org/hibernate/tool/hbm2ddl/grammar/SqlStatementParser.g4 b/hibernate-core/src/main/antlr/org/hibernate/grammars/importsql/SqlStatementParser.g4 similarity index 90% rename from hibernate-core/src/main/antlr/org/hibernate/tool/hbm2ddl/grammar/SqlStatementParser.g4 rename to hibernate-core/src/main/antlr/org/hibernate/grammars/importsql/SqlStatementParser.g4 index 4e3b51ffc8..7511c42759 100644 --- a/hibernate-core/src/main/antlr/org/hibernate/tool/hbm2ddl/grammar/SqlStatementParser.g4 +++ b/hibernate-core/src/main/antlr/org/hibernate/grammars/importsql/SqlStatementParser.g4 @@ -11,7 +11,7 @@ options { * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.tool.hbm2ddl.grammar; +package org.hibernate.grammars.importsql; } diff --git a/hibernate-core/src/main/antlr/org/hibernate/tool/hbm2ddl/grammar/SqlStatementLexer.tokens b/hibernate-core/src/main/antlr/org/hibernate/tool/hbm2ddl/grammar/SqlStatementLexer.tokens deleted file mode 100644 index 16afb731b9..0000000000 --- a/hibernate-core/src/main/antlr/org/hibernate/tool/hbm2ddl/grammar/SqlStatementLexer.tokens +++ /dev/null @@ -1,6 +0,0 @@ -STMT_END=1 -MULTILINE_COMMENT=2 -LINE_COMMENT=3 -NEWLINE=4 -WORD=5 -QUOTED_TEXT=6 diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java index 78c8e1a203..f48590f7b0 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java @@ -7,6 +7,9 @@ package org.hibernate.graph.internal.parse; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.grammars.graph.GraphLanguageLexer; +import org.hibernate.grammars.graph.GraphLanguageParser; +import org.hibernate.grammars.graph.GraphLanguageParserBaseVisitor; import org.hibernate.graph.InvalidGraphException; import org.hibernate.graph.spi.AttributeNodeImplementor; import org.hibernate.graph.spi.GraphImplementor; diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/HqlParseTreeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/HqlParseTreeBuilder.java index b11b3ef515..a5fd04484e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/HqlParseTreeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/HqlParseTreeBuilder.java @@ -6,6 +6,8 @@ */ package org.hibernate.query.hql.internal; +import org.hibernate.grammars.hql.HqlLexer; +import org.hibernate.grammars.hql.HqlParser; import org.hibernate.query.hql.HqlLogger; import org.jboss.logging.Logger; diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index 3ebf0c6880..65c43a34b2 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -22,6 +22,8 @@ import org.hibernate.NullPrecedence; import org.hibernate.SortOrder; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; +import org.hibernate.grammars.hql.HqlParser; +import org.hibernate.grammars.hql.HqlParserBaseVisitor; import org.hibernate.internal.util.collections.Stack; import org.hibernate.internal.util.collections.StandardStack; import org.hibernate.metamodel.CollectionClassification; @@ -136,7 +138,7 @@ import org.jboss.logging.Logger; import org.antlr.v4.runtime.Token; import static java.util.Arrays.asList; -import static org.hibernate.query.hql.internal.HqlParser.IDENTIFIER; +import static org.hibernate.grammars.hql.HqlParser.IDENTIFIER; /** * Responsible for producing an SQM using visitation over an HQL parse tree generated by diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/StandardHqlTranslator.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/StandardHqlTranslator.java index ac5a712be9..9a111928d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/StandardHqlTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/StandardHqlTranslator.java @@ -7,6 +7,8 @@ package org.hibernate.query.hql.internal; import org.hibernate.QueryException; +import org.hibernate.grammars.hql.HqlLexer; +import org.hibernate.grammars.hql.HqlParser; import org.hibernate.query.sqm.InterpretationException; import org.hibernate.query.hql.HqlTranslator; import org.hibernate.query.sqm.internal.SqmTreePrinter; diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/MultipleLinesSqlCommandExtractor.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/MultipleLinesSqlCommandExtractor.java index 92451a74b5..a3530a43e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/MultipleLinesSqlCommandExtractor.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/MultipleLinesSqlCommandExtractor.java @@ -9,8 +9,8 @@ package org.hibernate.tool.hbm2ddl; import java.io.Reader; import java.util.List; -import org.hibernate.tool.hbm2ddl.grammar.SqlStatementLexer; -import org.hibernate.tool.hbm2ddl.grammar.SqlStatementParser; +import org.hibernate.grammars.importsql.SqlStatementLexer; +import org.hibernate.grammars.importsql.SqlStatementParser; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.UnbufferedCharStream; diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SqlStatementParserListenerImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SqlStatementParserListenerImpl.java index 88fa27ea0a..ab2d234ca1 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SqlStatementParserListenerImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SqlStatementParserListenerImpl.java @@ -9,8 +9,8 @@ package org.hibernate.tool.hbm2ddl; import java.util.ArrayList; import java.util.List; -import org.hibernate.tool.hbm2ddl.grammar.SqlStatementParser; -import org.hibernate.tool.hbm2ddl.grammar.SqlStatementParserBaseListener; +import org.hibernate.grammars.importsql.SqlStatementParser; +import org.hibernate.grammars.importsql.SqlStatementParserBaseListener; /** * @author Andrea Boriero diff --git a/hibernate-core/src/test/java/org/hibernate/test/fileimport/StatementsWithoutTerminalCharsImportFileTest.java b/hibernate-core/src/test/java/org/hibernate/test/fileimport/StatementsWithoutTerminalCharsImportFileTest.java index 5c076aad1a..1632f6be2b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/fileimport/StatementsWithoutTerminalCharsImportFileTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/fileimport/StatementsWithoutTerminalCharsImportFileTest.java @@ -21,7 +21,6 @@ import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoo import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; import org.hibernate.tool.hbm2ddl.ImportScriptException; import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor; -import org.hibernate.tool.hbm2ddl.grammar.SqlStatementParser; import org.hibernate.tool.schema.SourceType; import org.hibernate.tool.schema.TargetType; import org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl;