You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/11/11 02:52:10 UTC

[GitHub] [shardingsphere] jingshanglu commented on a change in pull request #8116: Add sql formart visitor

jingshanglu commented on a change in pull request #8116:
URL: https://github.com/apache/shardingsphere/pull/8116#discussion_r521052668



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/impl/MySQLFormatSQLVisitor.java
##########
@@ -19,11 +19,423 @@
 
 import lombok.AccessLevel;
 import lombok.Getter;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.antlr.v4.runtime.tree.RuleNode;
+import org.antlr.v4.runtime.tree.TerminalNode;
 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementBaseVisitor;
+import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser;
 
 /**
  * MySQL Format SQL visitor for MySQL.
  */
 @Getter(AccessLevel.PROTECTED)
 public abstract class MySQLFormatSQLVisitor extends MySQLStatementBaseVisitor<String> {
+    private StringBuilder result = new StringBuilder();

Review comment:
       First, `FormartVisitor` is different from `StatementVisitors`, `StatementVisitors` need create different type `Segment`,  `FormartVisitor` just need `StringBuilder`, so using shared variables can reduce the cost of creating objects.
   Second, there is no need to processe the return value of child elements when using shared variables
    ,just call visit(`childrule`), 
   When a visitor function is added, we do not need to modify  its parent function.ItWill reduce the amount of code, otherwise, you need to create a visitor function for each rule. @tristaZero 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org