jellyj.classfile.classgen
Class MethodGen


public final class MethodGen
implements Constants

Template class for building up a method. This is done by defining exception handlers, adding thrown exceptions, local variables and attributes, whereas the `LocalVariableTable' attribute will be set automatically for the code. 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.

Author:
JellyJ Design Group
See Also: Instruction, Method

Constructor Summary
MethodGen(int access_flags, ClassGenType return_type, ClassGenType[] arg_types, String[] arg_names, String method_name, String class_name, InstructionList il, ConstantPoolGen cp)
          Declare method.

Method Summary
 voidaddAttribute(Attribute attr)
          Add an attribute to this method.
 voidaddException(String class_name)
          Add an exception thrown by this method.
 voidaddExceptionHandler(InstructionHandle start_pc, InstructionHandle end_pc, InstructionHandle handler_pc, int catch_type)
          Add an exception handler, i.e.
 voidaddExceptionHandler(InstructionHandle start_pc, InstructionHandle end_pc, InstructionHandle handler_pc, String catch_type)
          Add an exception handler, i.e.
 LocalVariableGenaddLocalVariable(String name, ClassGenType type, InstructionHandle start, InstructionHandle end)
          Add a local variable to this method.
 intgetAccessFlags()
           
 ClassGenType[]getArgTypes()
           
 final Attribute[]getAttributes()
           
 StringgetClassName()
           
 final InstructionListgetInstructionList()
           
 final LocalVariableGen[]getLocalVariables()
           
 MethodgetMethod(int max_stack)
          Get method object.
 StringgetMethodName()
           
 ClassGenTypegetReturnType()
           
 LocalVariableGenlookupLocal(String name)
           
 final voidremoveNOPs()
          Remove all NOPs from the instruction list (if possible) and update every object refering to them, i.e.
 voidsetAccessFlags(short access_flags)
           
 voidsetArgTypes(ClassGenType[] arg_types)
           
 voidsetMethodName(String method_name)
           
 voidsetReturnType(ClassGenType return_type)
           

Constructor Detail

MethodGen

public MethodGen(int access_flags, ClassGenType return_type, ClassGenType[] arg_types, String[] arg_names, String method_name, String class_name, InstructionList il, ConstantPoolGen cp)
Declare method. If the method is non-static the constructor automatically declares a local variable `$this' in slot 0.
Parameters:
access_flags - access qualifiers
return_type - method type
arg_types - argument types
arg_names - argument names (may be null)
method_name - name of method
class_name - class name containing this method
il - instruction list associated with this method, may be empty initially
cp - constant pool
Method Detail

addAttribute

public void addAttribute(Attribute attr)
Add an attribute to this method. Currently, the JVM knows about the `Code' and `Exceptions' attribute, others will be ignored.
Parameters:
attr - Attribute to be added

addException

public void addException(String class_name)
Add an exception thrown by this method. This is actually an attribute of the method and thus is being added to the attribute list.
Parameters:
class_name - name of exception

addExceptionHandler

public void addExceptionHandler(InstructionHandle start_pc, InstructionHandle end_pc, InstructionHandle handler_pc, int catch_type)
Add an exception handler, i.e. specify region where a handler is active and an instruction where the actual handling is done.
Parameters:
start_pc - Start of region
end_pc - End of region
handler_pc - Where handling is done
catch_type - which exception is handled (reference to class in constant pool)

addExceptionHandler

public void addExceptionHandler(InstructionHandle start_pc, InstructionHandle end_pc, InstructionHandle handler_pc, String catch_type)
Add an exception handler, i.e. specify region where a handler is active and an instruction where the actual handling is done.
Parameters:
start_pc - Start of region
end_pc - End of region
handler_pc - Where handling is done
catch_type - which exception is handled (fully qualified class name)

addLocalVariable

public LocalVariableGen addLocalVariable(String name, ClassGenType type, InstructionHandle start, InstructionHandle end)
Add a local variable to this method.
Parameters:
name - variable name
type - variable type
start - from where the variable is valid, if this is null, it is valid from the start
end - until where the variable is valid, if this is null, it is valid to the end
Returns: new local variable
See Also:
LocalVariable

getAccessFlags

public int getAccessFlags()

getArgTypes

public ClassGenType[] getArgTypes()

getAttributes

public final Attribute[] getAttributes()
Returns: all attributes of this method.

getClassName

public String getClassName()

getInstructionList

public final InstructionList getInstructionList()
Returns: InstructionList (geter for il )

getLocalVariables

public final LocalVariableGen[] getLocalVariables()

getMethod

public Method getMethod(int max_stack)
Get method object. The maximum stack size has to be supplied by the user, since it is hard to determine statically with just the byte code at hands. I.e. you'd have to identify loops and such. The stack size can be computed much easier on the fly when creating the code.
Parameters:
max_stack - maximum stack size of this method
il - instructions (byte code)
cp - constant pool
Returns: method object

getMethodName

public String getMethodName()

getReturnType

public ClassGenType getReturnType()

lookupLocal

public LocalVariableGen lookupLocal(String name)

removeNOPs

public final 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.

setAccessFlags

public void setAccessFlags(short access_flags)

setArgTypes

public void setArgTypes(ClassGenType[] arg_types)

setMethodName

public void setMethodName(String method_name)

setReturnType

public void setReturnType(ClassGenType return_type)

Association Links

to Class java.lang.String

to Class java.lang.String

to Class jellyj.classfile.classgen.ClassGenType

to Class jellyj.classfile.classgen.ClassGenType

to Class java.lang.String

to Class jellyj.classfile.classgen.InstructionList

to Class jellyj.classfile.classgen.ConstantPoolGen

to Class java.util.Vector

to Class java.util.Vector

to Class java.util.Vector

to Class java.util.Vector