1 2 package SOFA.Tools.Resolver; 3 4 import org.objectweb.asm.ClassReader; 5 import org.objectweb.asm.ClassVisitor; 6 import org.objectweb.asm.CodeVisitor; 7 8 12 public class ClassInfo { 13 14 private String name; 15 16 public ClassInfo(String fname) throws java.io.IOException { 17 name = null; 18 java.io.FileInputStream is = new java.io.FileInputStream (fname); 19 ClassReader cr = new ClassReader(is); 20 ClassVisitor cv = new ClassInfoVisitor(this); 21 cr.accept(cv, false); 22 } 23 24 public String className() { 25 return name; 26 } 27 28 void className(String name) { 29 this.name = name; 30 } 31 32 public static void main(String [] argv) throws Exception { 33 ClassInfo info = new ClassInfo(argv[0]); 34 System.out.println("Class name: "+info.className()); 35 } 36 } 37 38 class ClassInfoVisitor implements ClassVisitor { 39 private ClassInfo info; 40 public ClassInfoVisitor(ClassInfo info) { 41 this.info = info; 42 } 43 44 public void visit(final int access, final String name, final String superName, final String [] interfaces, final String sourceFile) { 45 info.className(name); 46 } 47 public void visitField(final int access, final String name, final String desc, final Object value) {} 48 public CodeVisitor visitMethod(final int access, final String name, final String desc, final String [] exceptions) { 49 return null; 50 } 51 public void visitEnd() {} 52 public void visitInnerClass(String name, String outerName, String innerName, int access) {} 53 } 54 | Popular Tags |