开发者

How to get method signature with ObjectWeb ASM?

Purpose: Obtain the public method signature(return value,parameter,method name) from java bytecode files.

I am using the ObjectWeb ASM framewor开发者_JAVA百科k.

Problem: I scanned through the API specification of ASM and tried several examples, but I still have no idea about how to get the signature. The MethodNode class has a signature field, but the value is null.


You can try something like this:

ClassReader cr = new ClassReader(is);
cr.accept(new EmptyVisitor() {
  public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if((Opcodes.ACC_PUBLIC & access)>0) {
      System.err.println("method name: " + name);
      System.err.println("return type: " + Type.getReturnType(desc));
      System.err.println("argument types: " + Arrays.toString(Type.getArgumentTypes(desc)));
    }
    return super.visitMethod(access, name, desc, signature, exceptions);
  }
}, 0);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜