问题描述
我有以下代码段,我使用ASM进行了分析
I have the following code snippet, which I analyze with ASM
try{
} catch (@TypeAnno7 RuntimeException re){
}
我找不到为Annotation调用的正确方法.我认为 MethodVisitor.visitTryCatchAnnotation 可以解决问题,但不会被调用.
I can't find the right method that gets called for the Annotation. I thought MethodVisitor.visitTryCatchAnnotation would do the trick, but it doesn't get called.
那么:使用的正确方法是什么?所述方法调用哪种代码?
So: what is the correct method used? And for what kind of code does the method mentioned get called?
推荐答案
除非try主体包含一些代码,否则Java编译器不会为try/catch生成任何字节码(否则,catch块将永远无法运行,因此一种消除无效代码的形式),您可以使用javac -p
进行验证.将一些代码添加到try主体中,然后应调用visitTryCatchAnnotation.
The Java compiler does not generate any bytecode for a try/catch unless the try body contains some code (otherwise, the catch block could never actually run, so it's a form of dead code elimination), which you can verify using javac -p
. Add some code to the try body, and then the visitTryCatchAnnotation should be called.
这篇关于什么是ASM Visitor方法在catch上被要求进行类型注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!