strongduanmu commented on code in PR #38032:
URL: https://github.com/apache/shardingsphere/pull/38032#discussion_r2852124648


##########
parser/sql/engine/core/src/main/java/org/apache/shardingsphere/sql/parser/engine/core/ParseASTNode.java:
##########
@@ -52,11 +56,70 @@ public ParseTree getRootNode() {
      */
     public Collection<Token> getHiddenTokens() {
         Collection<Token> result = new LinkedList<>();
-        for (Token each : tokenStream.getTokens()) {
-            if (Token.HIDDEN_CHANNEL == each.getChannel()) {
-                result.add(each);
+        List<Token> allTokens = tokenStream.getTokens();
+        int i = 0;
+        while (i < allTokens.size()) {
+            Token each = allTokens.get(i);
+            if (Token.HIDDEN_CHANNEL != each.getChannel()) {
+                i++;
+                continue;
             }
+            if (isExecutableCommentStart(each)) {
+                int endIndex = findExecutableCommentEnd(allTokens, i);
+                if (endIndex > i) {
+                    result.add(buildMergedExecutableCommentToken(each, 
allTokens.get(endIndex)));
+                    i = endIndex + 1;
+                    continue;
+                }
+            }
+            result.add(each);
+            i++;
         }
         return result;
     }
+    
+    /**
+     * Check if token is executable comment start.
+     *
+     * @param token token to check
+     * @return true if executable comment start
+     */
+    private boolean isExecutableCommentStart(final Token token) {
+        return token.getText().startsWith("/*!");
+    }
+    
+    /**
+     * Find executable comment end index.
+     *
+     * @param tokens all tokens
+     * @param startIndex start index
+     * @return end index or -1 if not found
+     */
+    private int findExecutableCommentEnd(final List<Token> tokens, final int 
startIndex) {
+        for (int i = startIndex + 1; i < tokens.size(); i++) {
+            Token each = tokens.get(i);
+            if (Token.HIDDEN_CHANNEL == each.getChannel() && 
"*/".equals(each.getText())) {
+                return i;
+            }
+        }
+        return -1;
+    }
+    
+    /**
+     * Build merged executable comment token.
+     *
+     * @param startToken start token
+     * @param endToken end token
+     * @return merged token
+     */
+    private Token buildMergedExecutableCommentToken(final Token startToken, 
final Token endToken) {
+        CharStream charStream = tokenStream.getTokenSource().getInputStream();
+        String fullText = 
charStream.getText(Interval.of(startToken.getStartIndex(), 
endToken.getStopIndex()));
+        CommonToken merged = new CommonToken(startToken.getType());
+        merged.setText(fullText);

Review Comment:
   What is purpose of this method? 



##########
parser/sql/engine/core/src/main/java/org/apache/shardingsphere/sql/parser/engine/core/ParseASTNode.java:
##########
@@ -52,11 +56,70 @@ public ParseTree getRootNode() {
      */
     public Collection<Token> getHiddenTokens() {
         Collection<Token> result = new LinkedList<>();
-        for (Token each : tokenStream.getTokens()) {
-            if (Token.HIDDEN_CHANNEL == each.getChannel()) {
-                result.add(each);
+        List<Token> allTokens = tokenStream.getTokens();
+        int i = 0;
+        while (i < allTokens.size()) {

Review Comment:
   If you need index, maybe `for index` loop is better.



##########
parser/sql/engine/core/src/main/java/org/apache/shardingsphere/sql/parser/engine/core/ParseASTNode.java:
##########
@@ -52,11 +56,70 @@ public ParseTree getRootNode() {
      */
     public Collection<Token> getHiddenTokens() {
         Collection<Token> result = new LinkedList<>();
-        for (Token each : tokenStream.getTokens()) {
-            if (Token.HIDDEN_CHANNEL == each.getChannel()) {
-                result.add(each);
+        List<Token> allTokens = tokenStream.getTokens();
+        int i = 0;
+        while (i < allTokens.size()) {
+            Token each = allTokens.get(i);
+            if (Token.HIDDEN_CHANNEL != each.getChannel()) {
+                i++;
+                continue;
             }
+            if (isExecutableCommentStart(each)) {
+                int endIndex = findExecutableCommentEnd(allTokens, i);
+                if (endIndex > i) {
+                    result.add(buildMergedExecutableCommentToken(each, 
allTokens.get(endIndex)));
+                    i = endIndex + 1;
+                    continue;
+                }
+            }
+            result.add(each);
+            i++;
         }
         return result;
     }
+    
+    /**
+     * Check if token is executable comment start.
+     *
+     * @param token token to check
+     * @return true if executable comment start
+     */

Review Comment:
   Please remove javadoc for private method



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to