You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2019/12/30 21:36:32 UTC

[groovy] branch GROOVY_2_4_X updated: remove repeat fields, set source position, and other minor edits

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/GROOVY_2_4_X by this push:
     new cb15ab5  remove repeat fields, set source position, and other minor edits
cb15ab5 is described below

commit cb15ab57ecd56d8fecd9b5fcbf93fac069ac2a68
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Dec 30 15:17:07 2019 -0600

    remove repeat fields, set source position, and other minor edits
---
 .../asm/sc/StaticPropertyAccessHelper.java         | 72 ++++++++++------------
 1 file changed, 32 insertions(+), 40 deletions(-)

diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticPropertyAccessHelper.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticPropertyAccessHelper.java
index 6027a0c..72499b5 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticPropertyAccessHelper.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticPropertyAccessHelper.java
@@ -30,63 +30,57 @@ import org.codehaus.groovy.transform.sc.TemporaryVariableExpression;
 import java.util.Arrays;
 
 /**
- * Contains helper methods aimed at facilitating the generation of statically compiled bytecode for property access.
+ * Facilitates the generation of statically-compiled bytecode for property access.
  *
- * @author Cédric Champeau
  * @since 2.4.0
  */
 public abstract class StaticPropertyAccessHelper {
+
     public static Expression transformToSetterCall(
-            Expression receiver,
-            MethodNode setterMethod,
-            final Expression arguments,
-            boolean implicitThis,
-            boolean safe,
-            boolean spreadSafe,
-            boolean requiresReturnValue,
-            Expression location) {
+            final Expression receiver,
+            final MethodNode setterMethod,
+            final Expression argument,
+            final boolean implicitThis,
+            final boolean safe,
+            final boolean spreadSafe,
+            final boolean requiresReturnValue,
+            final Expression propertyExpression) {
         if (requiresReturnValue) {
-            TemporaryVariableExpression tmp = new TemporaryVariableExpression(arguments);
+            TemporaryVariableExpression tmp = new TemporaryVariableExpression(argument);
             PoppingMethodCallExpression call = new PoppingMethodCallExpression(receiver, setterMethod, tmp);
-            call.setImplicitThis(implicitThis);
             call.setSafe(safe);
             call.setSpreadSafe(spreadSafe);
-            call.setSourcePosition(location);
-            PoppingListOfExpressionsExpression result = new PoppingListOfExpressionsExpression(tmp, call);
-            result.setSourcePosition(location);
-            return result;
-        } else {
-            MethodCallExpression call = new MethodCallExpression(
-                    receiver,
-                    setterMethod.getName(),
-                    arguments
-            );
             call.setImplicitThis(implicitThis);
+            call.setSourcePosition(propertyExpression);
+            PoppingListOfExpressionsExpression list = new PoppingListOfExpressionsExpression(tmp, call);
+            list.setSourcePosition(propertyExpression);
+            return list;
+        } else {
+            MethodCallExpression call = new MethodCallExpression(receiver, setterMethod.getName(), argument);
             call.setSafe(safe);
             call.setSpreadSafe(spreadSafe);
+            call.setImplicitThis(implicitThis);
             call.setMethodTarget(setterMethod);
-            call.setSourcePosition(location);
+            call.setSourcePosition(propertyExpression);
             return call;
         }
     }
 
     private static class PoppingListOfExpressionsExpression extends ListOfExpressionsExpression {
+
         private final TemporaryVariableExpression tmp;
         private final PoppingMethodCallExpression call;
 
         public PoppingListOfExpressionsExpression(final TemporaryVariableExpression tmp, final PoppingMethodCallExpression call) {
-            super(Arrays.asList(
-                    tmp,
-                    call
-            ));
+            super(Arrays.asList(tmp, call));
             this.tmp = tmp;
             this.call = call;
         }
 
         @Override
         public Expression transformExpression(final ExpressionTransformer transformer) {
-            PoppingMethodCallExpression tcall = (PoppingMethodCallExpression) call.transformExpression(transformer);
-            return new PoppingListOfExpressionsExpression(tcall.tmp, tcall);
+            PoppingMethodCallExpression call = (PoppingMethodCallExpression) this.call.transformExpression(transformer);
+            return new PoppingListOfExpressionsExpression(call.tmp, call);
         }
 
         @Override
@@ -99,26 +93,24 @@ public abstract class StaticPropertyAccessHelper {
     }
 
     private static class PoppingMethodCallExpression extends MethodCallExpression {
-        private final Expression receiver;
-        private final MethodNode setter;
+
         private final TemporaryVariableExpression tmp;
 
         public PoppingMethodCallExpression(final Expression receiver, final MethodNode setterMethod, final TemporaryVariableExpression tmp) {
             super(receiver, setterMethod.getName(), tmp);
-            this.receiver = receiver;
-            this.setter = setterMethod;
-            this.tmp = tmp;
             setMethodTarget(setterMethod);
+            this.tmp = tmp;
         }
 
         @Override
         public Expression transformExpression(final ExpressionTransformer transformer) {
-            PoppingMethodCallExpression trn = new PoppingMethodCallExpression(receiver.transformExpression(transformer), setter, (TemporaryVariableExpression) tmp.transformExpression(transformer));
-            trn.copyNodeMetaData(this);
-            trn.setImplicitThis(isImplicitThis());
-            trn.setSafe(isSafe());
-            trn.setSpreadSafe(isSpreadSafe());
-            return trn;
+            PoppingMethodCallExpression call = new PoppingMethodCallExpression(getObjectExpression().transformExpression(transformer), getMethodTarget(), (TemporaryVariableExpression) tmp.transformExpression(transformer));
+            call.copyNodeMetaData(this);
+            call.setSourcePosition(this);
+            call.setSafe(isSafe());
+            call.setSpreadSafe(isSpreadSafe());
+            call.setImplicitThis(isImplicitThis());
+            return call;
         }
 
         @Override