1 30 31 package oracle.toplink.libraries.asm; 32 33 38 39 public class Attribute { 40 41 44 45 public final String type; 46 47 50 51 public Attribute next; 52 53 58 59 protected Attribute (final String type) { 60 this.type = type; 61 } 62 63 69 70 public boolean isUnknown () { 71 return getClass().getName().equals("oracle.toplink.libraries.asm.Attribute"); 72 } 73 74 80 81 protected Label[] getLabels () { 82 return null; 83 } 84 85 107 108 protected Attribute read ( 109 ClassReader cr, int off, int len, char[] buf, int codeOff, Label[] labels) 110 { 111 return new Attribute(type); 112 } 113 114 133 134 protected ByteVector write ( 135 ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals) 136 { 137 return new ByteVector(); 138 } 139 140 145 146 final int getCount () { 147 int count = 0; 148 Attribute attr = this; 149 while (attr != null) { 150 if (!attr.isUnknown()) { 151 count += 1; 152 } 153 attr = attr.next; 154 } 155 return count; 156 } 157 158 177 178 final int getSize ( 179 final ClassWriter cw, 180 final byte[] code, 181 final int len, 182 final int maxStack, 183 final int maxLocals) 184 { 185 Attribute attr = this; 186 int size = 0; 187 while (attr != null) { 188 if (!attr.isUnknown()) { 189 cw.newUTF8(attr.type); 190 size += attr.write(cw, code, len, maxStack, maxLocals).length + 6; 191 } 192 attr = attr.next; 193 } 194 return size; 195 } 196 197 215 216 final void put ( 217 final ClassWriter cw, 218 final byte[] code, 219 final int len, 220 final int maxStack, 221 final int maxLocals, 222 final ByteVector out) 223 { 224 if (next != null) { 225 next.put(cw, code, len, maxStack, maxLocals, out); 226 } 227 if (isUnknown()) { 228 if (cw.checkAttributes) { 229 throw new IllegalArgumentException ("Unknown attribute type " + type); 230 } 231 } else { 232 ByteVector b = write(cw, code, len, maxStack, maxLocals); 233 out.putShort(cw.newUTF8(type)).putInt(b.length); 234 out.putByteArray(b.data, 0, b.length); 235 } 236 } 237 } 238 | Popular Tags |