Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X f5c50875b -> 2f9dcb49a


Minor refactoring: extract common method of MetaMethodSite subclasses

(cherry picked from commit af98abb)


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

Branch: refs/heads/GROOVY_2_5_X
Commit: 2f9dcb49a6de5ab662a085658d92c68b6b842416
Parents: f5c5087
Author: sunlan <sun...@apache.org>
Authored: Mon Mar 12 08:27:26 2018 +0800
Committer: sunlan <sun...@apache.org>
Committed: Mon Mar 12 09:16:14 2018 +0800

----------------------------------------------------------------------
 .../callsite/PlainObjectMetaMethodSite.java     | 53 ++++++++++++++++++++
 .../runtime/callsite/PogoMetaMethodSite.java    | 36 ++-----------
 .../runtime/callsite/PojoMetaMethodSite.java    | 36 ++-----------
 3 files changed, 61 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/2f9dcb49/src/main/java/org/codehaus/groovy/runtime/callsite/PlainObjectMetaMethodSite.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/runtime/callsite/PlainObjectMetaMethodSite.java
 
b/src/main/java/org/codehaus/groovy/runtime/callsite/PlainObjectMetaMethodSite.java
new file mode 100644
index 0000000..b396e26
--- /dev/null
+++ 
b/src/main/java/org/codehaus/groovy/runtime/callsite/PlainObjectMetaMethodSite.java
@@ -0,0 +1,53 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.codehaus.groovy.runtime.callsite;
+
+import groovy.lang.GroovyRuntimeException;
+import groovy.lang.MetaClass;
+import groovy.lang.MetaMethod;
+import org.codehaus.groovy.runtime.ScriptBytecodeAdapter;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Plain ordinary object call site
+ *   meta class - cached
+ *   method - cached
+ *
+ */
+public abstract class PlainObjectMetaMethodSite extends MetaMethodSite {
+    public PlainObjectMetaMethodSite(CallSite site, MetaClass metaClass, 
MetaMethod metaMethod, Class[] params) {
+        super(site, metaClass, metaMethod, params);
+    }
+
+    protected static Object doInvoke(Object receiver, Object[] args, Method 
reflect) throws Throwable {
+        try {
+            return reflect.invoke(receiver, args);
+        } catch (InvocationTargetException e) {
+            Throwable cause = e.getCause();
+            if (cause instanceof GroovyRuntimeException) {
+                throw ScriptBytecodeAdapter.unwrap ((GroovyRuntimeException) 
cause);
+            } else {
+                throw cause;
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/2f9dcb49/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite.java 
b/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite.java
index 243e62d..5240f34 100644
--- a/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite.java
+++ b/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite.java
@@ -27,7 +27,6 @@ import org.codehaus.groovy.runtime.GroovyCategorySupport;
 import org.codehaus.groovy.runtime.MetaClassHelper;
 import org.codehaus.groovy.runtime.ScriptBytecodeAdapter;
 
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 /**
@@ -35,7 +34,7 @@ import java.lang.reflect.Method;
  *   meta class - cached
  *   method - cached
 */
-public class PogoMetaMethodSite extends MetaMethodSite {
+public class PogoMetaMethodSite extends PlainObjectMetaMethodSite {
     private final int version;
     private final boolean skipVersionCheck;
     public PogoMetaMethodSite(CallSite site, MetaClassImpl metaClass, 
MetaMethod metaMethod, Class params[]) {
@@ -165,16 +164,7 @@ public class PogoMetaMethodSite extends MetaMethodSite {
         public Object invoke(Object receiver, Object[] args) throws Throwable {
             MetaClassHelper.unwrap(args);
             args = metaMethod.coerceArgumentsToClasses(args);
-            try {
-                return reflect.invoke(receiver, args);
-            } catch (InvocationTargetException e) {
-                Throwable cause = e.getCause();
-                if (cause instanceof GroovyRuntimeException) {
-                    throw ScriptBytecodeAdapter.unwrap 
((GroovyRuntimeException) cause);
-                } else {
-                    throw cause;
-                }
-            }
+            return doInvoke(receiver, args, reflect);
         }
     }
 
@@ -186,16 +176,7 @@ public class PogoMetaMethodSite extends MetaMethodSite {
 
         public final Object invoke(Object receiver, Object[] args) throws 
Throwable {
             args = metaMethod.coerceArgumentsToClasses(args);
-            try {
-                return reflect.invoke(receiver, args);
-            } catch (InvocationTargetException e) {
-                Throwable cause = e.getCause();
-                if (cause instanceof GroovyRuntimeException) {
-                    throw ScriptBytecodeAdapter.unwrap 
((GroovyRuntimeException) cause);
-                } else {
-                    throw cause;
-                }
-            }
+            return doInvoke(receiver, args, reflect);
         }
     }
 
@@ -206,16 +187,7 @@ public class PogoMetaMethodSite extends MetaMethodSite {
         }
 
         public final Object invoke(Object receiver, Object[] args) throws 
Throwable {
-            try {
-                return reflect.invoke(receiver, args);
-            } catch (InvocationTargetException e) {
-                Throwable cause = e.getCause();
-                if (cause instanceof GroovyRuntimeException) {
-                    throw ScriptBytecodeAdapter.unwrap 
((GroovyRuntimeException) cause);
-                } else {
-                    throw cause;
-                }
-            }
+            return doInvoke(receiver, args, reflect);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/2f9dcb49/src/main/java/org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite.java 
b/src/main/java/org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite.java
index 7bbd903..fb52e1f 100644
--- a/src/main/java/org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite.java
+++ b/src/main/java/org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite.java
@@ -27,7 +27,6 @@ import org.codehaus.groovy.runtime.MetaClassHelper;
 import org.codehaus.groovy.runtime.NullObject;
 import org.codehaus.groovy.runtime.ScriptBytecodeAdapter;
 
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 /**
@@ -37,7 +36,7 @@ import java.lang.reflect.Method;
  *
  * @author Alex Tkachman
 */
-public class PojoMetaMethodSite extends MetaMethodSite {
+public class PojoMetaMethodSite extends PlainObjectMetaMethodSite {
 
     protected final int version;
 
@@ -188,16 +187,7 @@ public class PojoMetaMethodSite extends MetaMethodSite {
         public Object invoke(Object receiver, Object[] args) throws Throwable {
             MetaClassHelper.unwrap(args);
             args = metaMethod.coerceArgumentsToClasses(args);
-            try {
-                return reflect.invoke(receiver, args);
-            } catch (InvocationTargetException e) {
-                Throwable cause = e.getCause();
-                if (cause instanceof GroovyRuntimeException) {
-                    throw ScriptBytecodeAdapter.unwrap 
((GroovyRuntimeException) cause);
-                } else {
-                    throw cause;
-                }
-            }
+            return doInvoke(receiver, args, reflect);
         }
     }
 
@@ -209,16 +199,7 @@ public class PojoMetaMethodSite extends MetaMethodSite {
 
         public final Object invoke(Object receiver, Object[] args) throws 
Throwable {
             args = metaMethod.coerceArgumentsToClasses(args);
-            try {
-                return reflect.invoke(receiver, args);
-            } catch (InvocationTargetException e) {
-                Throwable cause = e.getCause();
-                if (cause instanceof GroovyRuntimeException) {
-                    throw ScriptBytecodeAdapter.unwrap 
((GroovyRuntimeException) cause);
-                } else {
-                    throw cause;
-                }
-            }
+            return doInvoke(receiver, args, reflect);
         }
     }
 
@@ -229,16 +210,7 @@ public class PojoMetaMethodSite extends MetaMethodSite {
         }
 
         public final Object invoke(Object receiver, Object[] args) throws 
Throwable {
-            try {
-                return reflect.invoke(receiver, args);
-            } catch (InvocationTargetException e) {
-                Throwable cause = e.getCause();
-                if (cause instanceof GroovyRuntimeException) {
-                    throw ScriptBytecodeAdapter.unwrap 
((GroovyRuntimeException) cause);
-                } else {
-                    throw cause;
-                }
-            }
+            return doInvoke(receiver, args, reflect);
         }
     }
 

Reply via email to