Przeglądaj źródła

added addGetfield() and addPutfield() in javassist.bytecode.Bytecode.


git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@226 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
tags/rel_3_17_1_ga
chiba 18 lat temu
rodzic
commit
c9ab3dda7e
1 zmienionych plików z 38 dodań i 4 usunięć
  1. 38
    4
      src/main/javassist/bytecode/Bytecode.java

+ 38
- 4
src/main/javassist/bytecode/Bytecode.java Wyświetl plik

/** /**
* Appends GETFIELD. * 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. * @param type the descriptor of the field type.
* *
* @see Descriptor#of(CtClass) * @see Descriptor#of(CtClass)
growStack(Descriptor.dataSize(type) - 1); growStack(Descriptor.dataSize(type) - 1);
} }


/**
* 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. * Appends GETSTATIC.
* *
* @param desc the descriptor of the field type. * @param desc the descriptor of the field type.
*/ */
public void addPutfield(CtClass c, String name, String desc) { 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); 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)); addIndex(constPool.addFieldrefInfo(ci, name, desc));
growStack(-1 - Descriptor.dataSize(desc)); growStack(-1 - Descriptor.dataSize(desc));
} }
private void addPutstatic0(CtClass target, String classname, private void addPutstatic0(CtClass target, String classname,
String fieldName, String desc) { String fieldName, String desc) {
add(PUTSTATIC); add(PUTSTATIC);

// target is null if it represents THIS. // target is null if it represents THIS.
int ci = classname == null ? constPool.addClassInfo(target) int ci = classname == null ? constPool.addClassInfo(target)
: constPool.addClassInfo(classname); : constPool.addClassInfo(classname);

Ładowanie…
Anuluj
Zapisz