1 16 package net.sf.cglib.transform; 17 18 19 import java.io.*; 20 21 import org.apache.tools.ant.BuildException; 22 23 import org.objectweb.asm.ClassReader; 24 25 import org.objectweb.asm.ClassVisitor; 26 27 import org.objectweb.asm.CodeVisitor; 28 29 import org.objectweb.asm.Attribute; 30 31 32 public class DumpFieldsTask extends AbstractProcessTask { 33 34 private File outfile; 35 36 private PrintStream out; 37 38 39 40 public void setOutputFile(File outfile) { 41 42 this.outfile = outfile; 43 44 } 45 46 47 48 public void execute() throws BuildException { 49 50 try { 51 52 out = new PrintStream(new FileOutputStream(outfile)); 53 try{ 54 55 super.execute(); 56 57 }finally{ 58 out.close(); 59 } 60 61 } catch (IOException e) { 62 63 throw new BuildException(e); 64 65 } 66 67 } 68 69 70 71 protected void processFile(File file) throws Exception { 72 73 InputStream in = new BufferedInputStream(new FileInputStream(file)); 74 75 ClassReader r = new ClassReader(in); 76 77 r.accept(new ClassVisitor() { 78 79 private String className; 80 81 82 83 public void visitEnd() { } 84 85 public void visitInnerClass(String name, String outerName, String innerName, int access) { } 86 87 public void visitAttribute(Attribute attrs) { } 88 89 90 91 public CodeVisitor visitMethod(int access, String name, String desc, String [] exceptions, Attribute attrs) { 92 93 return null; 94 95 } 96 97 98 99 public void visit(int version, int access, String name, String superName, String [] interfaces, String sourceFile) { 100 101 className = name.replace('/', '.'); 102 103 } 104 105 106 107 public void visitField(int access, String name, String desc, Object value, Attribute attrs) { 108 109 out.println("class=" + className + ", field=" + name); 110 111 } 112 113 }, true); 114 115 } 116 117 } 118 119 | Popular Tags |