|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.bcel.classfile.AccessFlags org.apache.bcel.generic.FieldGenOrMethodGen org.apache.bcel.generic.MethodGen
public class 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
,
Serialized FormField Summary |
---|
Fields inherited from class org.apache.bcel.generic.FieldGenOrMethodGen |
---|
cp, name, type |
Fields inherited from class org.apache.bcel.classfile.AccessFlags |
---|
access_flags |
Constructor Summary | |
---|---|
MethodGen(int access_flags,
Type return_type,
Type[] arg_types,
String[] arg_names,
String method_name,
String class_name,
InstructionList il,
ConstantPoolGen cp)
Declare method. |
|
MethodGen(Method m,
String class_name,
ConstantPoolGen cp)
Instantiate from existing method. |
Method Summary | |
---|---|
void |
addCodeAttribute(Attribute a)
Add an attribute to the code. |
void |
addException(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. |
LineNumberGen |
addLineNumber(InstructionHandle ih,
int src_line)
Give an instruction a line number corresponding to the source code line. |
LocalVariableGen |
addLocalVariable(String name,
Type type,
InstructionHandle start,
InstructionHandle end)
Adds a local variable to this method and assigns an index automatically. |
LocalVariableGen |
addLocalVariable(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(String class_name,
ConstantPoolGen cp)
|
boolean |
equals(Object obj)
Return value as defined by given BCELComparator strategy. |
String |
getArgumentName(int i)
|
String[] |
getArgumentNames()
|
Type |
getArgumentType(int i)
|
Type[] |
getArgumentTypes()
|
String |
getClassName()
|
Attribute[] |
getCodeAttributes()
|
static BCELComparator |
getComparator()
|
CodeExceptionGen[] |
getExceptionHandlers()
|
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. |
Type |
getReturnType()
|
String |
getSignature()
|
int |
hashCode()
Return value as defined by given BCELComparator strategy. |
void |
removeCodeAttribute(Attribute a)
Remove a code attribute. |
void |
removeCodeAttributes()
Remove all code attributes. |
void |
removeException(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 |
setArgumentName(int i,
String name)
|
void |
setArgumentNames(String[] arg_names)
|
void |
setArgumentType(int i,
Type type)
|
void |
setArgumentTypes(Type[] arg_types)
|
void |
setClassName(String class_name)
|
static void |
setComparator(BCELComparator comparator)
|
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 |
setReturnType(Type return_type)
|
void |
stripAttributes(boolean flag)
Do not/Do produce attributes code attributesLineNumberTable and LocalVariableTable, like javac -O |
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 org.apache.bcel.generic.FieldGenOrMethodGen |
---|
addAttribute, clone, getAttributes, getConstantPool, getName, getType, removeAttribute, removeAttributes, setConstantPool, setName, setType |
Methods inherited from class org.apache.bcel.classfile.AccessFlags |
---|
getAccessFlags, getModifiers, isAbstract, isAbstract, isAnnotation, isAnnotation, isEnum, isEnum, isFinal, isFinal, isInterface, isInterface, isNative, isNative, isPrivate, isPrivate, isProtected, isProtected, isPublic, isPublic, isStatic, isStatic, isStrictfp, isStrictfp, isSynchronized, isSynchronized, isSynthetic, isSynthetic, isTransient, isTransient, isVolatile, isVolatile, setAccessFlags, setModifiers |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public MethodGen(int access_flags, Type return_type, Type[] arg_types, String[] arg_names, String method_name, 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, String class_name, ConstantPoolGen cp)
m
- methodclass_name
- class name containing this methodcp
- constant poolMethod Detail |
---|
public LocalVariableGen addLocalVariable(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 valid
LocalVariable
public LocalVariableGen addLocalVariable(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 end
LocalVariable
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 tag
LineNumber
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
- class type of handled exception or null if any
exception is handled
public void removeExceptionHandler(CodeExceptionGen c)
public void removeExceptionHandlers()
public CodeExceptionGen[] getExceptionHandlers()
public void addException(String class_name)
class_name
- (fully qualified) name of exceptionpublic void removeException(String c)
public void removeExceptions()
public 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 String getClassName()
public void setClassName(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(String[] arg_names)
public String[] getArgumentNames()
public void setArgumentName(int i, String name)
public String getArgumentName(int i)
public InstructionList getInstructionList()
public void setInstructionList(InstructionList il)
public String getSignature()
getSignature
in class 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 String toString()
toString
in class Object
public MethodGen copy(String class_name, ConstantPoolGen cp)
public static BCELComparator getComparator()
public static void setComparator(BCELComparator comparator)
comparator
- Comparison strategy objectpublic boolean equals(Object obj)
equals
in class Object
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class Object
Object.hashCode()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |