1 30 package org.objectweb.asm; 31 32 38 public class Attribute { 39 40 43 public final String type; 44 45 48 Attribute next; 49 50 55 protected Attribute(final String type) { 56 this.type = type; 57 } 58 59 65 public boolean isUnknown() { 66 return true; 67 } 68 69 74 public boolean isCodeAttribute() { 75 return false; 76 } 77 78 84 protected Label[] getLabels() { 85 return null; 86 } 87 88 114 protected Attribute read( 115 ClassReader cr, 116 int off, 117 int len, 118 char[] buf, 119 int codeOff, 120 Label[] labels) 121 { 122 return new Attribute(type); 123 } 124 125 145 protected ByteVector write( 146 ClassWriter cw, 147 byte[] code, 148 int len, 149 int maxStack, 150 int maxLocals) 151 { 152 return new ByteVector(); 153 } 154 155 160 final int getCount() { 161 int count = 0; 162 Attribute attr = this; 163 while (attr != null) { 164 if (!attr.isUnknown()) { 165 count += 1; 166 } 167 attr = attr.next; 168 } 169 return count; 170 } 171 172 192 final int getSize( 193 final ClassWriter cw, 194 final byte[] code, 195 final int len, 196 final int maxStack, 197 final int maxLocals) 198 { 199 Attribute attr = this; 200 int size = 0; 201 while (attr != null) { 202 if (!attr.isUnknown()) { 203 cw.newUTF8(attr.type); 204 size += attr.write(cw, code, len, maxStack, maxLocals).length + 6; 205 } 206 attr = attr.next; 207 } 208 return size; 209 } 210 211 231 final void put( 232 final ClassWriter cw, 233 final byte[] code, 234 final int len, 235 final int maxStack, 236 final int maxLocals, 237 final ByteVector out) 238 { 239 Attribute attr = this; 240 while (attr != null) { 241 if (attr.isUnknown()) { 242 if (cw.checkAttributes) { 243 throw new IllegalArgumentException ("Unknown attribute type: " 244 + attr.type); 245 } 246 } else { 247 ByteVector b = attr.write(cw, code, len, maxStack, maxLocals); 248 out.putShort(cw.newUTF8(attr.type)).putInt(b.length); 249 out.putByteArray(b.data, 0, b.length); 250 } 251 attr = attr.next; 252 } 253 } 254 } 255 | Popular Tags |