public class MethodGen extends FieldGenOrMethodGen
InstructionList
,
Method
annotationList, cp, name, type
Constructor and Description |
---|
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,
ConstantPool cp)
Declare method.
|
MethodGen(Method m,
java.lang.String class_name,
ConstantPool cp)
Instantiate from existing method.
|
MethodGen(Method m,
java.lang.String class_name,
ConstantPool cp,
boolean useTags) |
Modifier and Type | Method and Description |
---|---|
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.
|
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) |
void |
addParameterAnnotation(int parameterIndex,
AnnotationGen annotation) |
void |
addParameterAnnotationsAsAttribute(ConstantPool cp) |
java.util.List<AnnotationGen> |
getAnnotationsOnParameter(int i)
Return a list of AnnotationGen objects representing parameter annotations
|
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() |
int |
getHighestlinenumber() |
InstructionList |
getInstructionList() |
LineNumberGen[] |
getLineNumbers() |
LineNumberTable |
getLineNumberTable(ConstantPool cp) |
LocalVariableGen[] |
getLocalVariables() |
LocalVariableTable |
getLocalVariableTable(ConstantPool cp) |
int |
getMaxLocals() |
int |
getMaxStack() |
static int |
getMaxStack(ConstantPool cp,
InstructionList il,
CodeExceptionGen[] et)
Computes stack usage of an instruction list by performing control flow analysis.
|
Method |
getMethod()
Get method object.
|
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 |
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 based on the parameter count and bytecode usage of variables.
|
void |
setMaxLocals(boolean respectLocalVariableTable)
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) |
java.lang.String |
toString()
Return string representation close to declaration format, `public static void main(String[]) throws IOException', e.g.
|
addAnnotation, addAnnotationsAsAttribute, addAttribute, getAnnotations, getAttributes, getAttributesImmutable, getConstantPool, getName, getType, removeAnnotation, removeAnnotations, removeAttribute, removeAttributes, setConstantPool, setName, setType
getModifiers, isAbstract, isBridge, isFinal, isInterface, isNative, isPrivate, isProtected, isPublic, isStatic, isStrictfp, isSynchronized, isTransient, isVarargs, isVolatile, setModifiers
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, ConstantPool 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, ConstantPool cp)
m
- methodclass_name
- class name containing this methodcp
- constant poolpublic MethodGen(Method m, java.lang.String class_name, ConstantPool cp, boolean useTags)
public int getHighestlinenumber()
public LocalVariableGen addLocalVariable(java.lang.String name, Type type, int slot, InstructionHandle start, InstructionHandle end)
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(ConstantPool 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(ConstantPool 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 handledpublic 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 addParameterAnnotationsAsAttribute(ConstantPool cp)
public void removeCodeAttribute(Attribute a)
public void removeCodeAttributes()
public Attribute[] getCodeAttributes()
public Method getMethod()
public void setMaxLocals(int m)
public int getMaxLocals()
public void setMaxStack(int m)
public int getMaxStack()
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 InstructionList getInstructionList()
public void setInstructionList(InstructionList il)
public java.lang.String getSignature()
getSignature
in class FieldGenOrMethodGen
public void setMaxStack()
public void setMaxLocals()
public void setMaxLocals(boolean respectLocalVariableTable)
respectLocalVariableTable
- if true and the local variable table indicates more are in use
than the code suggests, respect the higher value from the local variable table data.public void stripAttributes(boolean flag)
public static int getMaxStack(ConstantPool cp, InstructionList il, CodeExceptionGen[] et)
public final java.lang.String toString()
toString
in class java.lang.Object
public java.util.List<AnnotationGen> getAnnotationsOnParameter(int i)
public void addParameterAnnotation(int parameterIndex, AnnotationGen annotation)