You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/03/12 00:33:09 UTC
groovy git commit: Minor refactoring: extract common method of
MetaMethodSite subclasses
Repository: groovy
Updated Branches:
refs/heads/master b3e042191 -> af98abb4d
Minor refactoring: extract common method of MetaMethodSite subclasses
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/af98abb4
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/af98abb4
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/af98abb4
Branch: refs/heads/master
Commit: af98abb4de171525214df1392dd5057a7397b041
Parents: b3e0421
Author: sunlan <su...@apache.org>
Authored: Mon Mar 12 08:27:26 2018 +0800
Committer: sunlan <su...@apache.org>
Committed: Mon Mar 12 08:27:26 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/af98abb4/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/af98abb4/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/af98abb4/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);
}
}