Package javassist.bytecode
Class ClassFileWriter.MethodWriter
- java.lang.Object
-
- javassist.bytecode.ClassFileWriter.MethodWriter
-
- Enclosing class:
- ClassFileWriter
public static final class ClassFileWriter.MethodWriter extends java.lang.Object
Method.
-
-
Field Summary
Fields Modifier and Type Field Description private int
catchCount
private int
catchPos
protected int
codeIndex
protected ClassFileWriter.ConstPoolWriter
constPool
private boolean
isAbstract
private int
methodCount
protected ByteStream
output
protected int
stackIndex
private int
startPos
protected int
throwsIndex
-
Constructor Summary
Constructors Constructor Description MethodWriter(ClassFileWriter.ConstPoolWriter cp)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int b)
Appends an 8bit value of bytecode.void
add16(int b)
Appends a 16bit value of bytecode.void
add32(int b)
Appends a 32bit value of bytecode.void
addCatch(int startPc, int endPc, int handlerPc, int catchType)
Appends anexception_table
entry to theCode_attribute
.void
addInvoke(int opcode, java.lang.String targetClass, java.lang.String methodName, java.lang.String descriptor)
Appends a invokevirtual, inovkespecial, or invokestatic bytecode.void
begin(int accessFlags, int name, int descriptor, int[] exceptions, ClassFileWriter.AttributeWriter aw)
Starts adding a new method.void
begin(int accessFlags, java.lang.String name, java.lang.String descriptor, java.lang.String[] exceptions, ClassFileWriter.AttributeWriter aw)
Starts Adding a new method.void
codeEnd(int maxStack, int maxLocals)
Ends appending bytecode.(package private) int
dataSize()
void
end(StackMapTable.Writer smap, ClassFileWriter.AttributeWriter aw)
Ends adding a new method.(package private) int
numOfMethods()
int
size()
Returns the length of the bytecode that has been added so far.(package private) void
write(java.io.OutputStream out)
Writes the added methods.private void
writeThrows(int[] exceptions)
-
-
-
Field Detail
-
output
protected ByteStream output
-
constPool
protected ClassFileWriter.ConstPoolWriter constPool
-
methodCount
private int methodCount
-
codeIndex
protected int codeIndex
-
throwsIndex
protected int throwsIndex
-
stackIndex
protected int stackIndex
-
startPos
private int startPos
-
isAbstract
private boolean isAbstract
-
catchPos
private int catchPos
-
catchCount
private int catchCount
-
-
Constructor Detail
-
MethodWriter
MethodWriter(ClassFileWriter.ConstPoolWriter cp)
-
-
Method Detail
-
begin
public void begin(int accessFlags, java.lang.String name, java.lang.String descriptor, java.lang.String[] exceptions, ClassFileWriter.AttributeWriter aw)
Starts Adding a new method.- Parameters:
accessFlags
- access flags.name
- the method name.descriptor
- the method signature.exceptions
- throws clause. It may be null. The class names must be the JVM-internal representations likejava/lang/Exception
.aw
- attributes to theMethod_info
.
-
begin
public void begin(int accessFlags, int name, int descriptor, int[] exceptions, ClassFileWriter.AttributeWriter aw)
Starts adding a new method.- Parameters:
accessFlags
- access flags.name
- the method name. an index indicating itsCONSTANT_Utf8_info
.descriptor
- the field type. an index indicating itsCONSTANT_Utf8_info
.exceptions
- throws clause. indexes indicatingCONSTANT_Class_info
s. It may be null.aw
- attributes to theMethod_info
.
-
writeThrows
private void writeThrows(int[] exceptions)
-
add
public void add(int b)
Appends an 8bit value of bytecode.- See Also:
Opcode
-
add16
public void add16(int b)
Appends a 16bit value of bytecode.
-
add32
public void add32(int b)
Appends a 32bit value of bytecode.
-
addInvoke
public void addInvoke(int opcode, java.lang.String targetClass, java.lang.String methodName, java.lang.String descriptor)
Appends a invokevirtual, inovkespecial, or invokestatic bytecode.- See Also:
Opcode
-
codeEnd
public void codeEnd(int maxStack, int maxLocals)
Ends appending bytecode.
-
addCatch
public void addCatch(int startPc, int endPc, int handlerPc, int catchType)
Appends anexception_table
entry to theCode_attribute
. This method is available only after thecodeEnd
method is called.- Parameters:
catchType
- an index indicating aCONSTANT_Class_info
.
-
end
public void end(StackMapTable.Writer smap, ClassFileWriter.AttributeWriter aw)
Ends adding a new method. Theadd
method must be called before theend
method is called.- Parameters:
smap
- a stack map table. may be null.aw
- attributes to theCode_attribute
. may be null.
-
size
public int size()
Returns the length of the bytecode that has been added so far.- Returns:
- the length in bytes.
- Since:
- 3.19
-
numOfMethods
int numOfMethods()
-
dataSize
int dataSize()
-
write
void write(java.io.OutputStream out) throws java.io.IOException
Writes the added methods.- Throws:
java.io.IOException
-
-