public class MethodGen extends FieldGenOrMethodGen
InstructionList
,
Method
cp, name, type
access_flags
Constructor and Description |
---|
MethodGen(int accessFlags,
Type returnType,
Type[] argTypes,
String[] argNames,
String methodName,
String className,
InstructionList il,
ConstantPoolGen cp)
Declare method.
|
MethodGen(Method method,
String className,
ConstantPoolGen cp)
Instantiate from existing method.
|
Modifier and Type | Method and Description |
---|---|
void |
addAnnotationsAsAttribute(ConstantPoolGen cp) |
void |
addCodeAttribute(Attribute a)
Add an attribute to the code.
|
void |
addException(String className)
Add an exception possibly thrown by this method.
|
CodeExceptionGen |
addExceptionHandler(InstructionHandle startPc,
InstructionHandle endPc,
InstructionHandle handlerPc,
ObjectType catchType)
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 srcLine)
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.
|
LocalVariableGen |
addLocalVariable(String name,
Type type,
int slot,
InstructionHandle start,
InstructionHandle end,
int origIndex)
Adds a local variable to this method.
|
void |
addObserver(MethodObserver o)
Add observer for this object.
|
void |
addParameterAnnotation(int parameterIndex,
AnnotationEntryGen annotation) |
void |
addParameterAnnotationsAsAttribute(ConstantPoolGen cp) |
MethodGen |
copy(String className,
ConstantPoolGen cp) |
boolean |
equals(Object obj)
Return value as defined by given BCELComparator strategy.
|
List<AnnotationEntryGen> |
getAnnotationsOnParameter(int i)
Return a list of AnnotationGen objects representing parameter annotations
|
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) |
LocalVariableTypeTable |
getLocalVariableTypeTable() |
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 |
removeLocalVariableTypeTable()
Remove the LocalVariableTypeTable
|
void |
removeNOPs()
Remove all NOPs from the instruction list (if possible) and update every object referring to them, i.e., branch
instructions, local variables and exception handlers.
|
void |
removeObserver(MethodObserver o)
Remove observer for this object.
|
void |
removeRuntimeAttributes(Attribute[] attrs)
Would prefer to make this private, but need a way to test if client is using BCEL version 6.5.0 or later that
contains fix for BCEL-329.
|
void |
setArgumentName(int i,
String name) |
void |
setArgumentNames(String[] argNames) |
void |
setArgumentType(int i,
Type type) |
void |
setArgumentTypes(Type[] argTypes) |
void |
setClassName(String className) |
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 returnType) |
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.
|
addAll, addAnnotationEntry, addAttribute, clone, getAnnotationEntries, getAttributes, getConstantPool, getName, getType, removeAnnotationEntries, removeAnnotationEntry, removeAttribute, removeAttributes, setConstantPool, setName, setType
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, isVarArgs, isVarArgs, isVolatile, isVolatile, setAccessFlags, setModifiers
public MethodGen(int accessFlags, Type returnType, Type[] argTypes, String[] argNames, String methodName, String className, InstructionList il, ConstantPoolGen cp)
accessFlags
- access qualifiersreturnType
- method typeargTypes
- argument typesargNames
- argument names (if this is null, default names will be provided for them)methodName
- name of methodclassName
- 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 method, String className, ConstantPoolGen cp)
method
- methodclassName
- class name containing this methodcp
- constant poolpublic static BCELComparator getComparator()
public static int getMaxStack(ConstantPoolGen cp, InstructionList il, CodeExceptionGen[] et)
public static void setComparator(BCELComparator comparator)
comparator
- Comparison strategy objectpublic void addAnnotationsAsAttribute(ConstantPoolGen cp)
public void addCodeAttribute(Attribute a)
a
- attribute to be addedpublic void addException(String className)
className
- (fully qualified) name of exceptionpublic CodeExceptionGen addExceptionHandler(InstructionHandle startPc, InstructionHandle endPc, InstructionHandle handlerPc, ObjectType catchType)
startPc
- Start of region (inclusive)endPc
- End of region (inclusive)handlerPc
- Where handling is donecatchType
- class type of handled exception or null if any exception is handledpublic LineNumberGen addLineNumber(InstructionHandle ih, int srcLine)
ih
- instruction to tagLineNumber
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 endLocalVariable
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 validLocalVariable
public LocalVariableGen addLocalVariable(String name, Type type, int slot, InstructionHandle start, InstructionHandle end, int origIndex)
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 validorigIndex
- the index of the local variable prior to any modificationsLocalVariable
public void addObserver(MethodObserver o)
public void addParameterAnnotation(int parameterIndex, AnnotationEntryGen annotation)
public void addParameterAnnotationsAsAttribute(ConstantPoolGen cp)
public MethodGen copy(String className, ConstantPoolGen cp)
public boolean equals(Object obj)
equals
in class Object
Object.equals(Object)
public List<AnnotationEntryGen> getAnnotationsOnParameter(int i)
public String getArgumentName(int i)
public String[] getArgumentNames()
public Type getArgumentType(int i)
public Type[] getArgumentTypes()
public String getClassName()
public Attribute[] getCodeAttributes()
public CodeExceptionGen[] getExceptionHandlers()
public String[] getExceptions()
public InstructionList getInstructionList()
public LineNumberGen[] getLineNumbers()
public LineNumberTable getLineNumberTable(ConstantPoolGen cp)
public LocalVariableGen[] getLocalVariables()
public LocalVariableTable getLocalVariableTable(ConstantPoolGen cp)
public LocalVariableTypeTable getLocalVariableTypeTable()
public int getMaxLocals()
public int getMaxStack()
public Method getMethod()
public Type getReturnType()
public String getSignature()
getSignature
in class FieldGenOrMethodGen
public int hashCode()
hashCode
in class Object
Object.hashCode()
public void removeCodeAttribute(Attribute a)
public void removeCodeAttributes()
public void removeException(String c)
public void removeExceptionHandler(CodeExceptionGen c)
public void removeExceptionHandlers()
public void removeExceptions()
public void removeLineNumber(LineNumberGen l)
public void removeLineNumbers()
public void removeLocalVariable(LocalVariableGen l)
public void removeLocalVariables()
public void removeLocalVariableTypeTable()
public void removeNOPs()
public void removeObserver(MethodObserver o)
public void removeRuntimeAttributes(Attribute[] attrs)
public void setArgumentName(int i, String name)
public void setArgumentNames(String[] argNames)
public void setArgumentType(int i, Type type)
public void setArgumentTypes(Type[] argTypes)
public void setClassName(String className)
public void setInstructionList(InstructionList il)
public void setMaxLocals()
public void setMaxLocals(int m)
public void setMaxStack()
public void setMaxStack(int m)
public void setReturnType(Type returnType)
public void stripAttributes(boolean flag)
public final String toString()
public void update()
Copyright © 2004–2022 The Apache Software Foundation. All rights reserved.