Class Method

java.lang.Object
EDU.purdue.cs.bloat.file.Method
All Implemented Interfaces:
MethodInfo

public class Method extends Object implements MethodInfo
Method represents a method in a Java classfile. A method's name and value (the types of its parameters and its return type) are modeled as indices into it class's constant pool. A method has modifiers that determine whether it is public, private, static, final, etc. Methods have a number of attributes such as their Code and any Exceptions they may throw.
See Also:
  • Field Details

    • DEBUG

      public static boolean DEBUG
  • Constructor Details

    • Method

      public Method(DataInputStream in, ClassInfo classInfo) throws IOException
      Constructor. Read a method from a class file.
      Parameters:
      in - The data stream of the class file.
      classInfo - The class file containing the method.
      Throws:
      IOException - If an error occurs while reading.
  • Method Details

    • declaringClass

      public ClassInfo declaringClass()
      Get the class which declared the method.
      Specified by:
      declaringClass in interface MethodInfo
      Returns:
      The ClassInfo of the class which declared the method.
    • setNameIndex

      public void setNameIndex(int name)
      Set the index into the constant pool of the name of the method.
      Specified by:
      setNameIndex in interface MethodInfo
      Parameters:
      name - The index into the constant pool of the name of the method.
    • setTypeIndex

      public void setTypeIndex(int type)
      Set the index into the constant pool of the type of the method.
      Specified by:
      setTypeIndex in interface MethodInfo
      Parameters:
      type - The index into the constant pool of the type of the method.
    • nameIndex

      public int nameIndex()
      Get the index into the constant pool of the name of the method.
      Specified by:
      nameIndex in interface MethodInfo
      Returns:
      The index into the constant pool of the name of the method.
    • typeIndex

      public int typeIndex()
      Get the index into the constant pool of the type of the method.
      Specified by:
      typeIndex in interface MethodInfo
      Returns:
      The index into the constant pool of the type of the method.
    • setModifiers

      public void setModifiers(int modifiers)
      Set the modifiers of the method. The values correspond to the constants in the Modifiers class.
      Specified by:
      setModifiers in interface MethodInfo
      Parameters:
      modifiers - A bit vector of modifier flags for the method.
      See Also:
    • modifiers

      public int modifiers()
      Get the modifiers of the method. The values correspond to the constants in the Modifiers class.
      Specified by:
      modifiers in interface MethodInfo
      Returns:
      A bit vector of modifier flags for the method.
      See Also:
    • maxStack

      public int maxStack()
      Get the maximum height of the operand stack.
      Specified by:
      maxStack in interface MethodInfo
      Returns:
      The maximum height of the operand stack.
    • setMaxStack

      public void setMaxStack(int maxStack)
      Set the maximum height of the operand stack.
      Specified by:
      setMaxStack in interface MethodInfo
      Parameters:
      maxStack - The maximum height of the operand stack.
    • maxLocals

      public int maxLocals()
      Get the maximum number of locals used in the method.
      Specified by:
      maxLocals in interface MethodInfo
      Returns:
      The maximum number of locals used in the method.
    • setMaxLocals

      public void setMaxLocals(int maxLocals)
      Set the maximum number of locals used in the method.
      Specified by:
      setMaxLocals in interface MethodInfo
      Parameters:
      maxLocals - The maximum number of locals used in the method.
    • code

      public byte[] code()
      Get the byte code array of the method.
      Specified by:
      code in interface MethodInfo
      Returns:
      The byte code array of the method.
    • codeLength

      public int codeLength()
      Returns the length of the Code array.
    • setCode

      public void setCode(byte[] bytes)
      Set the byte code array of the method.
      Specified by:
      setCode in interface MethodInfo
      Parameters:
      bytes - The byte code array of the method.
    • exceptionTypes

      public int[] exceptionTypes()
      Get the indices into the constant pool of the types of the exceptions thrown by the method.
      Specified by:
      exceptionTypes in interface MethodInfo
      Returns:
      The indices into the constant pool of the types of the exceptions thrown by the method.
    • setLineNumbers

      public void setLineNumbers(LineNumberDebugInfo[] lineNumbers)
      Set the line numbers of the instructions in the method.
      Specified by:
      setLineNumbers in interface MethodInfo
      Parameters:
      lineNumbers - The line numbers of the instructions in the method.
    • setLocals

      public void setLocals(LocalDebugInfo[] locals)
      Set the local variable debug info for the method.
      Specified by:
      setLocals in interface MethodInfo
      Parameters:
      locals - The local variable debug info for the method.
    • lineNumbers

      public LineNumberDebugInfo[] lineNumbers()
      Get the line numbers of the instructions in the method.
      Specified by:
      lineNumbers in interface MethodInfo
      Returns:
      The line numbers of the instructions in the method.
    • locals

      public LocalDebugInfo[] locals()
      Get the local variable debug info for the method.
      Specified by:
      locals in interface MethodInfo
      Returns:
      The local variable debug info for the method.
    • exceptionHandlers

      public Catch[] exceptionHandlers()
      Get the exception handlers in the method.
      Specified by:
      exceptionHandlers in interface MethodInfo
      Returns:
      The exception handlers in the method.
    • setExceptionHandlers

      public void setExceptionHandlers(Catch[] handlers)
      Set the exception handlers in the method.
      Specified by:
      setExceptionHandlers in interface MethodInfo
      Parameters:
      handlers - The exception handlers in the method.
    • write

      public void write(DataOutputStream out) throws IOException
      Write the method to a class file.
      Parameters:
      out - The data stream of the class file.
      Throws:
      IOException - If an error occurs while writing.
    • toString

      public String toString()
      Returns a string representation of the method.
      Overrides:
      toString in class Object
    • clone

      public Object clone()
      Creates a clone of this MethodInfo except that its declaring class does not know about it.
      Specified by:
      clone in interface MethodInfo
      Overrides:
      clone in class Object