|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--de.fub.bytecode.classfile.AccessFlags | +--de.fub.bytecode.generic.FieldGenOrMethodGen | +--de.fub.bytecode.generic.MethodGen
Template class for building up a method. This is done by defining exception handlers, adding thrown exceptions, local variables and attributes, whereas the `LocalVariableTable' and `LineNumberTable' attributes will be set automatically for the code. Use stripAttributes() if you don't like this. While generating code it may be necessary to insert NOP operations. You can use the `removeNOPs' method to get rid off them. The resulting method object can be obtained via the `getMethod()' method.
InstructionList
,
Method
Fields inherited from class de.fub.bytecode.generic.FieldGenOrMethodGen |
cp, name, type |
Fields inherited from class de.fub.bytecode.classfile.AccessFlags |
access_flags |
Constructor Summary | |
MethodGen(int access_flags,
Type return_type,
Type[] arg_types,
java.lang.String[] arg_names,
java.lang.String method_name,
java.lang.String class_name,
InstructionList il,
ConstantPoolGen cp)
Declare method. |
|
MethodGen(Method m,
java.lang.String class_name,
ConstantPoolGen cp)
Instantiate from existing method. |
Method Summary | |
void |
addCodeAttribute(Attribute a)
Add an attribute to the code. |
void |
addException(java.lang.String class_name)
Add an exception possibly thrown by this method. |
CodeExceptionGen |
addExceptionHandler(InstructionHandle start_pc,
InstructionHandle end_pc,
InstructionHandle handler_pc,
ObjectType catch_type)
Add an exception handler, i.e., specify region where a handler is active and an instruction where the actual handling is done. |
CodeExceptionGen |
addExceptionHandler(InstructionHandle start_pc,
InstructionHandle end_pc,
InstructionHandle handler_pc,
java.lang.String catch_type)
Deprecated. Use above method |
LineNumberGen |
addLineNumber(InstructionHandle ih,
int src_line)
Give an instruction a line number corresponding to the source code line. |
LocalVariableGen |
addLocalVariable(java.lang.String name,
Type type,
InstructionHandle start,
InstructionHandle end)
Adds a local variable to this method and assigns an index automatically. |
LocalVariableGen |
addLocalVariable(java.lang.String name,
Type type,
int slot,
InstructionHandle start,
InstructionHandle end)
Adds a local variable to this method. |
void |
addObserver(MethodObserver o)
Add observer for this object. |
MethodGen |
copy(java.lang.String class_name,
ConstantPoolGen cp)
|
java.lang.String |
getArgName(int i)
Deprecated. because of its ugly name |
java.lang.String[] |
getArgNames()
Deprecated. because of its ugly name |
Type |
getArgType(int i)
Deprecated. because of its ugly name |
Type[] |
getArgTypes()
Deprecated. because of its ugly name |
java.lang.String |
getArgumentName(int i)
|
java.lang.String[] |
getArgumentNames()
|
Type |
getArgumentType(int i)
|
Type[] |
getArgumentTypes()
|
java.lang.String |
getClassName()
|
Attribute[] |
getCodeAttributes()
|
CodeExceptionGen[] |
getExceptionHandlers()
|
java.lang.String[] |
getExceptions()
|
InstructionList |
getInstructionList()
|
LineNumberGen[] |
getLineNumbers()
|
LineNumberTable |
getLineNumberTable(ConstantPoolGen cp)
|
LocalVariableGen[] |
getLocalVariables()
|
LocalVariableTable |
getLocalVariableTable(ConstantPoolGen cp)
|
int |
getMaxLocals()
|
int |
getMaxStack()
|
static int |
getMaxStack(ConstantPoolGen cp,
InstructionList il,
CodeExceptionGen[] et)
Computes stack usage of an instruction list by performing control flow analysis. |
Method |
getMethod()
Get method object. |
java.lang.String |
getMethodName()
Deprecated. Use getName() |
java.lang.String |
getMethodSignature()
Deprecated. Use getSignature() |
Type |
getReturnType()
|
java.lang.String |
getSignature()
|
void |
removeCodeAttribute(Attribute a)
Remove a code attribute. |
void |
removeCodeAttributes()
Remove all code attributes. |
void |
removeException(java.lang.String c)
Remove an exception. |
void |
removeExceptionHandler(CodeExceptionGen c)
Remove an exception handler. |
void |
removeExceptionHandlers()
Remove all line numbers. |
void |
removeExceptions()
Remove all exceptions. |
void |
removeLineNumber(LineNumberGen l)
Remove a line number. |
void |
removeLineNumbers()
Remove all line numbers. |
void |
removeLocalVariable(LocalVariableGen l)
Remove a local variable, its slot will not be reused, if you do not use addLocalVariable with an explicit index argument. |
void |
removeLocalVariables()
Remove all local variables. |
void |
removeNOPs()
Remove all NOPs from the instruction list (if possible) and update every object refering to them, i.e., branch instructions, local variables and exception handlers. |
void |
removeObserver(MethodObserver o)
Remove observer for this object. |
void |
setArgName(int i,
java.lang.String name)
Deprecated. because of its ugly name |
void |
setArgNames(java.lang.String[] arg_names)
Deprecated. because of its ugly name |
void |
setArgType(int i,
Type type)
Deprecated. because of its ugly name |
void |
setArgTypes(Type[] arg_types)
Deprecated. because of its ugly name |
void |
setArgumentName(int i,
java.lang.String name)
|
void |
setArgumentNames(java.lang.String[] arg_names)
|
void |
setArgumentType(int i,
Type type)
|
void |
setArgumentTypes(Type[] arg_types)
|
void |
setClassName(java.lang.String class_name)
|
void |
setInstructionList(InstructionList il)
|
void |
setMaxLocals()
Compute maximum number of local variables. |
void |
setMaxLocals(int m)
Set maximum number of local variables. |
void |
setMaxStack()
Computes max. |
void |
setMaxStack(int m)
Set maximum stack size for this method. |
void |
setMethodName(java.lang.String method_name)
Deprecated. Use setName() |
void |
setReturnType(Type return_type)
|
void |
stripAttributes(boolean flag)
Do not/Do produce attributes code attributesLineNumberTable and LocalVariableTable, like javac -O |
java.lang.String |
toString()
Return string representation close to declaration format, `public static void main(String[]) throws IOException', e.g. |
void |
update()
Call notify() method on all observers. |
Methods inherited from class de.fub.bytecode.generic.FieldGenOrMethodGen |
addAttribute, clone, getAttributes, getConstantPool, getName, getType, removeAttribute, removeAttributes, setConstantPool, setName, setType |
Methods inherited from class de.fub.bytecode.classfile.AccessFlags |
getAccessFlags, isAbstract, isAbstract, isFinal, isFinal, isInterface, isInterface, isNative, isNative, isPrivate, isPrivate, isProtected, isProtected, isPublic, isPublic, isStatic, isStatic, isStrictfp, isStrictfp, isSynchronized, isSynchronized, isTransient, isTransient, isVolatile, isVolatile, setAccessFlags |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public MethodGen(int access_flags, Type return_type, Type[] arg_types, java.lang.String[] arg_names, java.lang.String method_name, java.lang.String class_name, InstructionList il, ConstantPoolGen cp)
access_flags
- access qualifiersreturn_type
- method typearg_types
- argument typesarg_names
- argument names (if this is null, default names will be provided
for them)method_name
- name of methodclass_name
- class name containing this method (may be null, if you don't care)il
- instruction list associated with this method, may be null only for
abstract or native methodscp
- constant poolpublic MethodGen(Method m, java.lang.String class_name, ConstantPoolGen cp)
m
- methodclass_name
- class name containing this methodcp
- constant poolMethod Detail |
public LocalVariableGen addLocalVariable(java.lang.String name, Type type, int slot, InstructionHandle start, InstructionHandle end)
name
- variable nametype
- variable typeslot
- the index of the local variable, if type is long or double, the next available
index is slot+2start
- from where the variable is validend
- until where the variable is validLocalVariable
public LocalVariableGen addLocalVariable(java.lang.String name, Type type, InstructionHandle start, InstructionHandle end)
name
- variable nametype
- variable typestart
- from where the variable is valid, if this is null,
it is valid from the startend
- until where the variable is valid, if this is null,
it is valid to the endLocalVariable
public void removeLocalVariable(LocalVariableGen l)
public void removeLocalVariables()
public LocalVariableGen[] getLocalVariables()
public LocalVariableTable getLocalVariableTable(ConstantPoolGen cp)
public LineNumberGen addLineNumber(InstructionHandle ih, int src_line)
ih
- instruction to tagLineNumber
public void removeLineNumber(LineNumberGen l)
public void removeLineNumbers()
public LineNumberGen[] getLineNumbers()
public LineNumberTable getLineNumberTable(ConstantPoolGen cp)
public CodeExceptionGen addExceptionHandler(InstructionHandle start_pc, InstructionHandle end_pc, InstructionHandle handler_pc, ObjectType catch_type)
start_pc
- Start of region (inclusive)end_pc
- End of region (inclusive)handler_pc
- Where handling is donecatch_type
- fully qualified class name of handled exception or null if any
exception is handledpublic CodeExceptionGen addExceptionHandler(InstructionHandle start_pc, InstructionHandle end_pc, InstructionHandle handler_pc, java.lang.String catch_type)
public void removeExceptionHandler(CodeExceptionGen c)
public void removeExceptionHandlers()
public CodeExceptionGen[] getExceptionHandlers()
public void addException(java.lang.String class_name)
class_name
- (fully qualified) name of exceptionpublic void removeException(java.lang.String c)
public void removeExceptions()
public java.lang.String[] getExceptions()
public void addCodeAttribute(Attribute a)
a
- attribute to be addedpublic void removeCodeAttribute(Attribute a)
public void removeCodeAttributes()
public Attribute[] getCodeAttributes()
public Method getMethod()
public void removeNOPs()
public void setMaxLocals(int m)
public int getMaxLocals()
public void setMaxStack(int m)
public int getMaxStack()
public void setMethodName(java.lang.String method_name)
public java.lang.String getMethodName()
public java.lang.String getClassName()
public void setClassName(java.lang.String class_name)
public void setReturnType(Type return_type)
public Type getReturnType()
public void setArgumentTypes(Type[] arg_types)
public Type[] getArgumentTypes()
public void setArgumentType(int i, Type type)
public Type getArgumentType(int i)
public void setArgumentNames(java.lang.String[] arg_names)
public java.lang.String[] getArgumentNames()
public void setArgumentName(int i, java.lang.String name)
public java.lang.String getArgumentName(int i)
public void setArgTypes(Type[] arg_types)
public Type[] getArgTypes()
public void setArgType(int i, Type type)
public Type getArgType(int i)
public void setArgNames(java.lang.String[] arg_names)
public java.lang.String[] getArgNames()
public void setArgName(int i, java.lang.String name)
public java.lang.String getArgName(int i)
public InstructionList getInstructionList()
public void setInstructionList(InstructionList il)
public java.lang.String getMethodSignature()
public java.lang.String getSignature()
getSignature
in class FieldGenOrMethodGen
de.fub.bytecode.generic.FieldGenOrMethodGen
public void setMaxStack()
public void setMaxLocals()
public void stripAttributes(boolean flag)
public static int getMaxStack(ConstantPoolGen cp, InstructionList il, CodeExceptionGen[] et)
public void addObserver(MethodObserver o)
public void removeObserver(MethodObserver o)
public void update()
public final java.lang.String toString()
toString
in class java.lang.Object
public MethodGen copy(java.lang.String class_name, ConstantPoolGen cp)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |