This is an automated email from the ASF dual-hosted git repository.

zhonghongsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 4c01881f962 Optimize SQLParserErrorListener code style (#20675)
4c01881f962 is described below

commit 4c01881f9621a91791d0be6ad0558363842c84f0
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Wed Aug 31 20:01:24 2022 +0800

    Optimize SQLParserErrorListener code style (#20675)
    
    * Optimize SQLParserErrorListener code style
    
    * update error message
---
 ...rrorListener.java => SQLParserErrorListener.java} | 20 +++++++++-----------
 .../core/database/parser/SQLParserExecutor.java      |  5 ++---
 2 files changed, 11 insertions(+), 14 deletions(-)

diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/parser/ParserErrorListener.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/parser/SQLParserErrorListener.java
similarity index 66%
rename from 
shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/parser/ParserErrorListener.java
rename to 
shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/parser/SQLParserErrorListener.java
index 7468cac6170..f57af0e40c0 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/parser/ParserErrorListener.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/parser/SQLParserErrorListener.java
@@ -25,27 +25,25 @@ import org.antlr.v4.runtime.Recognizer;
 import org.antlr.v4.runtime.misc.ParseCancellationException;
 
 /**
- * sql parser error listener.
+ * SQL parser error listener.
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ParserErrorListener extends BaseErrorListener {
+public final class SQLParserErrorListener extends BaseErrorListener {
     
-    private static final ParserErrorListener INSTANCE = new 
ParserErrorListener();
+    private static final SQLParserErrorListener INSTANCE = new 
SQLParserErrorListener();
     
     /**
-     * get ParserErrorListener instance.
-     * @return ParserErrorListener instance
+     * Get instance.
+     * 
+     * @return instance
      */
-    public static ParserErrorListener getInstance() {
+    public static SQLParserErrorListener getInstance() {
         return INSTANCE;
     }
     
     @Override
     public void syntaxError(final Recognizer<?, ?> recognizer, final Object 
offendingSymbol, final int line, final int charPositionInLine,
-                            final String msg, final RecognitionException e) 
throws ParseCancellationException {
-        StringBuilder sb = new StringBuilder("syntax error at line ");
-        sb.append(line).append(", position 
").append(charPositionInLine).append(", near 
").append(offendingSymbol).append(", ").append(msg);
-        throw new ParseCancellationException(sb.toString());
+                            final String message, final RecognitionException 
e) throws ParseCancellationException {
+        throw new ParseCancellationException(message + " at line " + line + ", 
position " + charPositionInLine + ", near " + offendingSymbol);
     }
-    
 }
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/parser/SQLParserExecutor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/parser/SQLParserExecutor.java
index 125c1b32115..0386a947a7c 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/parser/SQLParserExecutor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/parser/SQLParserExecutor.java
@@ -60,12 +60,11 @@ public final class SQLParserExecutor {
             ((Parser) sqlParser).reset();
             ((Parser) 
sqlParser).getInterpreter().setPredictionMode(PredictionMode.LL);
             ((Parser) sqlParser).removeErrorListeners();
-            ((Parser) 
sqlParser).addErrorListener(ParserErrorListener.getInstance());
+            ((Parser) 
sqlParser).addErrorListener(SQLParserErrorListener.getInstance());
             try {
                 return (ParseASTNode) sqlParser.parse();
             } catch (final ParseCancellationException e) {
-                StringBuilder sb = new 
StringBuilder(sql).append(";").append(e.getMessage());
-                throw new SQLParsingException(sb.toString());
+                throw new SQLParsingException(sql + ", " + e.getMessage());
             }
         }
     }

Reply via email to