public class ClassFileWriter
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ClassFileWriter.ClassFileFormatException
Thrown for cases where the error in generating the class file is
due to a program size constraints rather than a likely bug in the
compiler.
|
Modifier and Type | Field and Description |
---|---|
static short |
ACC_ABSTRACT |
static short |
ACC_FINAL |
static short |
ACC_NATIVE |
static short |
ACC_PRIVATE |
static short |
ACC_PROTECTED |
static short |
ACC_PUBLIC |
static short |
ACC_STATIC |
static short |
ACC_SUPER |
static short |
ACC_SYNCHRONIZED |
static short |
ACC_TRANSIENT |
static short |
ACC_VOLATILE |
Constructor and Description |
---|
ClassFileWriter(java.lang.String className,
java.lang.String superClassName,
java.lang.String sourceFileName)
Construct a ClassFileWriter for a class.
|
Modifier and Type | Method and Description |
---|---|
int |
acquireLabel() |
void |
add(int theOpCode)
Add the single-byte opcode to the current method.
|
void |
add(int theOpCode,
int theOperand)
Add a single-operand opcode to the current method.
|
void |
add(int theOpCode,
int theOperand1,
int theOperand2)
Add the given two-operand bytecode to the current method.
|
void |
add(int theOpCode,
java.lang.String className) |
void |
add(int theOpCode,
java.lang.String className,
java.lang.String fieldName,
java.lang.String fieldType) |
void |
addALoad(int local)
Load object from the given local into stack.
|
void |
addAStore(int local)
Store object from stack top into the given local.
|
void |
addDLoad(int local)
Load double from the given local into stack.
|
void |
addDStore(int local)
Store double from stack top into the given local.
|
void |
addExceptionHandler(int startLabel,
int endLabel,
int handlerLabel,
java.lang.String catchClassName) |
void |
addField(java.lang.String fieldName,
java.lang.String type,
short flags)
Add a field to the class.
|
void |
addField(java.lang.String fieldName,
java.lang.String type,
short flags,
double value)
Add a field to the class.
|
void |
addField(java.lang.String fieldName,
java.lang.String type,
short flags,
int value)
Add a field to the class.
|
void |
addField(java.lang.String fieldName,
java.lang.String type,
short flags,
long value)
Add a field to the class.
|
void |
addFLoad(int local)
Load float from the given local into stack.
|
void |
addFStore(int local)
Store float from stack top into the given local.
|
void |
addILoad(int local)
Load integer from the given local into stack.
|
void |
addInterface(java.lang.String interfaceName)
Add an interface implemented by this class.
|
void |
addInvoke(int theOpCode,
java.lang.String className,
java.lang.String methodName,
java.lang.String methodType) |
void |
addIStore(int local)
Store integer from stack top into the given local.
|
void |
addLineNumberEntry(short lineNumber) |
void |
addLLoad(int local)
Load long from the given local into stack.
|
void |
addLoadConstant(double k)
Generate the load constant bytecode for the given double.
|
void |
addLoadConstant(float k)
Generate the load constant bytecode for the given float.
|
void |
addLoadConstant(int k)
Generate the load constant bytecode for the given integer.
|
void |
addLoadConstant(long k)
Generate the load constant bytecode for the given long.
|
void |
addLoadConstant(java.lang.String k)
Generate the load constant bytecode for the given string.
|
void |
addLoadThis()
Load "this" into stack.
|
void |
addLStore(int local)
Store long from stack top into the given local.
|
void |
addPush(boolean k) |
void |
addPush(double k)
Generate code to load the given double on stack.
|
void |
addPush(int k)
Generate code to load the given integer on stack.
|
void |
addPush(long k)
Generate code to load the given long on stack.
|
void |
addPush(java.lang.String k)
Generate the code to leave on stack the given string even if the
string encoding exeeds the class file limit for single string constant
|
int |
addTableSwitch(int low,
int high) |
void |
addVariableDescriptor(java.lang.String name,
java.lang.String type,
int startPC,
int register)
Add Information about java variable to use when generating the local
variable table.
|
void |
adjustStackTop(int delta) |
static java.lang.String |
classNameToSignature(java.lang.String name)
Convert Java class name in dot notation into
"Lname-with-dots-replaced-by-slashes;" form suitable for use as
JVM type signatures.
|
java.lang.String |
getClassName() |
int |
getCurrentCodeOffset()
Get the current offset into the code of the current method.
|
int |
getLabelPC(int label) |
short |
getStackTop() |
boolean |
isUnderStringSizeLimit(java.lang.String k)
Check if k fits limit on string constant size imposed by class file
format.
|
void |
markHandler(int theLabel) |
void |
markLabel(int label) |
void |
markLabel(int label,
short stackTop) |
void |
markTableSwitchCase(int switchStart,
int caseIndex) |
void |
markTableSwitchCase(int switchStart,
int caseIndex,
int stackTop) |
void |
markTableSwitchDefault(int switchStart) |
void |
setFlags(short flags)
Set the class's flags.
|
void |
setStackTop(short n) |
void |
setTableSwitchJump(int switchStart,
int caseIndex,
int jumpTarget)
Set a jump case for a tableswitch instruction.
|
void |
startMethod(java.lang.String methodName,
java.lang.String type,
short flags)
Add a method and begin adding code.
|
void |
stopMethod(short maxLocals)
Complete generation of the method.
|
byte[] |
toByteArray()
Get the class file as array of bytesto the OutputStream.
|
void |
write(java.io.OutputStream oStream)
Write the class file to the OutputStream.
|
public static final short ACC_PUBLIC
public static final short ACC_PRIVATE
public static final short ACC_PROTECTED
public static final short ACC_STATIC
public static final short ACC_FINAL
public static final short ACC_SUPER
public static final short ACC_SYNCHRONIZED
public static final short ACC_VOLATILE
public static final short ACC_TRANSIENT
public static final short ACC_NATIVE
public static final short ACC_ABSTRACT
public ClassFileWriter(java.lang.String className, java.lang.String superClassName, java.lang.String sourceFileName)
className
- the name of the class to write, including
full package qualification.superClassName
- the name of the superclass of the class
to write, including full package qualification.sourceFileName
- the name of the source file to use for
producing debug information, or null if debug information
is not desiredpublic final java.lang.String getClassName()
public void addInterface(java.lang.String interfaceName)
interfaceName
- a name of an interface implemented
by the class being written, including full package
qualification.public void setFlags(short flags)
flags
- the set of class flags to setpublic static java.lang.String classNameToSignature(java.lang.String name)
public void addField(java.lang.String fieldName, java.lang.String type, short flags)
fieldName
- the name of the fieldtype
- the type of the field using ...flags
- the attributes of the field, such as ACC_PUBLIC, etc.
bitwise or'd togetherpublic void addField(java.lang.String fieldName, java.lang.String type, short flags, int value)
fieldName
- the name of the fieldtype
- the type of the field using ...flags
- the attributes of the field, such as ACC_PUBLIC, etc.
bitwise or'd togethervalue
- an initial integral valuepublic void addField(java.lang.String fieldName, java.lang.String type, short flags, long value)
fieldName
- the name of the fieldtype
- the type of the field using ...flags
- the attributes of the field, such as ACC_PUBLIC, etc.
bitwise or'd togethervalue
- an initial long valuepublic void addField(java.lang.String fieldName, java.lang.String type, short flags, double value)
fieldName
- the name of the fieldtype
- the type of the field using ...flags
- the attributes of the field, such as ACC_PUBLIC, etc.
bitwise or'd togethervalue
- an initial double valuepublic void addVariableDescriptor(java.lang.String name, java.lang.String type, int startPC, int register)
name
- variable name.type
- variable type as bytecode descriptor string.startPC
- the starting bytecode PC where this variable is live,
or -1 if it does not have a Java register.register
- the Java register number of variable
or -1 if it does not have a Java register.public void startMethod(java.lang.String methodName, java.lang.String type, short flags)
methodName
- the name of the methodtype
- a string representing the typeflags
- the attributes of the field, such as ACC_PUBLIC, etc.
bitwise or'd togetherpublic void stopMethod(short maxLocals)
startMethod
.maxLocals
- the maximum number of local variable slots
(a.k.a. Java registers) used by the methodpublic void add(int theOpCode)
theOpCode
- the opcode of the bytecodepublic void add(int theOpCode, int theOperand)
theOpCode
- the opcode of the bytecodetheOperand
- the operand of the bytecodepublic void addLoadConstant(int k)
k
- the constantpublic void addLoadConstant(long k)
k
- the constantpublic void addLoadConstant(float k)
k
- the constantpublic void addLoadConstant(double k)
k
- the constantpublic void addLoadConstant(java.lang.String k)
k
- the constantpublic void add(int theOpCode, int theOperand1, int theOperand2)
theOpCode
- the opcode of the bytecodetheOperand1
- the first operand of the bytecodetheOperand2
- the second operand of the bytecodepublic void add(int theOpCode, java.lang.String className)
public void add(int theOpCode, java.lang.String className, java.lang.String fieldName, java.lang.String fieldType)
public void addInvoke(int theOpCode, java.lang.String className, java.lang.String methodName, java.lang.String methodType)
public void addPush(int k)
k
- the constantpublic void addPush(boolean k)
public void addPush(long k)
k
- the constantpublic void addPush(double k)
k
- the constantpublic void addPush(java.lang.String k)
k
- the constantpublic boolean isUnderStringSizeLimit(java.lang.String k)
k
- the string constantpublic void addIStore(int local)
local
- number of local registerpublic void addLStore(int local)
local
- number of local registerpublic void addFStore(int local)
local
- number of local registerpublic void addDStore(int local)
local
- number of local registerpublic void addAStore(int local)
local
- number of local registerpublic void addILoad(int local)
local
- number of local registerpublic void addLLoad(int local)
local
- number of local registerpublic void addFLoad(int local)
local
- number of local registerpublic void addDLoad(int local)
local
- number of local registerpublic void addALoad(int local)
local
- number of local registerpublic void addLoadThis()
public int addTableSwitch(int low, int high)
public final void markTableSwitchDefault(int switchStart)
public final void markTableSwitchCase(int switchStart, int caseIndex)
public final void markTableSwitchCase(int switchStart, int caseIndex, int stackTop)
public void setTableSwitchJump(int switchStart, int caseIndex, int jumpTarget)
public int acquireLabel()
public void markLabel(int label)
public void markLabel(int label, short stackTop)
public void markHandler(int theLabel)
public int getLabelPC(int label)
public int getCurrentCodeOffset()
public short getStackTop()
public void setStackTop(short n)
public void adjustStackTop(int delta)
public void addExceptionHandler(int startLabel, int endLabel, int handlerLabel, java.lang.String catchClassName)
public void addLineNumberEntry(short lineNumber)
public void write(java.io.OutputStream oStream) throws java.io.IOException
oStream
- the stream to write tojava.io.IOException
- if writing to the stream produces an exceptionpublic byte[] toByteArray()
Copyright © 2010 - 2020 Adobe. All Rights Reserved