我正在尝试检查来自 Java 的一些 CGLib 代理 Groovy 类上的 Groovy 生成方法,以了解方法的返回和参数类型。例如,考虑这个 Groovy 类:
class Person {
String name
}
Groovy 为 name 属性生成getName()和setName()方法。getName()大概返回 aString并且setName()大概需要 a String。
但是当通过 CGLib 代理这个类并拦截对getName使用 CGLib 的MethodInterceptor的调用时,method.getName()返回getMetaClass和method.getReturnType()返回groovy.lang.MetaClass。
有没有办法从MethodInterceptor中学习实际的方法名称和返回类型?
编辑:这是拦截 Person.getName() 调用时的调用堆栈:
ExplicitMappingInterceptor.intercept(Object, Method, Object[], MethodProxy) line: 42
GroovyMMTester$A$$EnhancerByCGLIB$$915b5b4.getMetaClass() line: not available
CallSiteArray.createPogoSite(CallSite, Object, Object[]) line: 144
CallSiteArray.createCallSite(CallSite, Object, Object[]) line: 161
CallSiteArray.defaultCall(CallSite, Object, Object[]) line: 45
AbstractCallSite.call(Object, Object[]) line: 108
AbstractCallSite.call(Object) line: 112
GroovyMMTester$Map.configure() line: 18 <-- Person.getName() call is in here, but doesn't show