groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] branch master updated: Trivial refactoring: rename method name and extract common checks
Date Sat, 07 Dec 2019 18:56:07 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan 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 20a4daa  Trivial refactoring: rename method name and extract common checks
20a4daa is described below

commit 20a4daad7f908066a6dfa104d613d11345e0aa58
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Sun Dec 8 02:55:45 2019 +0800

    Trivial refactoring: rename method name and extract common checks
---
 .../groovy/classgen/asm/sc/StaticTypesLambdaWriter.java   | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
index 4f7f5d9..a80c5c8 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
@@ -136,8 +136,9 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
                 addDeserializeLambdaMethod();
             }
 
-            newGroovyLambdaWrapperAndLoad(lambdaWrapperClassNode, syntheticLambdaMethodNode,
expression);
-            loadEnclosingClassInstance(syntheticLambdaMethodNode);
+            boolean accessingInstanceMembers = isAccessingInstanceMembersOfEnclosingClass(syntheticLambdaMethodNode);
+            newGroovyLambdaWrapperAndLoad(lambdaWrapperClassNode, expression, accessingInstanceMembers);
+            loadEnclosingClassInstance(accessingInstanceMembers);
         }
 
         MethodVisitor mv = controller.getMethodVisitor();
@@ -161,12 +162,12 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements
AbstractFun
         return new Parameter[]{new Parameter(ClassHelper.SERIALIZEDLAMBDA_TYPE, SERIALIZED_LAMBDA_PARAM_NAME)};
     }
 
-    private void loadEnclosingClassInstance(MethodNode syntheticLambdaMethodNode) {
+    private void loadEnclosingClassInstance(boolean accessingInstanceMembers) {
         MethodVisitor mv = controller.getMethodVisitor();
         OperandStack operandStack = controller.getOperandStack();
         CompileStack compileStack = controller.getCompileStack();
 
-        if (controller.isStaticMethod() || compileStack.isInSpecialConstructorCall() || !isAccessingInstanceMembers(syntheticLambdaMethodNode))
{
+        if (controller.isStaticMethod() || compileStack.isInSpecialConstructorCall() || !accessingInstanceMembers)
{
             operandStack.pushConstant(ConstantExpression.NULL);
         } else {
             mv.visitVarInsn(ALOAD, 0);
@@ -174,7 +175,7 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
         }
     }
 
-    private boolean isAccessingInstanceMembers(MethodNode syntheticLambdaMethodNode) {
+    private boolean isAccessingInstanceMembersOfEnclosingClass(MethodNode syntheticLambdaMethodNode)
{
         ObjectHolder<Boolean> objectHolder = new ObjectHolder<>(false);
         ClassCodeVisitorSupport classCodeVisitorSupport = new ClassCodeVisitorSupport() {
             @Override
@@ -207,13 +208,13 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements
AbstractFun
         return objectHolder.getObject();
     }
 
-    private void newGroovyLambdaWrapperAndLoad(ClassNode lambdaWrapperClassNode, MethodNode
syntheticLambdaMethodNode, LambdaExpression expression) {
+    private void newGroovyLambdaWrapperAndLoad(ClassNode lambdaWrapperClassNode, LambdaExpression
expression, boolean accessingInstanceMembers) {
         MethodVisitor mv = controller.getMethodVisitor();
         String lambdaWrapperClassInternalName = BytecodeHelper.getClassInternalName(lambdaWrapperClassNode);
         mv.visitTypeInsn(NEW, lambdaWrapperClassInternalName);
         mv.visitInsn(DUP);
 
-        loadEnclosingClassInstance(syntheticLambdaMethodNode);
+        loadEnclosingClassInstance(accessingInstanceMembers);
         controller.getOperandStack().dup();
 
         loadSharedVariables(expression);


Mime
View raw message