javar.methods
Class Method

java.lang.Object
  |
  +--javar.methods.Method
All Implemented Interfaces:
Code

public class Method
extends Object
implements Code

This class represents a method inside of a class

Author:
Ben Litchfield

Nested Class Summary
 
Nested classes inherited from class javar.code.Code
Code.CodeHelper
 
Field Summary
static String CONSTRUCTOR_NAME
           
 
Fields inherited from interface javar.code.Code
AALOAD, AASTORE, ACONST_NULL, ALOAD, ALOAD_0, ALOAD_1, ALOAD_2, ALOAD_3, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ASTORE_0, ASTORE_1, ASTORE_2, ASTORE_3, ATHROW, BALOAD, BASTORE, BIPUSH, CASTORE, CHECKCAST, CODE_NAMES, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DLOAD_0, DLOAD_1, DLOAD_2, DLOAD_3, DMUL, DNEG, DREM, DRETURN, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAD_0, FLOAD_1, FLOAD_2, FLOAD_3, FMUL, FNEG, FREM, FRETURN, FSUB, GETFIELD, GETSTATIC, GOTO, GOTO_W, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, ILOAD_0, ILOAD_1, ILOAD_2, ILOAD_3, IMUL, INEG, INSTANCEOF, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISTORE_0, ISTORE_1, ISTORE_2, ISTORE_3, ISUB, IUSHR, IXOR, JSR, JSR_W, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDC_2W, LDC_W, LDIV, LLOAD, LLOAD_0, LLOAD_1, LLOAD_2, LLOAD_3, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SASTORE, SIPUSH, SWAP, TABLESWITCH, WIDE
 
Constructor Summary
Method(ConstantPool p)
          Constructor
 
Method Summary
 void addAttribute(Attribute attr)
          This will add an attribute to the class.
 void addCommand(int index, Command c)
          This will add a new command into the mix.
 int getAccessFlags()
          This will get the access flags for this class
 List getArguments()
          This will get all the arguments that this class takes
 byte[] getByteCode()
          This will return the byteCode for this function
 int getName()
          This will return the name of the method
 String getNameAsString()
          This will return the name of the method
 List getOperations()
          This will get a list of Command objects that represent operations that can be executed.
 String getReturnValue()
          This will get the return value of a class.
 boolean isConstructor()
          This is a convience method that determines if this method is a constructor or not.
 Iterator listExceptions()
          This will list all of the exceptions that this method throws.
 void load(DataInputStream in)
          This will load the data for a method
 void setAccessFlags(int flags)
          This will set the accessFlags()
 void setDescriptorIndex(int index)
          This will set the index of the descriptor.
 void setName(int index)
          This will set the index of the name.
 byte[] toBytes()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONSTRUCTOR_NAME

public static final String CONSTRUCTOR_NAME
See Also:
Constant Field Values
Constructor Detail

Method

public Method(ConstantPool p)
Constructor

Method Detail

setAccessFlags

public void setAccessFlags(int flags)
This will set the accessFlags()

Parameters:
flags - The new access flags

getAccessFlags

public int getAccessFlags()
This will get the access flags for this class

Returns:
The access flags for this class

setName

public void setName(int index)
This will set the index of the name.

Parameters:
index - The name index

setDescriptorIndex

public void setDescriptorIndex(int index)
This will set the index of the descriptor.

Parameters:
index - The descriptor index

addAttribute

public void addAttribute(Attribute attr)
This will add an attribute to the class.

Parameters:
attr - The attribute to add

listExceptions

public Iterator listExceptions()
                        throws JavarParseException
This will list all of the exceptions that this method throws. This will return a list of objects whose type is CONSTANT_Classref.

Returns:
A list of all exceptions that this methods throws.
Throws:
JavarParseException - If there is an error parsing the exception list

toBytes

public byte[] toBytes()

load

public void load(DataInputStream in)
          throws JavarParseException
This will load the data for a method

JavarParseException

getName

public int getName()
This will return the name of the method


getNameAsString

public String getNameAsString()
This will return the name of the method


isConstructor

public boolean isConstructor()
This is a convience method that determines if this method is a constructor or not. It is a constructor if the name of the method is ''.


getOperations

public List getOperations()
This will get a list of Command objects that represent operations that can be executed.

Returns:
A list of executable operations

addCommand

public void addCommand(int index,
                       Command c)
                throws JavarIOException
This will add a new command into the mix. This will insert the command just before the index so if the call is. A call to insert before a command that does not fall on the index of a previous command will throw and exception. The arguments parameter must be at least as long as the required bytes to fullfil any byte requirements that are required by the operation. It may be null if no bytes are required. addCommand( 1, B8, 0003 ); Before: [0]=2A // 0 aload_0 [1]=B70001 // 1 invokespecial java/lang/Object.()V [4]=B1 // 4 return After: [0]=2A // 0 aload_0 [1]=B80003 // 1 invokestatic reflection/one/Testone.replace(Ljava/lang/String;)Ljava/lang/String; [4]=B70001 // 1 invokespecial java/lang/Object.()V [7]=B1 // 4 return

Parameters:
index - The index of the code to insert the command
JavarIOException

getArguments

public List getArguments()
                  throws JavarParseException
This will get all the arguments that this class takes

Returns:
A List of string elements that represent the types of arguments
Throws:
JavarParseException - If there is an error during the parse of arguments.

getReturnValue

public String getReturnValue()
                      throws JavarParseException
This will get the return value of a class.

Returns:
The return type as a string
Throws:
JavarParseException - If there is an error parsing the return value.

getByteCode

public byte[] getByteCode()
This will return the byteCode for this function