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:24:30 GMT
Repository: groovy
Updated Branches:
  refs/heads/master c3d12bb6a -> 13e4a522c


Minor refactoring


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

Branch: refs/heads/master
Commit: 13e4a522c44f3c0ff337f3ee949aa87d443ca64d
Parents: c3d12bb
Author: sunlan <sunlan@apache.org>
Authored: Thu Jul 27 23:23:45 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Thu Jul 27 23:24:15 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/13e4a522/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 6a10aff..ce83274 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
@@ -2455,13 +2455,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
@@ -2510,24 +2504,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
@@ -2585,17 +2567,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:
@@ -2619,35 +2598,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
@@ -3988,6 +3949,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