|
@@ -18,7 +18,9 @@ package com.baomidou.mybatisplus.core.toolkit.support;
|
|
|
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
|
|
|
|
|
|
-import java.lang.reflect.Field;
|
|
|
+import java.lang.invoke.MethodHandle;
|
|
|
+import java.lang.invoke.MethodHandles;
|
|
|
+import java.lang.reflect.Executable;
|
|
|
import java.lang.reflect.InvocationHandler;
|
|
|
import java.lang.reflect.Proxy;
|
|
|
|
|
@@ -28,21 +30,6 @@ import java.lang.reflect.Proxy;
|
|
|
* Create by hcl at 2021/5/17
|
|
|
*/
|
|
|
public class IdeaProxyLambdaMeta implements LambdaMeta {
|
|
|
- private static final Field FIELD_MEMBER_NAME;
|
|
|
- private static final Field FIELD_MEMBER_NAME_CLAZZ;
|
|
|
- private static final Field FIELD_MEMBER_NAME_NAME;
|
|
|
-
|
|
|
- static {
|
|
|
- try {
|
|
|
- Class<?> classDirectMethodHandle = Class.forName("java.lang.invoke.DirectMethodHandle");
|
|
|
- FIELD_MEMBER_NAME = ReflectionKit.setAccessible(classDirectMethodHandle.getDeclaredField("member"));
|
|
|
- Class<?> classMemberName = Class.forName("java.lang.invoke.MemberName");
|
|
|
- FIELD_MEMBER_NAME_CLAZZ = ReflectionKit.setAccessible(classMemberName.getDeclaredField("clazz"));
|
|
|
- FIELD_MEMBER_NAME_NAME = ReflectionKit.setAccessible(classMemberName.getDeclaredField("name"));
|
|
|
- } catch (ClassNotFoundException | NoSuchFieldException e) {
|
|
|
- throw new MybatisPlusException(e);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
private final Class<?> clazz;
|
|
|
private final String name;
|
|
@@ -50,10 +37,10 @@ public class IdeaProxyLambdaMeta implements LambdaMeta {
|
|
|
public IdeaProxyLambdaMeta(Proxy func) {
|
|
|
InvocationHandler handler = Proxy.getInvocationHandler(func);
|
|
|
try {
|
|
|
- Object dmh = ReflectionKit.setAccessible(handler.getClass().getDeclaredField("val$target")).get(handler);
|
|
|
- Object member = FIELD_MEMBER_NAME.get(dmh);
|
|
|
- clazz = (Class<?>) FIELD_MEMBER_NAME_CLAZZ.get(member);
|
|
|
- name = (String) FIELD_MEMBER_NAME_NAME.get(member);
|
|
|
+ MethodHandle dmh = (MethodHandle) ReflectionKit.setAccessible(handler.getClass().getDeclaredField("val$target")).get(handler);
|
|
|
+ Executable executable = MethodHandles.reflectAs(Executable.class, dmh);
|
|
|
+ clazz = executable.getDeclaringClass();
|
|
|
+ name = executable.getName();
|
|
|
} catch (IllegalAccessException | NoSuchFieldException e) {
|
|
|
throw new MybatisPlusException(e);
|
|
|
}
|