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 2021/06/25 02:42:27 UTC
[groovy] branch danielsun/tweak-build updated: Trivial refactoring:
move `isSealed` to `ReflectionUtils`
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch danielsun/tweak-build
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/danielsun/tweak-build by this push:
new d676d00 Trivial refactoring: move `isSealed` to `ReflectionUtils`
d676d00 is described below
commit d676d0066c85ba6a38d61ded3740367543600e87
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Jun 25 10:41:50 2021 +0800
Trivial refactoring: move `isSealed` to `ReflectionUtils`
---
.../groovy/reflection/ReflectionUtils.java | 24 +++++++++++++++++++++
.../groovy/runtime/ProxyGeneratorAdapter.java | 25 +---------------------
2 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java b/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
index e0b5273..bdb23c2 100644
--- a/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
+++ b/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
@@ -22,6 +22,9 @@ import org.codehaus.groovy.classgen.asm.util.TypeUtil;
import org.codehaus.groovy.vmplugin.VMPlugin;
import org.codehaus.groovy.vmplugin.VMPluginFactory;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
@@ -235,6 +238,17 @@ public class ReflectionUtils {
}
}
+ public static boolean isSealed(Class<?> clazz) {
+ if (null == IS_SEALED_METHODHANDLE) return false;
+
+ boolean sealed = false;
+ try {
+ sealed = (boolean) IS_SEALED_METHODHANDLE.bindTo(clazz).invokeExact();
+ } catch (Throwable ignored) {
+ }
+ return sealed;
+ }
+
private static boolean classShouldBeIgnored(final Class c, final Collection<String> extraIgnoredPackages) {
return (c != null
&& (c.isSynthetic()
@@ -249,4 +263,14 @@ public class ReflectionUtils {
return super.getClassContext();
}
}
+
+ private static final MethodHandle IS_SEALED_METHODHANDLE;
+ static {
+ MethodHandle mh = null;
+ try {
+ mh = MethodHandles.lookup().findVirtual(Class.class, "isSealed", MethodType.methodType(boolean.class, new Class[0]));
+ } catch (NoSuchMethodException | IllegalAccessException ignored) {
+ }
+ IS_SEALED_METHODHANDLE = mh;
+ }
}
diff --git a/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java b/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
index 7ea2a9c..6ad943e 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
@@ -42,9 +42,6 @@ import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
import java.lang.annotation.Annotation;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -63,6 +60,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
+import static org.codehaus.groovy.reflection.ReflectionUtils.isSealed;
import static org.objectweb.asm.Opcodes.AASTORE;
import static org.objectweb.asm.Opcodes.ACC_ABSTRACT;
import static org.objectweb.asm.Opcodes.ACC_FINAL;
@@ -943,25 +941,4 @@ public class ProxyGeneratorAdapter extends ClassVisitor {
return value;
}
}
-
- private static final MethodHandle IS_SEALED_METHODHANDLE;
- static {
- MethodHandle mh = null;
- try {
- mh = MethodHandles.lookup().findVirtual(Class.class, "isSealed", MethodType.methodType(boolean.class, new Class[0]));
- } catch (NoSuchMethodException | IllegalAccessException ignored) {
- }
- IS_SEALED_METHODHANDLE = mh;
- }
-
- private static boolean isSealed(Class<?> clazz) {
- if (null == IS_SEALED_METHODHANDLE) return false;
-
- boolean sealed = false;
- try {
- sealed = (boolean) IS_SEALED_METHODHANDLE.bindTo(clazz).invokeExact();
- } catch (Throwable ignored) {
- }
- return sealed;
- }
}