groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] branch master updated: Transfer source offsets to tuple wrapper and protect NO_ARGUMENTS
Date Fri, 30 Aug 2019 20:30:46 GMT
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new e75905c  Transfer source offsets to tuple wrapper and protect NO_ARGUMENTS
e75905c is described below

commit e75905c974686ed07936838384af303abbb64f38
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Fri Aug 30 15:08:46 2019 -0500

    Transfer source offsets to tuple wrapper and protect NO_ARGUMENTS
---
 .../groovy/ast/expr/ConstructorCallExpression.java | 34 ++++----
 .../groovy/ast/expr/MethodCallExpression.java      | 94 +++++++++++-----------
 2 files changed, 65 insertions(+), 63 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/expr/ConstructorCallExpression.java b/src/main/java/org/codehaus/groovy/ast/expr/ConstructorCallExpression.java
index cbd5c7b..712c55d 100644
--- a/src/main/java/org/codehaus/groovy/ast/expr/ConstructorCallExpression.java
+++ b/src/main/java/org/codehaus/groovy/ast/expr/ConstructorCallExpression.java
@@ -23,7 +23,7 @@ import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.GroovyCodeVisitor;
 
 /**
- * A constructor call
+ * A constructor call.
  */
 public class ConstructorCallExpression extends Expression implements MethodCall {
 
@@ -31,9 +31,10 @@ public class ConstructorCallExpression extends Expression implements MethodCall
     private boolean usesAnonymousInnerClass;
 
     public ConstructorCallExpression(ClassNode type, Expression arguments) {
-        super.setType(type);
+        setType(type);
         if (!(arguments instanceof TupleExpression)) {
             this.arguments = new TupleExpression(arguments);
+            this.arguments.setSourcePosition(arguments);
         } else {
             this.arguments = arguments;
         }
@@ -44,12 +45,11 @@ public class ConstructorCallExpression extends Expression implements MethodCall
     }
 
     public Expression transformExpression(ExpressionTransformer transformer) {
-        Expression args = transformer.transform(arguments);
-        ConstructorCallExpression ret = new ConstructorCallExpression(getType(), args);
-        ret.setSourcePosition(this);
-        ret.setUsingAnonymousInnerClass(isUsingAnonymousInnerClass());
-        ret.copyNodeMetaData(this);
-        return ret;
+        ConstructorCallExpression answer = new ConstructorCallExpression(getType(), transformer.transform(arguments));
+        answer.setUsingAnonymousInnerClass(isUsingAnonymousInnerClass());
+        answer.setSourcePosition(this);
+        answer.copyNodeMetaData(this);
+        return answer;
     }
 
     public ASTNode getReceiver() {
@@ -65,7 +65,7 @@ public class ConstructorCallExpression extends Expression implements MethodCall
     }
 
     public String getText() {
-        String text = null;
+        String text;
         if (isSuperCall()) {
             text = "super ";
         } else if (isThisCall()) {
@@ -76,27 +76,27 @@ public class ConstructorCallExpression extends Expression implements MethodCall
         return text + arguments.getText();
     }
 
-    public String toString() {
-        return super.toString() + "[type: " + getType() + " arguments: " + arguments + "]";
+    public boolean isSpecialCall() {
+        return isThisCall() || isSuperCall();
     }
 
     public boolean isSuperCall() {
         return getType() == ClassNode.SUPER;
     }
 
-    public boolean isSpecialCall() {
-        return isThisCall() || isSuperCall();
-    }
-
     public boolean isThisCall() {
         return getType() == ClassNode.THIS;
     }
 
+    public boolean isUsingAnonymousInnerClass() {
+        return usesAnonymousInnerClass;
+    }
+
     public void setUsingAnonymousInnerClass(boolean usage) {
         this.usesAnonymousInnerClass = usage;
     }
 
-    public boolean isUsingAnonymousInnerClass() {
-        return usesAnonymousInnerClass;
+    public String toString() {
+        return super.toString() + "[type: " + getType() + " arguments: " + arguments + "]";
     }
 }
diff --git a/src/main/java/org/codehaus/groovy/ast/expr/MethodCallExpression.java b/src/main/java/org/codehaus/groovy/ast/expr/MethodCallExpression.java
index f0250a8..4f8583c 100644
--- a/src/main/java/org/codehaus/groovy/ast/expr/MethodCallExpression.java
+++ b/src/main/java/org/codehaus/groovy/ast/expr/MethodCallExpression.java
@@ -24,44 +24,52 @@ import org.codehaus.groovy.ast.GenericsType;
 import org.codehaus.groovy.ast.GroovyCodeVisitor;
 import org.codehaus.groovy.ast.MethodNode;
 
+import java.util.Collections;
+import java.util.List;
+
 /**
- * A method call on an object or class
+ * A method call on an object or class.
  */
 public class MethodCallExpression extends Expression implements MethodCall {
 
     private Expression objectExpression;
     private Expression method;
     private Expression arguments;
-    private boolean spreadSafe = false;
-    private boolean safe = false;
-    private boolean implicitThis;
+
+    private boolean implicitThis = true;
+    private boolean spreadSafe;
+    private boolean safe;
 
     // type spec for generics
-    private GenericsType[] genericsTypes = null;
-    private boolean usesGenerics = false;
+    private GenericsType[] genericsTypes;
+    private boolean usesGenerics;
 
     private MethodNode target;
 
-    public static final Expression NO_ARGUMENTS = new TupleExpression();
+    public static final Expression NO_ARGUMENTS = new TupleExpression() {
+        @Override
+        public List<Expression> getExpressions() {
+            return Collections.unmodifiableList(super.getExpressions());
+        }
+        @Override
+        public TupleExpression addExpression(Expression e) {
+            throw new UnsupportedOperationException();
+        }
+    };
 
     public MethodCallExpression(Expression objectExpression, String method, Expression arguments)
{
-        this(objectExpression,new ConstantExpression(method),arguments);
+        this(objectExpression, new ConstantExpression(method), arguments);
     }
 
     public MethodCallExpression(Expression objectExpression, Expression method, Expression
arguments) {
-        this.objectExpression = objectExpression;
-        this.method = method;
-        if (!(arguments instanceof TupleExpression)){
-            this.arguments = new TupleExpression(arguments);
-        } else {
-            this.arguments = arguments;
-        }
-        //TODO: set correct type here
-        // if setting type and a methodcall is the last expression in a method,
+        setMethod(method);
+        setArguments(arguments);
+        setObjectExpression(objectExpression);
+
+        // TODO: set correct type here
+        // if setting type and a MethodCall is the last expression in a method,
         // then the method will return null if the method itself is not void too!
         // (in bytecode after call: aconst_null, areturn)
-        this.setType(ClassHelper.DYNAMIC_TYPE);
-        this.setImplicitThis(true);
     }
 
     public void visit(GroovyCodeVisitor visitor) {
@@ -86,8 +94,9 @@ public class MethodCallExpression extends Expression implements MethodCall
{
     }
 
     public void setArguments(Expression arguments) {
-        if (!(arguments instanceof TupleExpression)){
+        if (!(arguments instanceof TupleExpression)) {
             this.arguments = new TupleExpression(arguments);
+            this.arguments.setSourcePosition(arguments);
         } else {
             this.arguments = arguments;
         }
@@ -101,26 +110,26 @@ public class MethodCallExpression extends Expression implements MethodCall
{
       this.method = method;
     }
 
-    public ASTNode getReceiver() {
-        return getObjectExpression();
-    }
-
     /**
      * This method returns the method name as String if it is no dynamic
      * calculated method name, but a constant.
      */
     public String getMethodAsString() {
-        if (! (method instanceof ConstantExpression)) return null;
+        if (!(method instanceof ConstantExpression)) return null;
         ConstantExpression constant = (ConstantExpression) method;
         return constant.getText();
     }
 
+    public Expression getObjectExpression() {
+        return objectExpression;
+    }
+
     public void setObjectExpression(Expression objectExpression) {
       this.objectExpression = objectExpression;
     }
 
-    public Expression getObjectExpression() {
-        return objectExpression;
+    public ASTNode getReceiver() {
+        return getObjectExpression();
     }
 
     public String getText() {
@@ -165,17 +174,6 @@ public class MethodCallExpression extends Expression implements MethodCall
{
         this.implicitThis = implicitThis;
     }
 
-    public String toString() {
-        return super.toString()
-            + "[object: "
-            + objectExpression
-            + " method: "
-            + method
-            + " arguments: "
-            + arguments
-            + "]";
-    }
-
     public GenericsType[] getGenericsTypes() {
         return genericsTypes;
     }
@@ -190,26 +188,26 @@ public class MethodCallExpression extends Expression implements MethodCall
{
     }
 
     /**
+     * @return the target as method node if set
+     */
+    public MethodNode getMethodTarget() {
+        return target;
+    }
+
+    /**
      * Sets a method call target for a direct method call.
      * WARNING: A method call made this way will run outside of the MOP!
      * @param mn the target as MethodNode, mn==null means no target
      */
     public void setMethodTarget(MethodNode mn) {
         this.target = mn;
-        if (mn!=null) {
+        if (mn != null) {
             setType(target.getReturnType());
         } else {
             setType(ClassHelper.OBJECT_TYPE);
         }
     }
 
-    /**
-     * @return the target as method node if set
-     */
-    public MethodNode getMethodTarget() {
-        return target;
-    }
-
     @Override
     public void setSourcePosition(ASTNode node) {
         super.setSourcePosition(node);
@@ -230,4 +228,8 @@ public class MethodCallExpression extends Expression implements MethodCall
{
             method.setSourcePosition(((PropertyExpression) node).getProperty());
         }
     }
+
+    public String toString() {
+        return super.toString() + "[object: " + objectExpression + " method: " + method +
" arguments: " + arguments + "]";
+    }
 }


Mime
View raw message