【发布时间】:2015-10-26 20:20:05
【问题描述】:
我是 ASM 的新手。我有一个类文件,其中有方法的运行时可见注释。我想解析这个类文件并根据特定标准选择注释。我查看了 ASM 的文档并尝试使用 visibleAnnotation。我似乎无法打印在我的类文件中可以看到的方法注释列表。
我的代码是
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Iterator;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.ClassReader;
public class ByteCodeParser {
public static void main(String[] args) throws Exception{
InputStream in=new FileInputStream("sample.class");
ClassReader cr=new ClassReader(in);
ClassNode classNode=new ClassNode();
//ClassNode is a ClassVisitor
cr.accept(classNode, 0);
//
Iterator<MethodNode> i = classNode.methods.iterator();
while(i.hasNext()){
MethodNode mn = i.next();
System.out.println(mn.name+ "" + mn.desc);
System.out.println(mn.visibleAnnotations);
}
}
}
输出是:
<clinit>()V
null
<init>()V
null
MyRandomFunction1()V
[org.objectweb.asm.tree.AnnotationNode@5674cd4d]
MyRandomFunction2()V
[org.objectweb.asm.tree.AnnotationNode@63961c42]
我的 RandomFunction 1 和 2 有注释,但我似乎无法理解 [org.objectweb.asm.tree.AnnotationNode@5674cd4d]。
【问题讨论】: