| java.lang.Object org.mozilla.classfile.ClassFileWriter
ClassFileWriter | public class ClassFileWriter (Code) | | ClassFileWriter
A ClassFileWriter is used to write a Java class file. Methods are
provided to create fields and methods, and within methods to write
Java bytecodes.
author: Roger Lawrence |
Inner Class :public static class ClassFileFormatException extends RuntimeException | |
Method Summary | |
public int | acquireLabel() | public void | add(int theOpCode) Add the single-byte opcode to the current method. | public void | add(int theOpCode, int theOperand) Add a single-operand opcode to the current method. | public void | add(int theOpCode, int theOperand1, int theOperand2) Add the given two-operand bytecode to the current method. | public void | add(int theOpCode, String className) | public void | add(int theOpCode, String className, String fieldName, String fieldType) | public void | addALoad(int local) Load object from the given local into stack. | public void | addAStore(int local) Store object from stack top into the given local. | public void | addDLoad(int local) Load double from the given local into stack. | public void | addDStore(int local) Store double from stack top into the given local. | public void | addExceptionHandler(int startLabel, int endLabel, int handlerLabel, String catchClassName) | public void | addFLoad(int local) Load float from the given local into stack. | public void | addFStore(int local) Store float from stack top into the given local. | public void | addField(String fieldName, String type, short flags) Add a field to the class. | public void | addField(String fieldName, String type, short flags, int value) Add a field to the class. | public void | addField(String fieldName, String type, short flags, long value) Add a field to the class. | public void | addField(String fieldName, String type, short flags, double value) Add a field to the class. | public void | addILoad(int local) Load integer from the given local into stack. | public void | addIStore(int local) Store integer from stack top into the given local. | public void | addInterface(String interfaceName) Add an interface implemented by this class. | public void | addInvoke(int theOpCode, String className, String methodName, String methodType) | public void | addLLoad(int local) Load long from the given local into stack. | public void | addLStore(int local) Store long from stack top into the given local. | public void | addLineNumberEntry(short lineNumber) | public void | addLoadConstant(int k) Generate the load constant bytecode for the given integer. | public void | addLoadConstant(long k) Generate the load constant bytecode for the given long. | public void | addLoadConstant(float k) Generate the load constant bytecode for the given float. | public void | addLoadConstant(double k) Generate the load constant bytecode for the given double. | public void | addLoadConstant(String k) Generate the load constant bytecode for the given string. | public void | addLoadThis() Load "this" into stack. | public void | addPush(int k) Generate code to load the given integer on stack. | public void | addPush(boolean k) | public void | addPush(long k) Generate code to load the given long on stack. | public void | addPush(double k) Generate code to load the given double on stack. | public void | addPush(String k) | public int | addTableSwitch(int low, int high) | public void | addVariableDescriptor(String name, String type, int startPC, int register) Add Information about java variable to use when generating the local
variable table. | public void | adjustStackTop(int delta) | public static String | classNameToSignature(String name) Convert Java class name in dot notation into
"Lname-with-dots-replaced-by-slashes;" form suitable for use as
JVM type signatures. | final char[] | getCharBuffer(int minimalSize) | final public String | getClassName() | public int | getCurrentCodeOffset() Get the current offset into the code of the current method. | static String | getSlashedForm(String name) | public short | getStackTop() | public boolean | isUnderStringSizeLimit(String k) Check if k fits limit on string constant size imposed by class file
format. | public void | markHandler(int theLabel) | public void | markLabel(int label) | public void | markLabel(int label, short stackTop) | final public void | markTableSwitchCase(int switchStart, int caseIndex) | final public void | markTableSwitchCase(int switchStart, int caseIndex, int stackTop) | final public void | markTableSwitchDefault(int switchStart) | static int | opcodeCount(int opcode) Number of operands accompanying the opcode. | static int | putInt16(int value, byte[] array, int offset) | static int | putInt32(int value, byte[] array, int offset) | static int | putInt64(long value, byte[] array, int offset) | public void | setFlags(short flags) Set the class's flags. | public void | setStackTop(short n) | public void | setTableSwitchJump(int switchStart, int caseIndex, int jumpTarget) | static int | stackChange(int opcode) The effect on the operand stack of a given opcode. | public void | startMethod(String methodName, String type, short flags) Add a method and begin adding code.
This method must be called before other methods for adding code,
exception tables, etc. | public void | stopMethod(short maxLocals) Complete generation of the method.
After this method is called, no more code can be added to the
method begun with startMethod .
Parameters: maxLocals - the maximum number of local variable slots(a.k.a. | public byte[] | toByteArray() Get the class file as array of bytesto the OutputStream. | public void | write(OutputStream oStream) Write the class file to the OutputStream. |
ACC_PUBLICACC_PRIVATEACC_PROTECTEDACC_STATICACC_FINALACC_SYNCHRONIZEDACC_VOLATILEACC_TRANSIENTACC_NATIVEACC_ABSTRACT | final public static short ACC_PUBLICACC_PRIVATEACC_PROTECTEDACC_STATICACC_FINALACC_SYNCHRONIZEDACC_VOLATILEACC_TRANSIENTACC_NATIVEACC_ABSTRACT(Code) | | |
ClassFileWriter | public ClassFileWriter(String className, String superClassName, String sourceFileName)(Code) | | Construct a ClassFileWriter for a class.
Parameters: className - the name of the class to write, includingfull package qualification. Parameters: superClassName - the name of the superclass of the classto write, including full package qualification. Parameters: sourceFileName - the name of the source file to use forproducing debug information, or null if debug informationis not desired |
acquireLabel | public int acquireLabel()(Code) | | |
add | public void add(int theOpCode)(Code) | | Add the single-byte opcode to the current method.
Parameters: theOpCode - the opcode of the bytecode |
add | public void add(int theOpCode, int theOperand)(Code) | | Add a single-operand opcode to the current method.
Parameters: theOpCode - the opcode of the bytecode Parameters: theOperand - the operand of the bytecode |
add | public void add(int theOpCode, int theOperand1, int theOperand2)(Code) | | Add the given two-operand bytecode to the current method.
Parameters: theOpCode - the opcode of the bytecode Parameters: theOperand1 - the first operand of the bytecode Parameters: theOperand2 - the second operand of the bytecode |
addALoad | public void addALoad(int local)(Code) | | Load object from the given local into stack.
Parameters: local - number of local register |
addAStore | public void addAStore(int local)(Code) | | Store object from stack top into the given local.
Parameters: local - number of local register |
addDLoad | public void addDLoad(int local)(Code) | | Load double from the given local into stack.
Parameters: local - number of local register |
addDStore | public void addDStore(int local)(Code) | | Store double from stack top into the given local.
Parameters: local - number of local register |
addExceptionHandler | public void addExceptionHandler(int startLabel, int endLabel, int handlerLabel, String catchClassName)(Code) | | |
addFLoad | public void addFLoad(int local)(Code) | | Load float from the given local into stack.
Parameters: local - number of local register |
addFStore | public void addFStore(int local)(Code) | | Store float from stack top into the given local.
Parameters: local - number of local register |
addField | public void addField(String fieldName, String type, short flags)(Code) | | Add a field to the class.
Parameters: fieldName - the name of the field Parameters: type - the type of the field using ... Parameters: flags - the attributes of the field, such as ACC_PUBLIC, etc.bitwise or'd together |
addField | public void addField(String fieldName, String type, short flags, int value)(Code) | | Add a field to the class.
Parameters: fieldName - the name of the field Parameters: type - the type of the field using ... Parameters: flags - the attributes of the field, such as ACC_PUBLIC, etc.bitwise or'd together Parameters: value - an initial integral value |
addField | public void addField(String fieldName, String type, short flags, long value)(Code) | | Add a field to the class.
Parameters: fieldName - the name of the field Parameters: type - the type of the field using ... Parameters: flags - the attributes of the field, such as ACC_PUBLIC, etc.bitwise or'd together Parameters: value - an initial long value |
addField | public void addField(String fieldName, String type, short flags, double value)(Code) | | Add a field to the class.
Parameters: fieldName - the name of the field Parameters: type - the type of the field using ... Parameters: flags - the attributes of the field, such as ACC_PUBLIC, etc.bitwise or'd together Parameters: value - an initial double value |
addILoad | public void addILoad(int local)(Code) | | Load integer from the given local into stack.
Parameters: local - number of local register |
addIStore | public void addIStore(int local)(Code) | | Store integer from stack top into the given local.
Parameters: local - number of local register |
addInterface | public void addInterface(String interfaceName)(Code) | | Add an interface implemented by this class.
This method may be called multiple times for classes that
implement multiple interfaces.
Parameters: interfaceName - a name of an interface implementedby the class being written, including full packagequalification. |
addLLoad | public void addLLoad(int local)(Code) | | Load long from the given local into stack.
Parameters: local - number of local register |
addLStore | public void addLStore(int local)(Code) | | Store long from stack top into the given local.
Parameters: local - number of local register |
addLineNumberEntry | public void addLineNumberEntry(short lineNumber)(Code) | | |
addLoadConstant | public void addLoadConstant(int k)(Code) | | Generate the load constant bytecode for the given integer.
Parameters: k - the constant |
addLoadConstant | public void addLoadConstant(long k)(Code) | | Generate the load constant bytecode for the given long.
Parameters: k - the constant |
addLoadConstant | public void addLoadConstant(float k)(Code) | | Generate the load constant bytecode for the given float.
Parameters: k - the constant |
addLoadConstant | public void addLoadConstant(double k)(Code) | | Generate the load constant bytecode for the given double.
Parameters: k - the constant |
addLoadConstant | public void addLoadConstant(String k)(Code) | | Generate the load constant bytecode for the given string.
Parameters: k - the constant |
addLoadThis | public void addLoadThis()(Code) | | Load "this" into stack.
|
addPush | public void addPush(int k)(Code) | | Generate code to load the given integer on stack.
Parameters: k - the constant |
addPush | public void addPush(boolean k)(Code) | | |
addPush | public void addPush(long k)(Code) | | Generate code to load the given long on stack.
Parameters: k - the constant |
addPush | public void addPush(double k)(Code) | | Generate code to load the given double on stack.
Parameters: k - the constant |
addPush | public void addPush(String k)(Code) | | Generate the code to leave on stack the given string even if the
string encoding exeeds the class file limit for single string constant
Parameters: k - the constant |
addTableSwitch | public int addTableSwitch(int low, int high)(Code) | | |
addVariableDescriptor | public void addVariableDescriptor(String name, String type, int startPC, int register)(Code) | | Add Information about java variable to use when generating the local
variable table.
Parameters: name - variable name. Parameters: type - variable type as bytecode descriptor string. Parameters: startPC - the starting bytecode PC where this variable is live,or -1 if it does not have a Java register. Parameters: register - the Java register number of variableor -1 if it does not have a Java register. |
adjustStackTop | public void adjustStackTop(int delta)(Code) | | |
classNameToSignature | public static String classNameToSignature(String name)(Code) | | Convert Java class name in dot notation into
"Lname-with-dots-replaced-by-slashes;" form suitable for use as
JVM type signatures.
|
getCharBuffer | final char[] getCharBuffer(int minimalSize)(Code) | | |
getCurrentCodeOffset | public int getCurrentCodeOffset()(Code) | | Get the current offset into the code of the current method.
an integer representing the offset |
getStackTop | public short getStackTop()(Code) | | |
isUnderStringSizeLimit | public boolean isUnderStringSizeLimit(String k)(Code) | | Check if k fits limit on string constant size imposed by class file
format.
Parameters: k - the string constant |
markHandler | public void markHandler(int theLabel)(Code) | | |
markLabel | public void markLabel(int label)(Code) | | |
markLabel | public void markLabel(int label, short stackTop)(Code) | | |
markTableSwitchCase | final public void markTableSwitchCase(int switchStart, int caseIndex)(Code) | | |
markTableSwitchCase | final public void markTableSwitchCase(int switchStart, int caseIndex, int stackTop)(Code) | | |
markTableSwitchDefault | final public void markTableSwitchDefault(int switchStart)(Code) | | |
opcodeCount | static int opcodeCount(int opcode)(Code) | | Number of operands accompanying the opcode.
|
putInt16 | static int putInt16(int value, byte[] array, int offset)(Code) | | |
putInt32 | static int putInt32(int value, byte[] array, int offset)(Code) | | |
putInt64 | static int putInt64(long value, byte[] array, int offset)(Code) | | |
setFlags | public void setFlags(short flags)(Code) | | Set the class's flags.
Flags must be a set of the following flags, bitwise or'd
together:
ACC_PUBLIC
ACC_PRIVATE
ACC_PROTECTED
ACC_FINAL
ACC_ABSTRACT
TODO: check that this is the appropriate set
Parameters: flags - the set of class flags to set |
setStackTop | public void setStackTop(short n)(Code) | | |
setTableSwitchJump | public void setTableSwitchJump(int switchStart, int caseIndex, int jumpTarget)(Code) | | |
stackChange | static int stackChange(int opcode)(Code) | | The effect on the operand stack of a given opcode.
|
startMethod | public void startMethod(String methodName, String type, short flags)(Code) | | Add a method and begin adding code.
This method must be called before other methods for adding code,
exception tables, etc. can be invoked.
Parameters: methodName - the name of the method Parameters: type - a string representing the type Parameters: flags - the attributes of the field, such as ACC_PUBLIC, etc.bitwise or'd together |
stopMethod | public void stopMethod(short maxLocals)(Code) | | Complete generation of the method.
After this method is called, no more code can be added to the
method begun with startMethod .
Parameters: maxLocals - the maximum number of local variable slots(a.k.a. Java registers) used by the method |
toByteArray | public byte[] toByteArray()(Code) | | Get the class file as array of bytesto the OutputStream.
|
write | public void write(OutputStream oStream) throws IOException(Code) | | Write the class file to the OutputStream.
Parameters: oStream - the stream to write to throws: IOException - if writing to the stream produces an exception |
|
|