Package serp.bytecode

Class ExceptionHandler

java.lang.Object
serp.bytecode.ExceptionHandler
All Implemented Interfaces:
BCEntity, InstructionPtr, VisitAcceptor

public class ExceptionHandler extends Object implements InstructionPtr, BCEntity, VisitAcceptor
Represents a try {} catch() {} statement in bytecode.
  • Field Details

  • Constructor Details

    • ExceptionHandler

      ExceptionHandler(Code owner)
  • Method Details

    • getCode

      public Code getCode()
      Return the owning code block.
      Specified by:
      getCode in interface InstructionPtr
    • getTryStart

      public Instruction getTryStart()
      Return the instruction marking the beginning of the try {} block.
    • setTryStart

      public void setTryStart(Instruction instruction)
      Set the Instruction marking the beginning of the try block. The instruction must already be a part of the method.
    • getTryEnd

      public Instruction getTryEnd()
      Return the instruction at the end of the try {} block.
    • setTryEnd

      public void setTryEnd(Instruction instruction)
      Set the Instruction at the end of the try block. The Instruction must already be a part of the method.
    • getHandlerStart

      public Instruction getHandlerStart()
      Return the instruction marking the beginning of the catch {} block.
    • setHandlerStart

      public void setHandlerStart(Instruction instruction)
      Set the Instruction marking the beginning of the catch block. The instruction must already be a part of the method. WARNING: if this instruction is deleted, the results are undefined.
    • getCatchIndex

      public int getCatchIndex()
      Return the index into the class ConstantPool of the ClassEntry describing the exception type this handler catches.
    • setCatchIndex

      public void setCatchIndex(int catchTypeIndex)
      Set the index into the class ConstantPool of the ClassEntry describing the exception type this handler catches.
    • getCatchName

      public String getCatchName()
      Return the name of the exception type; returns null for catch-all clauses used to implement finally blocks. The name will be returned in a forum suitable for a Class.forName(java.lang.String) call.
    • getCatchType

      public Class getCatchType()
      Return the Class of the exception type; returns null for catch-all clauses used to implement finally blocks.
    • getCatchBC

      public BCClass getCatchBC()
      Return the bytecode of the exception type; returns null for catch-all clauses used to implement finally blocks.
    • setCatch

      public void setCatch(String name)
      Set the class of the exception type, or null for catch-all clauses used with finally blocks.
    • setCatch

      public void setCatch(Class type)
      Set the class of the exception type, or null for catch-all clauses used for finally blocks.
    • setCatch

      public void setCatch(BCClass type)
      Set the class of the exception type, or null for catch-all clauses used for finally blocks.
    • updateTargets

      public void updateTargets()
      Description copied from interface: InstructionPtr
      Use the byte indexes read from the class file to calculate and set references to the target instruction(s) for this ptr. This method will be called after the byte code has been read in for the first time and before it is written after modification.
      Specified by:
      updateTargets in interface InstructionPtr
    • replaceTarget

      public void replaceTarget(Instruction oldTarget, Instruction newTarget)
      Description copied from interface: InstructionPtr
      Replace the given old, likely invalid, target with a new target. The new target Instruction is guaranteed to be in the same code block as this InstructionPtr.
      Specified by:
      replaceTarget in interface InstructionPtr
    • getProject

      public Project getProject()
      Description copied from interface: BCEntity
      Return the project of the current class.
      Specified by:
      getProject in interface BCEntity
    • getPool

      public ConstantPool getPool()
      Description copied from interface: BCEntity
      Return the constant pool of the current class.
      Specified by:
      getPool in interface BCEntity
    • getClassLoader

      public ClassLoader getClassLoader()
      Description copied from interface: BCEntity
      Return the class loader to use when loading related classes.
      Specified by:
      getClassLoader in interface BCEntity
    • isValid

      public boolean isValid()
      Description copied from interface: BCEntity
      Return false if this entity has been removed from its parent; in this case the results of any operations on the entity are undefined.
      Specified by:
      isValid in interface BCEntity
    • acceptVisit

      public void acceptVisit(BCVisitor visit)
      Description copied from interface: VisitAcceptor
      Accept a visit from a BCVisitor, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.
      Specified by:
      acceptVisit in interface VisitAcceptor
    • read

      void read(ExceptionHandler orig)
    • read

      void read(DataInput in) throws IOException
      Throws:
      IOException
    • write

      void write(DataOutput out) throws IOException
      Throws:
      IOException
    • setTryStart

      public void setTryStart(int start)
    • getTryStartPc

      public int getTryStartPc()
    • setTryEnd

      public void setTryEnd(int end)
    • getTryEndPc

      public int getTryEndPc()
      Return the program counter end position for this exception handler. This represents an index into the code byte array.
    • setHandlerStart

      public void setHandlerStart(int handler)
    • getHandlerStartPc

      public int getHandlerStartPc()
    • invalidate

      void invalidate()