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
Date Thu, 27 Jul 2017 15:26:52 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 16b281087 -> 93f410813


Minor refactoring

(cherry picked from commit 13e4a52)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 93f410813918f78e1c033f02faeb5699a8244d9a
Parents: 16b2810
Author: sunlan <sunlan@apache.org>
Authored: Thu Jul 27 23:23:45 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Thu Jul 27 23:26:35 2017 +0800

----------------------------------------------------------------------
 .../apache/groovy/parser/antlr4/AstBuilder.java | 71 ++++++--------------
 1 file changed, 21 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/93f41081/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 750e4f8..4437ad6 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
@@ -2476,13 +2476,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
 
     @Override
     public BinaryExpression visitPowerExprAlt(PowerExprAltContext ctx) {
-        BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op,
ctx.right);
-
-        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
-            return this.configureAST(binaryExpression, ctx.op);
-        }
-
-        return this.configureAST(binaryExpression, ctx);
+        return this.createBinaryExpression(ctx.left, ctx.op, ctx.right, ctx);
     }
 
     @Override
@@ -2531,24 +2525,12 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
 
     @Override
     public BinaryExpression visitMultiplicativeExprAlt(MultiplicativeExprAltContext ctx)
{
-        BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op,
ctx.right);
-
-        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
-            return this.configureAST(binaryExpression, ctx.op);
-        }
-
-        return this.configureAST(binaryExpression, ctx);
+        return this.createBinaryExpression(ctx.left, ctx.op, ctx.right, ctx);
     }
 
     @Override
     public BinaryExpression visitAdditiveExprAlt(AdditiveExprAltContext ctx) {
-        BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op,
ctx.right);
-
-        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
-            return this.configureAST(binaryExpression, ctx.op);
-        }
-
-        return this.configureAST(binaryExpression, ctx);
+        return this.createBinaryExpression(ctx.left, ctx.op, ctx.right, ctx);
     }
 
     @Override
@@ -2606,17 +2588,14 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
             case GT:
             case LT:
             case IN:
-            case NOT_IN:
-            {
-                BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left,
ctx.op, ctx.right);
-
+            case NOT_IN: {
                 if (ctx.op.getType() == IN || ctx.op.getType() == NOT_IN ) {
-                    if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
-                        return this.configureAST(binaryExpression, ctx.op);
-                    }
+                    return this.createBinaryExpression(ctx.left, ctx.op, ctx.right, ctx);
                 }
 
-                return this.configureAST(binaryExpression, ctx);
+                return this.configureAST(
+                        this.createBinaryExpression(ctx.left, ctx.op, ctx.right),
+                        ctx);
             }
 
             default:
@@ -2640,35 +2619,17 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
 
     @Override
     public BinaryExpression visitAndExprAlt(AndExprAltContext ctx) {
-        BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op,
ctx.right);
-
-        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
-            return this.configureAST(binaryExpression, ctx.op);
-        }
-
-        return this.configureAST(binaryExpression, ctx);
+        return this.createBinaryExpression(ctx.left, ctx.op, ctx.right, ctx);
     }
 
     @Override
     public BinaryExpression visitExclusiveOrExprAlt(ExclusiveOrExprAltContext ctx) {
-        BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op,
ctx.right);
-
-        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
-            return this.configureAST(binaryExpression, ctx.op);
-        }
-
-        return this.configureAST(binaryExpression, ctx);
+        return this.createBinaryExpression(ctx.left, ctx.op, ctx.right, ctx);
     }
 
     @Override
     public BinaryExpression visitInclusiveOrExprAlt(InclusiveOrExprAltContext ctx) {
-        BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op,
ctx.right);
-
-        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
-            return this.configureAST(binaryExpression, ctx.op);
-        }
-
-        return this.configureAST(binaryExpression, ctx);
+        return this.createBinaryExpression(ctx.left, ctx.op, ctx.right, ctx);
     }
 
     @Override
@@ -4065,6 +4026,16 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
         return new BinaryExpression((Expression) this.visit(left), this.createGroovyToken(op),
(Expression) this.visit(right));
     }
 
+    private BinaryExpression createBinaryExpression(ExpressionContext left, Token op, ExpressionContext
right, ExpressionContext ctx) {
+        BinaryExpression binaryExpression = this.createBinaryExpression(left, op, right);
+
+        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
+            return this.configureAST(binaryExpression, op);
+        }
+
+        return this.configureAST(binaryExpression, ctx);
+    }
+
     private Statement unpackStatement(Statement statement) {
         if (statement instanceof DeclarationListStatement) {
             List<ExpressionStatement> expressionStatementList = ((DeclarationListStatement)
statement).getDeclarationStatements();


Mime
View raw message