groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Minor refactoring: variableDeclaration
Date Sun, 01 Oct 2017 00:49:17 GMT
Repository: groovy
Updated Branches:
  refs/heads/master f4b8989f7 -> 7b101dd98


Minor refactoring: variableDeclaration


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7b101dd9
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7b101dd9
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7b101dd9

Branch: refs/heads/master
Commit: 7b101dd98ffc04b1bfd2447bbe277340d8954add
Parents: f4b8989
Author: sunlan <sunlan@apache.org>
Authored: Sun Oct 1 08:49:06 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Sun Oct 1 08:49:06 2017 +0800

----------------------------------------------------------------------
 src/antlr/GroovyParser.g4                       | 22 +++++++-------
 .../apache/groovy/parser/antlr4/AstBuilder.java | 31 ++++++++++++--------
 2 files changed, 29 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/7b101dd9/src/antlr/GroovyParser.g4
----------------------------------------------------------------------
diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index a094f76..59a6f4c 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -565,24 +565,24 @@ localVariableDeclaration
         variableDeclaration[0]
     ;
 
+classifiedModifiers[int t]
+    :   { 0 == $t }? variableModifiers
+    |   { 1 == $t }? modifiers
+    ;
+
+
 /**
  *  t   0: local variable declaration; 1: field declaration
  */
 variableDeclaration[int t]
-    :   (   { 0 == $t }? variableModifiers
-        |   { 1 == $t }? modifiers
+@leftfactor { classifiedModifiers }
+    :   classifiedModifiers[$t]
+        (   type? variableDeclarators
+        |   typeNamePairs nls ASSIGN nls variableInitializer
         )
-        type? variableDeclarators
     |
-        (   { 0 == $t }? variableModifiersOpt
-        |   { 1 == $t }? modifiersOpt
-        )
+        classifiedModifiers[$t]?
         type variableDeclarators
-    |
-        (   { 0 == $t }? variableModifiers
-        |   { 1 == $t }? modifiers
-        )
-        typeNamePairs nls ASSIGN nls variableInitializer
     ;
 
 typeNamePairs

http://git-wip-us.apache.org/repos/asf/groovy/blob/7b101dd9/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
----------------------------------------------------------------------
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 d18fd2c..29cd49e 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
@@ -1510,19 +1510,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
     }
 
     private ModifierManager createModifierManager(VariableDeclarationContext ctx) {
-        List<ModifierNode> modifierNodeList = Collections.emptyList();
-
-        if (asBoolean(ctx.variableModifiers())) {
-            modifierNodeList = this.visitVariableModifiers(ctx.variableModifiers());
-        } else if (asBoolean(ctx.variableModifiersOpt())) {
-            modifierNodeList = this.visitVariableModifiersOpt(ctx.variableModifiersOpt());
-        } else if (asBoolean(ctx.modifiers())) {
-            modifierNodeList = this.visitModifiers(ctx.modifiers());
-        } else if (asBoolean(ctx.modifiersOpt())) {
-            modifierNodeList = this.visitModifiersOpt(ctx.modifiersOpt());
-        }
-
-        return new ModifierManager(this, modifierNodeList);
+        return new ModifierManager(this, this.visitClassifiedModifiers(ctx.classifiedModifiers()));
     }
 
     private DeclarationListStatement createMultiAssignmentDeclarationListStatement(VariableDeclarationContext
ctx, ModifierManager modifierManager) {
@@ -1554,6 +1542,23 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
     }
 
     @Override
+    public List<ModifierNode> visitClassifiedModifiers(ClassifiedModifiersContext ctx)
{
+        List<ModifierNode> modifierNodeList = Collections.emptyList();
+
+        if (!asBoolean(ctx)) {
+            return modifierNodeList;
+        }
+
+        if (asBoolean(ctx.variableModifiers())) {
+            modifierNodeList = this.visitVariableModifiers(ctx.variableModifiers());
+        } if (asBoolean(ctx.modifiers())) {
+            modifierNodeList = this.visitModifiers(ctx.modifiers());
+        }
+
+        return modifierNodeList;
+    }
+
+    @Override
     public DeclarationListStatement visitVariableDeclaration(VariableDeclarationContext ctx)
{
         ModifierManager modifierManager = this.createModifierManager(ctx);
 


Mime
View raw message