[英]ByteBuddy intercept the calls toward specific class instances inside the bytecode of a method
I have a class A with a method m() and a class B with a method n(). 我有一个带有方法m()的类A和一个带有方法n()的类B. In AI have a field b of type B. In m() there is at some point a call to bn().
在AI中有一个类型为B的字段b。在m()中,某些时候会调用bn()。 I need to change the code of A with ByteBuddy in order to do some action before and after the bn() call.
我需要使用ByteBuddy更改A的代码,以便在bn()调用之前和之后执行一些操作。 I need some advice/tips/hint to attack the problem.
我需要一些建议/提示/提示来解决问题。
Thanks in advance, 提前致谢,
Radu 拉杜
You can only do this in Byte Buddy by writing custom byte code using the underlying ASM API. 您只能通过使用基础ASM API编写自定义字节代码在Byte Buddy中执行此操作。 Byte Buddy does not offer any high-level constructs to alter any code within a method.
Byte Buddy不提供任何高级构造来更改方法中的任何代码。
The API is exposed by registering an AsmVisitorWrapper. 通过注册AsmVisitorWrapper公开API。
Alternatively, you could create a subclass of Bn() where you add this interception logic and set it as the field of A. This would however affect all invokations via A. 或者,您可以创建Bn()的子类,您可以在其中添加此拦截逻辑并将其设置为A的字段。但是这将通过A影响所有调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.