1 30 31 package oracle.toplink.libraries.asm.util.attrs; 32 33 import java.util.Map ; 34 35 import oracle.toplink.libraries.asm.Attribute; 36 import oracle.toplink.libraries.asm.ClassReader; 37 import oracle.toplink.libraries.asm.Label; 38 import oracle.toplink.libraries.asm.attrs.LocalVariableType; 39 import oracle.toplink.libraries.asm.attrs.LocalVariableTypeTableAttribute; 40 41 46 47 public class ASMLocalVariableTypeTableAttribute 48 extends LocalVariableTypeTableAttribute 49 implements ASMifiable 50 { 51 52 protected Attribute read( ClassReader cr, int off, int len, char[] buf, int codeOff, Label[] labels) { 53 LocalVariableTypeTableAttribute attr = ( LocalVariableTypeTableAttribute) super.read(cr, off, len, buf, codeOff, labels); 54 55 ASMLocalVariableTypeTableAttribute res = new ASMLocalVariableTypeTableAttribute(); 56 res.getTypes().addAll( attr.getTypes()); 57 return res; 58 } 59 60 public void asmify( StringBuffer buf, String varName, Map labelNames) { 61 buf.append("LocalVariableTypeTableAttribute ").append(varName) 62 .append(" = new LocalVariableTypeTableAttribute();\n"); 63 64 buf.append("{\n"); 65 buf.append("LocalVariableTypeTableAttribute ").append(varName).append("Attr"); 66 buf.append(" = new LocalVariableTypeTableAttribute();\n"); 67 if (types.size() > 0) { 68 for (int i = 0; i < types.size(); i++) { 69 asmify((LocalVariableType)types.get(i), buf, varName + "type" + i, labelNames); 70 } 71 } 72 buf.append(varName).append(".visitAttribute(").append(varName); 73 buf.append("Attr);\n}\n"); 74 } 75 76 private void asmify( LocalVariableType type, StringBuffer buf, String varName, Map labelNames) { 77 declareLabel(buf, labelNames, type.start); 78 declareLabel(buf, labelNames, type.end); 79 buf.append("{\n"); 80 81 buf.append("LocalVariableType ").append(varName).append( " = new LocalVariableType();\n"); 82 83 buf.append(varName).append(".start = ").append( labelNames.get( type.start)).append(";\n"); 84 buf.append(varName).append(".end = ").append( labelNames.get( type.end)).append(";\n"); 85 buf.append(varName).append(".name = \"").append( type.name).append( "\";\n"); 86 buf.append(varName).append(".signature = ").append( type.signature).append( "\";\n"); 87 buf.append(varName).append(".index = ").append( type.index).append( "\";\n"); 88 89 buf.append( "cvAttr.types.add(").append(varName).append(");\n"); 90 buf.append("}\n"); 91 } 92 93 static void declareLabel (StringBuffer buf, Map labelNames, Label l) { 94 String name = (String )labelNames.get(l); 95 if (name == null) { 96 name = "l" + labelNames.size(); 97 labelNames.put(l, name); 98 buf.append("Label ").append(name).append(" = new Label();\n"); 99 } 100 } 101 102 } 103 104 | Popular Tags |