diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2005-12-23 15:58:43 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2005-12-23 15:58:43 +0000 |
commit | c9ab3dda7e40a5fa6fa83757a347d9256d2b77d9 (patch) | |
tree | 5c2197ee273ac326db9d68cc755ff55eb2c3cdb6 | |
parent | ecb71c75155bdd2990141314db777348fdf313ff (diff) | |
download | javassist-c9ab3dda7e40a5fa6fa83757a347d9256d2b77d9.tar.gz javassist-c9ab3dda7e40a5fa6fa83757a347d9256d2b77d9.zip |
added addGetfield() and addPutfield() in javassist.bytecode.Bytecode.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@226 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r-- | src/main/javassist/bytecode/Bytecode.java | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/src/main/javassist/bytecode/Bytecode.java b/src/main/javassist/bytecode/Bytecode.java index 9fe0bb84..a1f74c6d 100644 --- a/src/main/javassist/bytecode/Bytecode.java +++ b/src/main/javassist/bytecode/Bytecode.java @@ -832,8 +832,8 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode { /** * Appends GETFIELD. * - * @param c the class - * @param name the field name + * @param c the class. + * @param name the field name. * @param type the descriptor of the field type. * * @see Descriptor#of(CtClass) @@ -846,6 +846,22 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode { } /** + * Appends GETFIELD. + * + * @param c the fully-qualified class name. + * @param name the field name. + * @param type the descriptor of the field type. + * + * @see Descriptor#of(CtClass) + */ + public void addGetfield(String c, String name, String type) { + add(GETFIELD); + int ci = constPool.addClassInfo(c); + addIndex(constPool.addFieldrefInfo(ci, name, type)); + growStack(Descriptor.dataSize(type) - 1); + } + + /** * Appends GETSTATIC. * * @param c the class @@ -1283,8 +1299,27 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode { * @param desc the descriptor of the field type. */ public void addPutfield(CtClass c, String name, String desc) { + addPutfield0(c, null, name, desc); + } + + /** + * Appends PUTFIELD. + * + * @param classname the fully-qualified name of the target class. + * @param name the field name. + * @param desc the descriptor of the field type. + */ + public void addPutfield(String classname, String name, String desc) { + // if classnaem is null, the target class is THIS. + addPutfield0(null, classname, name, desc); + } + + private void addPutfield0(CtClass target, String classname, + String name, String desc) { add(PUTFIELD); - int ci = constPool.addClassInfo(c); + // target is null if it represents THIS. + int ci = classname == null ? constPool.addClassInfo(target) + : constPool.addClassInfo(classname); addIndex(constPool.addFieldrefInfo(ci, name, desc)); growStack(-1 - Descriptor.dataSize(desc)); } @@ -1315,7 +1350,6 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode { private void addPutstatic0(CtClass target, String classname, String fieldName, String desc) { add(PUTSTATIC); - // target is null if it represents THIS. int ci = classname == null ? constPool.addClassInfo(target) : constPool.addClassInfo(classname); |