Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 71903bdf7 -> c5c4b26be


Minor refactoring


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

Branch: refs/heads/GROOVY_2_6_X
Commit: c5c4b26be7947d25b57a6eb7315ff041841f274a
Parents: 71903bd
Author: sunlan <[email protected]>
Authored: Fri Aug 25 11:27:35 2017 +0800
Committer: sunlan <[email protected]>
Committed: Fri Aug 25 11:27:35 2017 +0800

----------------------------------------------------------------------
 .../apache/groovy/parser/antlr4/AstBuilder.java | 48 ++++++--------------
 1 file changed, 15 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/c5c4b26b/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 57d54f8..533366e 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
@@ -2052,14 +2052,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(this.createCallMethodCallExpression(attributeExpression, 
argumentsExpr, true), ctx);
             }
 
             if (baseExpr instanceof PropertyExpression) { // e.g. obj.a(1, 2)
@@ -2072,16 +2065,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(this.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);
                 }
@@ -2180,21 +2164,15 @@ 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);
             }
 
-
             if (baseExpr instanceof PropertyExpression) { // e.g. obj.m {  }
                 PropertyExpression propertyExpression = (PropertyExpression) 
baseExpr;
 
@@ -2232,10 +2210,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;
     }
@@ -3284,7 +3266,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
                 if (allFalse) {
                     values.add(this.configureAST(new ConstantExpression(null), 
e));
                 } else {
-                    values.add(this.configureAST(new 
MethodCallExpression(expression, CALL_STR, new ArgumentListExpression()), e));
+                    
values.add(this.configureAST(this.createCallMethodCallExpression(expression, 
new ArgumentListExpression(), true), e));
                 }
             } else {
                 values.add(expression);

Reply via email to