Repository: groovy
Updated Branches:
  refs/heads/master 47a47a4ac -> 482e8d369


Minor refactoring


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

Branch: refs/heads/master
Commit: 482e8d3699e5593a60cc8db5523895fbf7235367
Parents: 47a47a4
Author: sunlan <[email protected]>
Authored: Fri Aug 25 11:17:11 2017 +0800
Committer: sunlan <[email protected]>
Committed: Fri Aug 25 11:17:23 2017 +0800

----------------------------------------------------------------------
 .../apache/groovy/parser/antlr4/AstBuilder.java | 46 ++++++--------------
 1 file changed, 14 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/482e8d36/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 0a80fbf..968e7c4 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
@@ -2039,14 +2039,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
                 AttributeExpression attributeExpression = 
(AttributeExpression) baseExpr;
                 attributeExpression.setSpreadSafe(false); // whether 
attributeExpression is spread safe or not, we must reset it as false
 
-                MethodCallExpression methodCallExpression =
-                        new MethodCallExpression(
-                                attributeExpression,
-                                CALL_STR,
-                                argumentsExpr
-                        );
-
-                return this.configureAST(methodCallExpression, ctx);
+                return 
this.configureAST(createCallMethodCallExpression(attributeExpression, 
argumentsExpr, true), ctx);
             }
 
             if (baseExpr instanceof PropertyExpression) { // e.g. obj.a(1, 2)
@@ -2059,16 +2052,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
             if (baseExpr instanceof VariableExpression) { // void and 
primitive type AST node must be an instance of VariableExpression
                 String baseExprText = baseExpr.getText();
                 if (VOID_STR.equals(baseExprText)) { // e.g. void()
-                    MethodCallExpression methodCallExpression =
-                            new MethodCallExpression(
-                                    this.createConstantExpression(baseExpr),
-                                    CALL_STR,
-                                    argumentsExpr
-                            );
-
-                    methodCallExpression.setImplicitThis(false);
-
-                    return this.configureAST(methodCallExpression, ctx);
+                    return 
this.configureAST(createCallMethodCallExpression(this.createConstantExpression(baseExpr),
 argumentsExpr), ctx);
                 } else if (PRIMITIVE_TYPE_SET.contains(baseExprText)) { // 
e.g. int(), long(), float(), etc.
                     throw createParsingFailedException("Primitive type 
literal: " + baseExprText + " cannot be used as a method name", ctx);
                 }
@@ -2163,18 +2147,12 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
 
             // e.g. 1 {}, 1.1 {}
             if (baseExpr instanceof ConstantExpression && isTrue(baseExpr, 
IS_NUMERIC)) {
-                MethodCallExpression methodCallExpression =
-                        new MethodCallExpression(
-                                baseExpr,
-                                CALL_STR,
-                                this.configureAST(
-                                        new 
ArgumentListExpression(closureExpression),
-                                        closureExpression
-                                )
-                        );
-                methodCallExpression.setImplicitThis(false);
-
-                return this.configureAST(methodCallExpression, ctx);
+                return this.configureAST(this.createCallMethodCallExpression(
+                        baseExpr,
+                        this.configureAST(
+                                new ArgumentListExpression(closureExpression),
+                                closureExpression)
+                ), ctx);
             }
 
 
@@ -2215,10 +2193,14 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
     }
 
     private MethodCallExpression createCallMethodCallExpression(Expression 
baseExpr, Expression argumentsExpr) {
+        return createCallMethodCallExpression(baseExpr, argumentsExpr, false);
+    }
+
+    private MethodCallExpression createCallMethodCallExpression(Expression 
baseExpr, Expression argumentsExpr, boolean implicitThis) {
         MethodCallExpression methodCallExpression =
                 new MethodCallExpression(baseExpr, CALL_STR, argumentsExpr);
 
-        methodCallExpression.setImplicitThis(false);
+        methodCallExpression.setImplicitThis(implicitThis);
 
         return methodCallExpression;
     }
@@ -3237,7 +3219,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
                             return this.configureAST(new 
ConstantExpression(null), e);
                         }
 
-                        return this.configureAST(new 
MethodCallExpression(expression, CALL_STR, new ArgumentListExpression()), e);
+                        return 
this.configureAST(this.createCallMethodCallExpression(expression, new 
ArgumentListExpression(), true), e);
                     }
 
                     return expression;

Reply via email to