| java.lang.Object net.sf.retrotranslator.runtime.asm.ClassWriter
All known Subclasses: net.sf.retrotranslator.transformer.ReflectionDataVisitor,
ClassWriter | public class ClassWriter implements ClassVisitor(Code) | | A
ClassVisitor that generates classes in bytecode form. More
precisely this visitor generates a byte array conforming to the Java class
file format. It can be used alone, to generate a Java class "from scratch",
or with one or more
ClassReader ClassReader and adapter class visitor
to generate a modified class from one or more existing Java classes.
author: Eric Bruneton |
Field Summary | |
final static int | CLASS The type of CONSTANT_Class constant pool items. | final static int | DOUBLE The type of CONSTANT_Double constant pool items. | final static int | FIELD The type of CONSTANT_Fieldref constant pool items. | final static int | FIELDORMETH_INSN The type of field and method invocations instructions. | final static int | FLOAT The type of CONSTANT_Float constant pool items. | final static int | IINC_INSN The type of the IINC instruction. | final static int | IMETH The type of CONSTANT_InterfaceMethodref constant pool items. | final static int | IMPLVAR_INSN The type of instructions with an implicit local variable index argument. | final static int | INT The type of CONSTANT_Integer constant pool items. | final static int | ITFMETH_INSN The type of the INVOKEINTERFACE instruction. | final static int | LABELW_INSN The type of instructions with a 4 bytes bytecode offset label. | final static int | LABEL_INSN The type of instructions with a 2 bytes bytecode offset label. | final static int | LDCW_INSN The type of the LDC_W and LDC2_W instructions. | final static int | LDC_INSN The type of the LDC instruction. | final static int | LONG The type of CONSTANT_Long constant pool items. | final static int | LOOK_INSN The type of the LOOKUPSWITCH instruction. | final static int | MANA_INSN The type of the MULTIANEWARRAY instruction. | final static int | METH The type of CONSTANT_Methodref constant pool items. | final static int | NAME_TYPE The type of CONSTANT_NameAndType constant pool items. | final static int | NOARG_INSN The type of instructions without any argument. | final static int | SBYTE_INSN The type of instructions with an signed byte argument. | final static int | SHORT_INSN The type of instructions with an signed short argument. | final static int | STR The type of CONSTANT_String constant pool items. | final static int | TABL_INSN The type of the TABLESWITCH instruction. | static byte[] | TYPE The instruction types of all JVM opcodes. | final static int | TYPE_INSN The type of instructions with a type descriptor argument. | final static int | UTF8 The type of CONSTANT_Utf8 constant pool items. | final static int | VAR_INSN The type of instructions with a local variable index argument. | final static int | WIDE_INSN The type of the WIDE instruction. | ClassReader | cr The class reader from which this class writer was constructed, if any. | FieldWriter | firstField The fields of this class. | MethodWriter | firstMethod The methods of this class. | int | index Index of the next item to be added in the constant pool. | Item[] | items The constant pool's hash table data. | Item | key A reusable key used to look for items in the hash
ClassWriter.items items . | Item | key2 A reusable key used to look for items in the hash
ClassWriter.items items . | Item | key3 A reusable key used to look for items in the hash
ClassWriter.items items . | FieldWriter | lastField The fields of this class. | MethodWriter | lastMethod The methods of this class. | ByteVector | pool The constant pool of this class. | int | threshold The threshold of the constant pool's hash table. | int | version Minor and major version numbers of the class to be generated. |
Constructor Summary | |
public | ClassWriter(boolean computeMaxs) Constructs a new
ClassWriter ClassWriter object. | public | ClassWriter(boolean computeMaxs, boolean skipUnknownAttributes) Constructs a new
ClassWriter object.
Parameters: computeMaxs - true if the maximum stack size and themaximum number of local variables must be automatically computed.If this flag is true, then the arguments of theMethodVisitor.visitMaxs visitMaxs method of theMethodVisitor returned by theClassWriter.visitMethod visitMethod method will be ignored, andcomputed automatically from the signature and the bytecode of eachmethod. Parameters: skipUnknownAttributes - Deprecated. | public | ClassWriter(ClassReader classReader, boolean computeMaxs) Constructs a new
ClassWriter object and enables optimizations for
"mostly add" bytecode transformations. |
Method Summary | |
public int | newClass(String value) Adds a class reference to the constant pool of the class being build.
Does nothing if the constant pool already contains a similar item.
This method is intended for
Attribute sub classes, and is
normally not needed by class generators or adapters.
Parameters: value - the internal name of the class. | public int | newConst(Object cst) Adds a number or string constant to the constant pool of the class being
build. | Item | newConstItem(Object cst) Adds a number or string constant to the constant pool of the class being
build. | Item | newDouble(double value) Adds a double to the constant pool of the class being build. | public int | newField(String owner, String name, String desc) Adds a field reference to the constant pool of the class being build.
Does nothing if the constant pool already contains a similar item.
This method is intended for
Attribute sub classes, and is
normally not needed by class generators or adapters.
Parameters: owner - the internal name of the field's owner class. Parameters: name - the field's name. Parameters: desc - the field's descriptor. | Item | newFloat(float value) Adds a float to the constant pool of the class being build. | Item | newInteger(int value) Adds an integer to the constant pool of the class being build. | Item | newLong(long value) Adds a long to the constant pool of the class being build. | public int | newMethod(String owner, String name, String desc, boolean itf) Adds a method reference to the constant pool of the class being build.
Does nothing if the constant pool already contains a similar item.
This method is intended for
Attribute sub classes, and is
normally not needed by class generators or adapters.
Parameters: owner - the internal name of the method's owner class. Parameters: name - the method's name. Parameters: desc - the method's descriptor. Parameters: itf - true if owner is an interface. | Item | newMethodItem(String owner, String name, String desc, boolean itf) Adds a method reference to the constant pool of the class being build.
Does nothing if the constant pool already contains a similar item.
Parameters: owner - the internal name of the method's owner class. Parameters: name - the method's name. Parameters: desc - the method's descriptor. Parameters: itf - true if owner is an interface. | public int | newNameType(String name, String desc) Adds a name and type to the constant pool of the class being build. | public int | newUTF8(String value) Adds an UTF8 string to the constant pool of the class being build. | public byte[] | toByteArray() Returns the bytecode of the class that was build with this class writer. | public byte[] | toByteArray(boolean dropTigerFlags) | public void | visit(int version, int access, String name, String signature, String superName, String[] interfaces) | public AnnotationVisitor | visitAnnotation(String desc, boolean visible) | public void | visitAttribute(Attribute attr) | public void | visitEnd() | public FieldVisitor | visitField(int access, String name, String desc, String signature, Object value) | public void | visitInnerClass(String name, String outerName, String innerName, int access) | public MethodVisitor | visitMethod(int access, String name, String desc, String signature, String[] exceptions) | public void | visitOuterClass(String owner, String name, String desc) | public void | visitSource(String file, String debug) |
CLASS | final static int CLASS(Code) | | The type of CONSTANT_Class constant pool items.
|
DOUBLE | final static int DOUBLE(Code) | | The type of CONSTANT_Double constant pool items.
|
FIELD | final static int FIELD(Code) | | The type of CONSTANT_Fieldref constant pool items.
|
FIELDORMETH_INSN | final static int FIELDORMETH_INSN(Code) | | The type of field and method invocations instructions.
|
FLOAT | final static int FLOAT(Code) | | The type of CONSTANT_Float constant pool items.
|
IINC_INSN | final static int IINC_INSN(Code) | | The type of the IINC instruction.
|
IMETH | final static int IMETH(Code) | | The type of CONSTANT_InterfaceMethodref constant pool items.
|
IMPLVAR_INSN | final static int IMPLVAR_INSN(Code) | | The type of instructions with an implicit local variable index argument.
|
INT | final static int INT(Code) | | The type of CONSTANT_Integer constant pool items.
|
ITFMETH_INSN | final static int ITFMETH_INSN(Code) | | The type of the INVOKEINTERFACE instruction.
|
LABELW_INSN | final static int LABELW_INSN(Code) | | The type of instructions with a 4 bytes bytecode offset label.
|
LABEL_INSN | final static int LABEL_INSN(Code) | | The type of instructions with a 2 bytes bytecode offset label.
|
LDCW_INSN | final static int LDCW_INSN(Code) | | The type of the LDC_W and LDC2_W instructions.
|
LDC_INSN | final static int LDC_INSN(Code) | | The type of the LDC instruction.
|
LONG | final static int LONG(Code) | | The type of CONSTANT_Long constant pool items.
|
LOOK_INSN | final static int LOOK_INSN(Code) | | The type of the LOOKUPSWITCH instruction.
|
MANA_INSN | final static int MANA_INSN(Code) | | The type of the MULTIANEWARRAY instruction.
|
METH | final static int METH(Code) | | The type of CONSTANT_Methodref constant pool items.
|
NAME_TYPE | final static int NAME_TYPE(Code) | | The type of CONSTANT_NameAndType constant pool items.
|
NOARG_INSN | final static int NOARG_INSN(Code) | | The type of instructions without any argument.
|
SBYTE_INSN | final static int SBYTE_INSN(Code) | | The type of instructions with an signed byte argument.
|
SHORT_INSN | final static int SHORT_INSN(Code) | | The type of instructions with an signed short argument.
|
STR | final static int STR(Code) | | The type of CONSTANT_String constant pool items.
|
TABL_INSN | final static int TABL_INSN(Code) | | The type of the TABLESWITCH instruction.
|
TYPE | static byte[] TYPE(Code) | | The instruction types of all JVM opcodes.
|
TYPE_INSN | final static int TYPE_INSN(Code) | | The type of instructions with a type descriptor argument.
|
UTF8 | final static int UTF8(Code) | | The type of CONSTANT_Utf8 constant pool items.
|
VAR_INSN | final static int VAR_INSN(Code) | | The type of instructions with a local variable index argument.
|
WIDE_INSN | final static int WIDE_INSN(Code) | | The type of the WIDE instruction.
|
cr | ClassReader cr(Code) | | The class reader from which this class writer was constructed, if any.
|
firstField | FieldWriter firstField(Code) | | The fields of this class. These fields are stored in a linked list of
FieldWriter objects, linked to each other by their
FieldWriter.next field. This field stores the first element of
this list.
|
firstMethod | MethodWriter firstMethod(Code) | | The methods of this class. These methods are stored in a linked list of
MethodWriter objects, linked to each other by their
MethodWriter.next field. This field stores the first element of
this list.
|
index | int index(Code) | | Index of the next item to be added in the constant pool.
|
items | Item[] items(Code) | | The constant pool's hash table data.
|
lastField | FieldWriter lastField(Code) | | The fields of this class. These fields are stored in a linked list of
FieldWriter objects, linked to each other by their
FieldWriter.next field. This field stores the last element of
this list.
|
lastMethod | MethodWriter lastMethod(Code) | | The methods of this class. These methods are stored in a linked list of
MethodWriter objects, linked to each other by their
MethodWriter.next field. This field stores the last element of
this list.
|
threshold | int threshold(Code) | | The threshold of the constant pool's hash table.
|
version | int version(Code) | | Minor and major version numbers of the class to be generated.
|
ClassWriter | public ClassWriter(boolean computeMaxs)(Code) | | Constructs a new
ClassWriter ClassWriter object.
Parameters: computeMaxs - true if the maximum stack size and themaximum number of local variables must be automatically computed.If this flag is true, then the arguments of theMethodVisitor.visitMaxs visitMaxs method of theMethodVisitor returned by theClassWriter.visitMethod visitMethod method will be ignored, andcomputed automatically from the signature and the bytecode of eachmethod. |
ClassWriter | public ClassWriter(boolean computeMaxs, boolean skipUnknownAttributes)(Code) | | Constructs a new
ClassWriter object.
Parameters: computeMaxs - true if the maximum stack size and themaximum number of local variables must be automatically computed.If this flag is true, then the arguments of theMethodVisitor.visitMaxs visitMaxs method of theMethodVisitor returned by theClassWriter.visitMethod visitMethod method will be ignored, andcomputed automatically from the signature and the bytecode of eachmethod. Parameters: skipUnknownAttributes - Deprecated. The value of thisparameter is ignored. |
ClassWriter | public ClassWriter(ClassReader classReader, boolean computeMaxs)(Code) | | Constructs a new
ClassWriter object and enables optimizations for
"mostly add" bytecode transformations. These optimizations are the
following:
- The constant pool from the original class is copied as is in
the new class, which saves time. New constant pool entries will be added
at the end if necessary, but unused constant pool entries won't be
removed.
- Methods that are not transformed are copied as
is in the new class, directly from the original class bytecode (i.e.
without emitting visit events for all the method instructions), which
saves a lot of time. Untransformed methods are detected by the
fact that the
ClassReader receives
MethodVisitor objects
that come from a
ClassWriter (and not from a custom
ClassAdapter or any other
ClassVisitor instance).
Parameters: classReader - the ClassReader used to read the originalclass. It will be used to copy the entire constant pool from theoriginal class and also to copy other fragments of originalbytecode where applicable. Parameters: computeMaxs - true if the maximum stack size and themaximum number of local variables must be automatically computed.If this flag is true, then the arguments of theMethodVisitor.visitMaxs visitMaxs method of theMethodVisitor returned by theClassWriter.visitMethod visitMethod method will be ignored, andcomputed automatically from the signature and the bytecode of eachmethod. |
newClass | public int newClass(String value)(Code) | | Adds a class reference to the constant pool of the class being build.
Does nothing if the constant pool already contains a similar item.
This method is intended for
Attribute sub classes, and is
normally not needed by class generators or adapters.
Parameters: value - the internal name of the class. the index of a new or already existing class reference item. |
newConst | public int newConst(Object cst)(Code) | | Adds a number or string constant to the constant pool of the class being
build. Does nothing if the constant pool already contains a similar item.
This method is intended for
Attribute sub classes, and is
normally not needed by class generators or adapters.
Parameters: cst - the value of the constant to be added to the constant pool.This parameter must be an Integer, a Float, aLong, a Double or a String. the index of a new or already existing constant item with thegiven value. |
newConstItem | Item newConstItem(Object cst)(Code) | | Adds a number or string constant to the constant pool of the class being
build. Does nothing if the constant pool already contains a similar item.
Parameters: cst - the value of the constant to be added to the constant pool.This parameter must be an Integer, a Float, aLong, a Double, a String or aType. a new or already existing constant item with the given value. |
newDouble | Item newDouble(double value)(Code) | | Adds a double to the constant pool of the class being build. Does nothing
if the constant pool already contains a similar item.
Parameters: value - the double value. a new or already existing double item. |
newField | public int newField(String owner, String name, String desc)(Code) | | Adds a field reference to the constant pool of the class being build.
Does nothing if the constant pool already contains a similar item.
This method is intended for
Attribute sub classes, and is
normally not needed by class generators or adapters.
Parameters: owner - the internal name of the field's owner class. Parameters: name - the field's name. Parameters: desc - the field's descriptor. the index of a new or already existing field reference item. |
newFloat | Item newFloat(float value)(Code) | | Adds a float to the constant pool of the class being build. Does nothing
if the constant pool already contains a similar item.
Parameters: value - the float value. a new or already existing float item. |
newInteger | Item newInteger(int value)(Code) | | Adds an integer to the constant pool of the class being build. Does
nothing if the constant pool already contains a similar item.
Parameters: value - the int value. a new or already existing int item. |
newLong | Item newLong(long value)(Code) | | Adds a long to the constant pool of the class being build. Does nothing
if the constant pool already contains a similar item.
Parameters: value - the long value. a new or already existing long item. |
newMethod | public int newMethod(String owner, String name, String desc, boolean itf)(Code) | | Adds a method reference to the constant pool of the class being build.
Does nothing if the constant pool already contains a similar item.
This method is intended for
Attribute sub classes, and is
normally not needed by class generators or adapters.
Parameters: owner - the internal name of the method's owner class. Parameters: name - the method's name. Parameters: desc - the method's descriptor. Parameters: itf - true if owner is an interface. the index of a new or already existing method reference item. |
newMethodItem | Item newMethodItem(String owner, String name, String desc, boolean itf)(Code) | | Adds a method reference to the constant pool of the class being build.
Does nothing if the constant pool already contains a similar item.
Parameters: owner - the internal name of the method's owner class. Parameters: name - the method's name. Parameters: desc - the method's descriptor. Parameters: itf - true if owner is an interface. a new or already existing method reference item. |
newNameType | public int newNameType(String name, String desc)(Code) | | Adds a name and type to the constant pool of the class being build. Does
nothing if the constant pool already contains a similar item. This
method is intended for
Attribute sub classes, and is normally not
needed by class generators or adapters.
Parameters: name - a name. Parameters: desc - a type descriptor. the index of a new or already existing name and type item. |
newUTF8 | public int newUTF8(String value)(Code) | | Adds an UTF8 string to the constant pool of the class being build. Does
nothing if the constant pool already contains a similar item. This
method is intended for
Attribute sub classes, and is normally not
needed by class generators or adapters.
Parameters: value - the String value. the index of a new or already existing UTF8 item. |
toByteArray | public byte[] toByteArray()(Code) | | Returns the bytecode of the class that was build with this class writer.
the bytecode of the class that was build with this class writer. |
toByteArray | public byte[] toByteArray(boolean dropTigerFlags)(Code) | | |
visitEnd | public void visitEnd()(Code) | | |
|
|