1 30 31 package oracle.toplink.libraries.asm.attrs; 32 33 import java.util.ArrayList ; 34 import java.util.HashSet ; 35 import java.util.List ; 36 37 import oracle.toplink.libraries.asm.Attribute; 38 import oracle.toplink.libraries.asm.ByteVector; 39 import oracle.toplink.libraries.asm.ClassReader; 40 import oracle.toplink.libraries.asm.ClassWriter; 41 import oracle.toplink.libraries.asm.Label; 42 43 129 public class LocalVariableTypeTableAttribute extends Attribute { 130 131 protected List types = new ArrayList (); 132 133 134 public LocalVariableTypeTableAttribute() { 135 super( "LocalVariableTypeTable"); 136 } 137 138 public List getTypes() { 139 return types; 140 } 141 142 protected Label[] getLabels() { 143 HashSet labels = new HashSet (); 144 for (int i = 0; i < types.size(); i++) { 145 LocalVariableType t = (LocalVariableType)types.get(i); 146 labels.add( t.getStart()); 147 labels.add( t.getEnd()); 148 } 149 return ( Label[]) labels.toArray( new Label[ labels.size()]); 150 } 151 152 protected Attribute read( ClassReader cr, int off, int len, char[] buf, int codeOff, Label[] labels) { 153 int localVariableTypeTableLength = cr.readUnsignedShort(off); 154 off += 2; 155 LocalVariableTypeTableAttribute attr = new LocalVariableTypeTableAttribute(); 156 for( int i = 0; i < localVariableTypeTableLength; i++) { 157 LocalVariableType t = new LocalVariableType(); 158 int start = cr.readUnsignedShort( off); 159 int length = cr.readUnsignedShort( off + 2); 160 t.start = getLabel( labels, start); 161 t.end = getLabel( labels, start + length); 162 t.name = cr.readUTF8( off + 4, buf); 163 t.signature = cr.readUTF8( off + 6, buf); 164 t.index = cr.readUnsignedShort( off + 8); 165 off += 10; 166 types.add(t); 167 } 168 return attr; 169 } 170 171 protected ByteVector write( ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals) { 172 ByteVector bv = new ByteVector(); 173 bv.putShort( types.size()); 174 for( int i = 0; i < types.size(); i++) { 175 LocalVariableType t = ( LocalVariableType) types.get(i); 176 int startOffset = t.getStart().getOffset(); 177 bv.putShort( startOffset); 178 bv.putShort( t.getEnd().getOffset()-startOffset); 179 bv.putUTF8( t.getName()); 180 bv.putUTF8( t.getSignature()); 181 bv.putShort( t.getIndex()); 182 } 183 return bv; 184 } 185 186 private Label getLabel( Label[] labels, int offset) { 187 Label label = labels[ offset]; 188 if( label==null) { 189 label = new Label(); 190 labels[ offset] = label; 191 } 192 return label; 193 } 194 195 public String toString() { 196 StringBuffer sb = new StringBuffer ("LocalVariableTypeTable["); 197 for (int i = 0; i < types.size(); i++) { 198 sb.append('\n').append('[').append(types.get(i)).append(']'); 199 } 200 sb.append("\n]"); 201 return sb.toString(); 202 } 203 204 } 205 206 | Popular Tags |