1 30 package net.sf.retrotranslator.runtime.asm; 31 32 37 final class FieldWriter implements FieldVisitor { 38 39 42 FieldWriter next; 43 44 47 private ClassWriter cw; 48 49 52 private int access; 53 54 58 private int name; 59 60 64 private int desc; 65 66 70 private int signature; 71 72 76 private int value; 77 78 81 private AnnotationWriter anns; 82 83 86 private AnnotationWriter ianns; 87 88 91 private Attribute attrs; 92 93 97 107 protected FieldWriter( 108 final ClassWriter cw, 109 final int access, 110 final String name, 111 final String desc, 112 final String signature, 113 final Object value) 114 { 115 if (cw.firstField == null) { 116 cw.firstField = this; 117 } else { 118 cw.lastField.next = this; 119 } 120 cw.lastField = this; 121 this.cw = cw; 122 this.access = access; 123 this.name = cw.newUTF8(name); 124 this.desc = cw.newUTF8(desc); 125 if (signature != null) { 126 this.signature = cw.newUTF8(signature); 127 } 128 if (value != null) { 129 this.value = cw.newConstItem(value).index; 130 } 131 } 132 133 137 public AnnotationVisitor visitAnnotation( 138 final String desc, 139 final boolean visible) 140 { 141 ByteVector bv = new ByteVector(); 142 bv.putShort(cw.newUTF8(desc)).putShort(0); 144 AnnotationWriter aw = new AnnotationWriter(cw, true, bv, bv, 2); 145 if (visible) { 146 aw.next = anns; 147 anns = aw; 148 } else { 149 aw.next = ianns; 150 ianns = aw; 151 } 152 return aw; 153 } 154 155 public void visitAttribute(final Attribute attr) { 156 attr.next = attrs; 157 attrs = attr; 158 } 159 160 public void visitEnd() { 161 } 162 163 167 172 int getSize() { 173 int size = 8; 174 if (value != 0) { 175 cw.newUTF8("ConstantValue"); 176 size += 8; 177 } 178 if ((access & Opcodes.ACC_SYNTHETIC) != 0 179 && (cw.version & 0xffff) < Opcodes.V1_5) 180 { 181 cw.newUTF8("Synthetic"); 182 size += 6; 183 } 184 if ((access & Opcodes.ACC_DEPRECATED) != 0) { 185 cw.newUTF8("Deprecated"); 186 size += 6; 187 } 188 if (cw.version == Opcodes.V1_4 && (access & Opcodes.ACC_ENUM) != 0) { 189 cw.newUTF8("Enum"); 190 size += 6; 191 } 192 if (signature != 0) { 193 cw.newUTF8("Signature"); 194 size += 8; 195 } 196 if (anns != null) { 197 cw.newUTF8("RuntimeVisibleAnnotations"); 198 size += 8 + anns.getSize(); 199 } 200 if (ianns != null) { 201 cw.newUTF8("RuntimeInvisibleAnnotations"); 202 size += 8 + ianns.getSize(); 203 } 204 if (attrs != null) { 205 size += attrs.getSize(cw, null, 0, -1, -1); 206 } 207 return size; 208 } 209 210 216 void put(final ByteVector out, boolean dropTigerFlags) { 217 int modifiers = access; 218 if (dropTigerFlags) { 219 modifiers &= ~(Opcodes.ACC_SYNTHETIC | Opcodes.ACC_ENUM); 220 } 221 out.putShort(modifiers).putShort(name).putShort(desc); 222 int attributeCount = 0; 223 if (value != 0) { 224 ++attributeCount; 225 } 226 if ((access & Opcodes.ACC_SYNTHETIC) != 0 227 && (cw.version & 0xffff) < Opcodes.V1_5) 228 { 229 ++attributeCount; 230 } 231 if ((access & Opcodes.ACC_DEPRECATED) != 0) { 232 ++attributeCount; 233 } 234 if (cw.version == Opcodes.V1_4 && (access & Opcodes.ACC_ENUM) != 0) { 235 ++attributeCount; 236 } 237 if (signature != 0) { 238 ++attributeCount; 239 } 240 if (anns != null) { 241 ++attributeCount; 242 } 243 if (ianns != null) { 244 ++attributeCount; 245 } 246 if (attrs != null) { 247 attributeCount += attrs.getCount(); 248 } 249 out.putShort(attributeCount); 250 if (value != 0) { 251 out.putShort(cw.newUTF8("ConstantValue")); 252 out.putInt(2).putShort(value); 253 } 254 if ((access & Opcodes.ACC_SYNTHETIC) != 0 255 && (cw.version & 0xffff) < Opcodes.V1_5) 256 { 257 out.putShort(cw.newUTF8("Synthetic")).putInt(0); 258 } 259 if ((access & Opcodes.ACC_DEPRECATED) != 0) { 260 out.putShort(cw.newUTF8("Deprecated")).putInt(0); 261 } 262 if (cw.version == Opcodes.V1_4 && (access & Opcodes.ACC_ENUM) != 0) { 263 out.putShort(cw.newUTF8("Enum")).putInt(0); 264 } 265 if (signature != 0) { 266 out.putShort(cw.newUTF8("Signature")); 267 out.putInt(2).putShort(signature); 268 } 269 if (anns != null) { 270 out.putShort(cw.newUTF8("RuntimeVisibleAnnotations")); 271 anns.put(out); 272 } 273 if (ianns != null) { 274 out.putShort(cw.newUTF8("RuntimeInvisibleAnnotations")); 275 ianns.put(out); 276 } 277 if (attrs != null) { 278 attrs.put(cw, null, 0, -1, -1, out); 279 } 280 } 281 } 282 | Popular Tags |