1 30 package com.sleepycat.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 215 void put(final ByteVector out) { 216 out.putShort(access).putShort(name).putShort(desc); 217 int attributeCount = 0; 218 if (value != 0) { 219 ++attributeCount; 220 } 221 if ((access & Opcodes.ACC_SYNTHETIC) != 0 222 && (cw.version & 0xffff) < Opcodes.V1_5) 223 { 224 ++attributeCount; 225 } 226 if ((access & Opcodes.ACC_DEPRECATED) != 0) { 227 ++attributeCount; 228 } 229 if (cw.version == Opcodes.V1_4 && (access & Opcodes.ACC_ENUM) != 0) { 230 ++attributeCount; 231 } 232 if (signature != 0) { 233 ++attributeCount; 234 } 235 if (anns != null) { 236 ++attributeCount; 237 } 238 if (ianns != null) { 239 ++attributeCount; 240 } 241 if (attrs != null) { 242 attributeCount += attrs.getCount(); 243 } 244 out.putShort(attributeCount); 245 if (value != 0) { 246 out.putShort(cw.newUTF8("ConstantValue")); 247 out.putInt(2).putShort(value); 248 } 249 if ((access & Opcodes.ACC_SYNTHETIC) != 0 250 && (cw.version & 0xffff) < Opcodes.V1_5) 251 { 252 out.putShort(cw.newUTF8("Synthetic")).putInt(0); 253 } 254 if ((access & Opcodes.ACC_DEPRECATED) != 0) { 255 out.putShort(cw.newUTF8("Deprecated")).putInt(0); 256 } 257 if (cw.version == Opcodes.V1_4 && (access & Opcodes.ACC_ENUM) != 0) { 258 out.putShort(cw.newUTF8("Enum")).putInt(0); 259 } 260 if (signature != 0) { 261 out.putShort(cw.newUTF8("Signature")); 262 out.putInt(2).putShort(signature); 263 } 264 if (anns != null) { 265 out.putShort(cw.newUTF8("RuntimeVisibleAnnotations")); 266 anns.put(out); 267 } 268 if (ianns != null) { 269 out.putShort(cw.newUTF8("RuntimeInvisibleAnnotations")); 270 ianns.put(out); 271 } 272 if (attrs != null) { 273 attrs.put(cw, null, 0, -1, -1, out); 274 } 275 } 276 } 277 | Popular Tags |