Java ASM 4.0,类节点中的重命名方法
好吧,那么。我试图在ASM4.0中重命名类节点中的方法 这是我的重命名类:Java ASM 4.0,类节点中的重命名方法,java,methods,bytecode,java-bytecode-asm,Java,Methods,Bytecode,Java Bytecode Asm,好吧,那么。我试图在ASM4.0中重命名类节点中的方法 这是我的重命名类: public class RenameVisitor extends ClassVisitor { private String newName,oldName; public RenameVisitor(String newName,String oldName){ super(Opcodes.ASM4); this.newName = newName; this.oldName = old
public class RenameVisitor extends ClassVisitor {
private String newName,oldName;
public RenameVisitor(String newName,String oldName){
super(Opcodes.ASM4);
this.newName = newName;
this.oldName = oldName;
}
@Override
public MethodVisitor visitMethod(int access, String name,
String desc, String signature, String[] exceptions) {
if(name.contains(oldName)){
System.out.println(newName);
return cv.visitMethod(access,newName,desc,signature,exceptions);
}
return cv.visitMethod(access, name, desc, signature, exceptions);
}
}
现在,我如何使用它来重命名类节点中的方法?
我尝试了以下几种方法:
ClassVisitor rv = new RenameVisitor(mn.name,"_"+mn.name);//mn is the method node being tested
ClassReader cr = new ClassReader(node.name);
cr.accept(rv,0);
它总是抛出一个找不到类的错误。我需要做什么才能让它读取类节点?这将是一个很好的起点。您没有提供字节码的具体来源,但是如果您想使用具有类名的ClassReader构造函数,则类应该存在于类路径中(因此出现“找不到类”错误)