您在Byte Buddy中发现了一个盲点,我想修复一会儿。早期版本的Byte
Buddy不允许定义注释,但是当它允许时,该API已经被广泛使用,以至于我无法更改它,并且在实现中也需要一些位。
如果您愿意为添加合成方法付出最小的代价,则可以改类为基础:
new ByteBuddy().rebase(ClassThatNeedsToBeAnnotated.class)
这样做,您可以仅使用当前的API并添加的实现
SuperMethodCall。这将在重新基准化中调用完全相同的方法。
此处跟踪了Byte Buddy的增强功能:https://github.com/raphw/byte-
buddy/issues/627
更新 :在即将发布的字节好友1.10.0中,可以通过以下方式实现:
new ByteBuddy() .redefine(ClassThatNeedsToBeAnnotated.class) .visit(new MemberAttributeExtension.ForMethod() .annotateMethod(someAnnotation) .on(matcher)) .make();
注释实例可以通过以下方式获取:
AnnotationDescription.Latent.Builder.ofType(AnnotationClass.class).build()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)