1 9 package de.loskutov.bco.asm; 10 11 import java.util.BitSet ; 12 13 import org.objectweb.asm.Label; 14 import org.objectweb.asm.util.ASMifierClassVisitor; 15 import org.objectweb.asm.util.ASMifierMethodVisitor; 16 17 import de.loskutov.bco.preferences.BCOConstants; 18 19 22 public class CommentedASMifierClassVisitor extends ASMifierClassVisitor { 23 24 protected BitSet modes; 25 protected boolean raw; 26 27 protected ASMifierMethodVisitor createASMifierMethodVisitor() { 28 return new ASMifierMethodVisitor() { 29 30 public void visitFrame(final int type, final int nLocal, 31 final Object [] local, final int nStack, final Object [] stack) { 32 if (showStackMap) { 33 super.visitFrame(type, nLocal, local, nStack, stack); 34 } 35 } 36 37 public void visitLineNumber(int line, Label start) { 38 if (showLines) { 39 super.visitLineNumber(line, start); 40 } 41 } 42 43 public void visitLocalVariable(String name, String desc, 44 String signature, Label start, Label end, int index) { 45 if (showLocals) { 46 super.visitLocalVariable( 47 name, desc, signature, start, end, index); 48 } 49 } 50 51 public void visitMaxs(int maxStack, int maxLocals) { 52 if (showLocals) { 53 super.visitMaxs(maxStack, maxLocals); 54 } 55 } 56 57 }; 58 } 59 60 protected boolean showLines; 61 protected boolean showLocals; 62 protected boolean showStackMap; 63 64 public CommentedASMifierClassVisitor(final BitSet modes) { 65 super(null); 66 this.modes = modes; 67 raw = !modes.get(BCOConstants.F_SHOW_RAW_BYTECODE); 68 showLines = modes.get(BCOConstants.F_SHOW_LINE_INFO); 69 showLocals = modes.get(BCOConstants.F_SHOW_VARIABLES); 70 showStackMap = modes.get(BCOConstants.F_SHOW_STACKMAP); 71 } 72 73 public void visitEnd() { 74 text.add("cw.visitEnd();\n\n"); 75 text.add("return cw.toByteArray();\n"); 76 text.add("}\n"); 77 text.add("}\n"); 78 } 79 } | Popular Tags |