org.apache.tapestry.enhance
Class MethodFabricator

java.lang.Object
  |
  +--org.apache.tapestry.enhance.MethodFabricator

public class MethodFabricator
extends Object

Wrapper around MethodGen used to simplify the creation of new methods within a new class.

Since:
3.0
Version:
$Id: MethodFabricator.java,v 1.6 2003/05/28 13:41:41 hlship Exp $
Author:
Howard Lewis Ship

Method Summary
 int addArgument(org.apache.bcel.generic.Type type, String name)
          Adds an argument to the method.
 void addExceptionHandler(org.apache.bcel.generic.InstructionHandle start, org.apache.bcel.generic.InstructionHandle end, org.apache.bcel.generic.InstructionHandle handler, org.apache.bcel.generic.ObjectType catchType)
          Adds an exception handler.
 int addLocalVariable(org.apache.bcel.generic.Type type, String name)
          Adds a local variable of the given type, returning its index.
 org.apache.bcel.generic.InstructionHandle append(org.apache.bcel.generic.BranchInstruction instruction)
          Convienience method for adding instructions.
 org.apache.bcel.generic.InstructionHandle append(org.apache.bcel.generic.CompoundInstruction instruction)
          Convienience method for adding instructions.
 org.apache.bcel.generic.InstructionHandle append(org.apache.bcel.generic.Instruction instruction)
          Convienience method for adding instructions.
 void commit()
          Commits the method; this is invoked last.
 org.apache.bcel.generic.InstructionList getInstructionList()
          Returns the instruction list for the method being created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addArgument

public int addArgument(org.apache.bcel.generic.Type type,
                       String name)
Adds an argument to the method. Arguments must be added in order. Returns the index of the added argument. This is an implicit argument in slot 0, the first explicit argument is in slot 1.

All arguments must be added before any local variables are added.

Throws:
IllegalStateException - if arguments may not be added.

addLocalVariable

public int addLocalVariable(org.apache.bcel.generic.Type type,
                            String name)
Adds a local variable of the given type, returning its index. Local variables come after any arguments. Arguments may not be added after local variables.

getInstructionList

public org.apache.bcel.generic.InstructionList getInstructionList()
Returns the instruction list for the method being created.

append

public org.apache.bcel.generic.InstructionHandle append(org.apache.bcel.generic.Instruction instruction)
Convienience method for adding instructions.

append

public org.apache.bcel.generic.InstructionHandle append(org.apache.bcel.generic.CompoundInstruction instruction)
Convienience method for adding instructions.

append

public org.apache.bcel.generic.InstructionHandle append(org.apache.bcel.generic.BranchInstruction instruction)
Convienience method for adding instructions.

commit

public void commit()
Commits the method; this is invoked last. It updates the MethodGen with any arguments that have been added, then creates the Method object and adds it to the ClassGen.

addExceptionHandler

public void addExceptionHandler(org.apache.bcel.generic.InstructionHandle start,
                                org.apache.bcel.generic.InstructionHandle end,
                                org.apache.bcel.generic.InstructionHandle handler,
                                org.apache.bcel.generic.ObjectType catchType)
Adds an exception handler. The start and end instructions are indicated by their handles (to be honest, I'm shakey on whether the entire end instruction is covered, or only until just before the end instruction). The handler is an instruction that should immediately follow the protected block. The catch type determines what kind of exception will be caught.