1 32 package net.sf.retrotranslator.transformer; 33 34 import net.sf.retrotranslator.runtime.asm.*; 35 import net.sf.retrotranslator.runtime.impl.EmptyVisitor; 36 37 40 class MemberFinder extends EmptyVisitor { 41 42 private final ClassReaderFactory factory; 43 private final boolean method; 44 private final boolean stat; 45 private final String name; 46 private final String desc; 47 48 private String superName; 49 private String [] interfaces; 50 private int found; 51 52 public MemberFinder(ClassReaderFactory factory, boolean method, boolean stat, String name, String desc) { 53 this.factory = factory; 54 this.method = method; 55 this.stat = stat; 56 this.name = name; 57 this.desc = desc; 58 } 59 60 public int findIn(String className, String location) throws ClassNotFoundException { 61 if (className == null) return 0; 62 try { 63 factory.getClassReader(className).accept(this, true); 64 } catch (ClassNotFoundException e) { 65 if (location == null) throw e; 66 throw new ClassNotFoundException (e.getMessage() + ", location: " + location, e); 67 } 68 if (found > 0) return found; 69 String superClassName = superName; 70 for (String interfaceName : interfaces) { 71 if (findIn(interfaceName, className) > 0) return found; 72 } 73 return findIn(superClassName, className); 74 } 75 76 public void visit(int version, int access, String name, String signature, String superName, String [] interfaces) { 77 this.superName = superName; 78 this.interfaces = interfaces; 79 } 80 81 public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { 82 if (!method) check(access, name, desc); 83 return null; 84 } 85 86 public MethodVisitor visitMethod(int access, String name, String desc, String signature, String [] exceptions) { 87 if (method) check(access, name, desc); 88 return null; 89 } 90 91 private void check(int access, String name, String desc) { 92 if (name.equals(this.name) && desc.equals(this.desc) && stat == ((access & Opcodes.ACC_STATIC) != 0)) found++; 93 } 94 } 95 | Popular Tags |