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

This page was automatically generated by Maven