1 30 package com.sleepycat.asm; 31 32 38 public class Attribute { 39 40 43 public final String type; 44 45 48 byte[] value; 49 50 53 Attribute next; 54 55 60 protected Attribute(final String type) { 61 this.type = type; 62 } 63 64 70 public boolean isUnknown() { 71 return true; 72 } 73 74 79 public boolean isCodeAttribute() { 80 return false; 81 } 82 83 89 protected Label[] getLabels() { 90 return null; 91 } 92 93 119 protected Attribute read( 120 ClassReader cr, 121 int off, 122 int len, 123 char[] buf, 124 int codeOff, 125 Label[] labels) 126 { 127 Attribute attr = new Attribute(type); 128 attr.value = new byte[len]; 129 System.arraycopy(cr.b, off, attr.value, 0, len); 130 return attr; 131 } 132 133 153 protected ByteVector write( 154 ClassWriter cw, 155 byte[] code, 156 int len, 157 int maxStack, 158 int maxLocals) 159 { 160 ByteVector v = new ByteVector(); 161 v.data = value; 162 v.length = value.length; 163 return v; 164 } 165 166 171 final int getCount() { 172 int count = 0; 173 Attribute attr = this; 174 while (attr != null) { 175 count += 1; 176 attr = attr.next; 177 } 178 return count; 179 } 180 181 201 final int getSize( 202 final ClassWriter cw, 203 final byte[] code, 204 final int len, 205 final int maxStack, 206 final int maxLocals) 207 { 208 Attribute attr = this; 209 int size = 0; 210 while (attr != null) { 211 cw.newUTF8(attr.type); 212 size += attr.write(cw, code, len, maxStack, maxLocals).length + 6; 213 attr = attr.next; 214 } 215 return size; 216 } 217 218 238 final void put( 239 final ClassWriter cw, 240 final byte[] code, 241 final int len, 242 final int maxStack, 243 final int maxLocals, 244 final ByteVector out) 245 { 246 Attribute attr = this; 247 while (attr != null) { 248 ByteVector b = attr.write(cw, code, len, maxStack, maxLocals); 249 out.putShort(cw.newUTF8(attr.type)).putInt(b.length); 250 out.putByteArray(b.data, 0, b.length); 251 attr = attr.next; 252 } 253 } 254 } 255 | Popular Tags |