groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 15/18: consolidate calls to ClassNode#makeArray() and other minor edits
Date Sun, 17 Nov 2019 08:54:10 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit abfcecf701d690e7f602ebbe4544638d7b5db6a5
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Fri Nov 15 17:08:34 2019 -0600

    consolidate calls to ClassNode#makeArray() and other minor edits
    
    (cherry picked from commit 159e1a9d879e68431cd9d8895d372e598d2d7463)
---
 .../groovy/antlr/AntlrParserPluginFactory.java     |  3 +-
 .../apache/groovy/parser/antlr4/AstBuilder.java    | 60 ++++++++--------------
 2 files changed, 23 insertions(+), 40 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPluginFactory.java b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPluginFactory.java
index 61bab21..f0f3f9e 100644
--- a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPluginFactory.java
+++ b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPluginFactory.java
@@ -21,10 +21,9 @@ package org.codehaus.groovy.antlr;
 import org.codehaus.groovy.control.ParserPlugin;
 import org.codehaus.groovy.control.ParserPluginFactory;
 
-/**
- */
 @Deprecated
 public class AntlrParserPluginFactory extends ParserPluginFactory {
+    @Deprecated
     public ParserPlugin createParserPlugin() {
         return new AntlrParserPlugin();
     }
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index c6efdec..580f23d 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -3085,9 +3085,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
             if (asBoolean(ctx.arrayInitializer())) {
                 ClassNode elementType = classNode;
                 allDimList = this.visitDims(ctx.dims());
-
-                for (int i = 0, n = allDimList.size() - 1; i < n; i++) {
-                    elementType = elementType.makeArray();
+                for (int i = 0, n = allDimList.size() - 1; i < n; i += 1) {
+                    elementType = this.createArrayType(elementType);
                 }
 
                 arrayExpression =
@@ -3124,7 +3123,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
                 Collections.reverse(allDimList);
             }
 
-            arrayExpression.setType(createArrayType(classNode, allDimList));
+            arrayExpression.setType(this.createArrayType(classNode, allDimList));
 
             return configureAST(arrayExpression, ctx);
         }
@@ -3132,15 +3131,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
         throw createParsingFailedException("Unsupported creator: " + ctx.getText(), ctx);
     }
 
-    private ClassNode createArrayType(ClassNode classNode, List<List<AnnotationNode>>
dimList) {
-        ClassNode arrayType = classNode;
-        for (int i = 0, n = dimList.size(); i < n; i++) {
-            arrayType = arrayType.makeArray();
-            arrayType.addAnnotations(dimList.get(i));
-        }
-        return arrayType;
-    }
-
     private static String nextAnonymousClassName(ClassNode outerClass) {
         int anonymousClassCount = 0;
         for (Iterator<InnerClassNode> it = outerClass.getInnerClasses(); it.hasNext();)
{
@@ -4114,6 +4104,19 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
         return this.createClassNode(ctx);
     }
 
+    private ClassNode createArrayType(ClassNode elementType, List<List<AnnotationNode>>
dimsList) {
+        ClassNode arrayType = elementType;
+        for (int i = 0, n = dimsList.size(); i < n; i += 1) {
+            arrayType = this.createArrayType(arrayType);
+            arrayType.addAnnotations(dimsList.get(i));
+        }
+        return arrayType;
+    }
+
+    private ClassNode createArrayType(ClassNode elementType) {
+        return elementType.makeArray();
+    }
+
     private ClassNode createClassNode(GroovyParserRuleContext ctx) {
         ClassNode result = ClassHelper.make(ctx.getText());
 
@@ -4200,7 +4203,12 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
         ClassNode classNode = this.visitType(typeContext);
 
         if (asBoolean(ellipsis)) {
-            classNode = configureAST(classNode.makeArray(), classNode);
+            classNode = this.createArrayType(classNode);
+            if (!asBoolean(typeContext)) {
+                configureAST(classNode, ellipsis);
+            } else {
+                configureAST(classNode, typeContext, configureAST(new ConstantExpression("..."),
ellipsis));
+            }
         }
 
         Parameter parameter =
@@ -4411,17 +4419,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
         );
     }
 
-    /*
-    private org.codehaus.groovy.syntax.Token createGroovyToken(String text, int startLine,
int startColumn) {
-        return new org.codehaus.groovy.syntax.Token(
-                Types.lookup(text, Types.ANY),
-                text,
-                startLine,
-                startColumn
-        );
-    }
-    */
-
     /**
      * set the script source position
      */
@@ -4553,18 +4550,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
         parser.addErrorListener(this.createANTLRErrorListener());
     }
 
-    /*
-    private String createExceptionMessage(Throwable t) {
-        StringWriter sw = new StringWriter();
-
-        try (PrintWriter pw = new PrintWriter(sw)) {
-            t.printStackTrace(pw);
-        }
-
-        return sw.toString();
-    }
-    */
-
     private static class DeclarationListStatement extends Statement {
         private final List<ExpressionStatement> declarationStatements;
 
@@ -4678,4 +4663,3 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
 
     private static final String CLASS_NAME = "_CLASS_NAME";
 }
-


Mime
View raw message