groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 01/08: Fix the hardcoded caller class
Date Sat, 02 Nov 2019 21:46:58 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit cdb3deb640c52611c91eafb343c255dd7ded5cf5
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Sun Nov 3 00:42:32 2019 +0800

    Fix the hardcoded caller class
    
    (cherry picked from commit b84e9af0eb488dba41501c21c42fcf9fdc28c78a)
---
 src/main/java/groovy/lang/MetaClassImpl.java                |  7 +++----
 src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java    | 10 ++++++++++
 src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java    |  5 +++++
 src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java |  2 +-
 src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java    |  5 +++++
 5 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index 1443797..e1b00eb 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -80,7 +80,6 @@ import org.codehaus.groovy.util.SingleKeyHashMap;
 import org.codehaus.groovy.vmplugin.VMPluginFactory;
 
 import javax.annotation.Nullable;
-
 import java.beans.BeanInfo;
 import java.beans.EventSetDescriptor;
 import java.beans.IntrospectionException;
@@ -1263,7 +1262,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
         }
 
         if (method != null) {
-            MetaMethod transformedMetaMethod = VMPluginFactory.getPlugin().transformMetaMethod(this,
method, MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+            MetaMethod transformedMetaMethod = VMPluginFactory.getPlugin().transformMetaMethod(this,
method, MetaClassHelper.convertToTypeArray(arguments));
             return transformedMetaMethod.doMethodInvoke(object, arguments);
         } else {
             return invokePropertyOrMissing(object, methodName, originalArguments, fromInsideClass,
isCallToSuper);
@@ -1924,7 +1923,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
             //----------------------------------------------------------------------
             // executing the getter method
             //----------------------------------------------------------------------
-            MetaMethod transformedMetaMethod = VMPluginFactory.getPlugin().transformMetaMethod(this,
method, MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+            MetaMethod transformedMetaMethod = VMPluginFactory.getPlugin().transformMetaMethod(this,
method, MetaClassHelper.convertToTypeArray(arguments));
             return transformedMetaMethod.doMethodInvoke(object, arguments);
         }
 
@@ -2824,7 +2823,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
                 arguments[1] = newValue;
             }
 
-            MetaMethod transformedMetaMethod = VMPluginFactory.getPlugin().transformMetaMethod(this,
method, MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+            MetaMethod transformedMetaMethod = VMPluginFactory.getPlugin().transformMetaMethod(this,
method, MetaClassHelper.convertToTypeArray(arguments));
             transformedMetaMethod.doMethodInvoke(object, arguments);
             return;
         }
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
index c0cd3bd..b5118d3 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
@@ -103,4 +103,14 @@ public interface VMPlugin {
      * @return the transformed meta method
      */
     MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[]
params, Class<?> caller);
+
+    /**
+     * transform meta method.
+     *
+     * @param metaClass meta class
+     * @param metaMethod the original meta method
+     * @param params parameter types
+     * @return the transformed meta method
+     */
+    MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[]
params);
 }
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
index 1ab516b..ff52fb8 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -591,6 +591,11 @@ public class Java5 implements VMPlugin {
         return metaMethod;
     }
 
+    @Override
+    public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[]
params) {
+        return metaMethod;
+    }
+
     private static final Permission ACCESS_PERMISSION = new ReflectPermission("suppressAccessChecks");
 }
 
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java b/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
index c686a78..7872c67 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
@@ -634,7 +634,7 @@ public abstract class Selector {
             if (metaMethod instanceof CachedMethod) {
                 if (LOG_ENABLED) LOG.info("meta method is CachedMethod instance");
                 CachedMethod cm = (CachedMethod) metaMethod;
-                cm = (CachedMethod) VMPluginFactory.getPlugin().transformMetaMethod(getMetaClass(),
cm, cm.getPT(), Selector.class);
+                cm = (CachedMethod) VMPluginFactory.getPlugin().transformMetaMethod(getMetaClass(),
cm, cm.getPT());
                 isVargs = cm.isVargsMethod();
                 try {
                     Method m = cm.getCachedMethod();
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
index a1970c9..ab6d335 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
@@ -168,6 +168,11 @@ public class Java9 extends Java8 {
     }
 
     @Override
+    public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[]
params) {
+        return transformMetaMethod(metaClass, metaMethod, params, ReflectionUtils.getCallingClass());
+    }
+
+    @Override
     public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[]
params, Class<?> caller) {
         if (!(metaMethod instanceof CachedMethod)) {
             return metaMethod;


Mime
View raw message