1 15 16 package javassist.convert; 17 18 import javassist.CtClass; 19 import javassist.CtField; 20 import javassist.bytecode.*; 21 22 final public class TransformWriteField extends TransformReadField { 23 public TransformWriteField(Transformer next, CtField field, 24 String methodClassname, String methodName) 25 { 26 super(next, field, methodClassname, methodName); 27 } 28 29 public int transform(CtClass tclazz, int pos, CodeIterator iterator, 30 ConstPool cp) throws BadBytecode 31 { 32 int c = iterator.byteAt(pos); 33 if (c == PUTFIELD || c == PUTSTATIC) { 34 int index = iterator.u16bitAt(pos + 1); 35 String typedesc = isField(tclazz.getClassPool(), cp, 36 fieldClass, fieldname, isPrivate, index); 37 if (typedesc != null) { 38 if (c == PUTSTATIC) { 39 CodeAttribute ca = iterator.get(); 40 iterator.move(pos); 41 char c0 = typedesc.charAt(0); 42 if (c0 == 'J' || c0 == 'D') { iterator.insertGap(3); 45 iterator.writeByte(ACONST_NULL, pos); 46 iterator.writeByte(DUP_X2, pos + 1); 47 iterator.writeByte(POP, pos + 2); 48 ca.setMaxStack(ca.getMaxStack() + 2); 49 } 50 else { 51 iterator.insertGap(2); 53 iterator.writeByte(ACONST_NULL, pos); 54 iterator.writeByte(SWAP, pos + 1); 55 ca.setMaxStack(ca.getMaxStack() + 1); 56 } 57 58 pos = iterator.next(); 59 } 60 61 int mi = cp.addClassInfo(methodClassname); 62 String type = "(Ljava/lang/Object;" + typedesc + ")V"; 63 int methodref = cp.addMethodrefInfo(mi, methodName, type); 64 iterator.writeByte(INVOKESTATIC, pos); 65 iterator.write16bit(methodref, pos + 1); 66 } 67 } 68 69 return pos; 70 } 71 } 72 | Popular Tags |