Package serp.bytecode
Class ExceptionHandler
- java.lang.Object
-
- serp.bytecode.ExceptionHandler
-
- All Implemented Interfaces:
BCEntity
,InstructionPtr
,VisitAcceptor
public class ExceptionHandler extends java.lang.Object implements InstructionPtr, BCEntity, VisitAcceptor
Represents atry {} catch() {}
statement in bytecode.- Author:
- Abe White
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
acceptVisit(BCVisitor visit)
Accept a visit from aBCVisitor
, 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.BCClass
getCatchBC()
Return the bytecode of the exception type; returns null for catch-all clauses used to implement finally blocks.int
getCatchIndex()
Return the index into the classConstantPool
of theClassEntry
describing the exception type this handler catches.java.lang.String
getCatchName()
Return the name of the exception type; returns null for catch-all clauses used to implement finally blocks.java.lang.Class
getCatchType()
Return theClass
of the exception type; returns null for catch-all clauses used to implement finally blocks.java.lang.ClassLoader
getClassLoader()
Return the class loader to use when loading related classes.Code
getCode()
Return the owning code block.Instruction
getHandlerStart()
Return the instruction marking the beginning of the catch {} block.int
getHandlerStartPc()
ConstantPool
getPool()
Return the constant pool of the current class.Project
getProject()
Return the project of the current class.Instruction
getTryEnd()
Return the instruction at the end of the try {} block.int
getTryEndPc()
Return the program counter end position for this exception handler.Instruction
getTryStart()
Return the instruction marking the beginning of the try {} block.int
getTryStartPc()
boolean
isValid()
Return false if this entity has been removed from its parent; in this case the results of any operations on the entity are undefined.void
replaceTarget(Instruction oldTarget, Instruction newTarget)
Replace the given old, likely invalid, target with a new target.void
setCatch(java.lang.Class type)
Set the class of the exception type, or null for catch-all clauses used for finally blocks.void
setCatch(java.lang.String name)
Set the class of the exception type, or null for catch-all clauses used with finally blocks.void
setCatch(BCClass type)
Set the class of the exception type, or null for catch-all clauses used for finally blocks.void
setCatchIndex(int catchTypeIndex)
Set the index into the classConstantPool
of theClassEntry
describing the exception type this handler catches.void
setHandlerStart(int handler)
void
setHandlerStart(Instruction instruction)
Set theInstruction
marking the beginning of the catch block.void
setTryEnd(int end)
void
setTryEnd(Instruction instruction)
Set the Instruction at the end of the try block.void
setTryStart(int start)
void
setTryStart(Instruction instruction)
Set theInstruction
marking the beginning of the try block.void
updateTargets()
Use the byte indexes read from the class file to calculate and set references to the target instruction(s) for this ptr.
-
-
-
Method Detail
-
getCode
public Code getCode()
Return the owning code block.- Specified by:
getCode
in interfaceInstructionPtr
-
getTryStart
public Instruction getTryStart()
Return the instruction marking the beginning of the try {} block.
-
setTryStart
public void setTryStart(Instruction instruction)
Set theInstruction
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 theInstruction
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 classConstantPool
of theClassEntry
describing the exception type this handler catches.
-
setCatchIndex
public void setCatchIndex(int catchTypeIndex)
Set the index into the classConstantPool
of theClassEntry
describing the exception type this handler catches.
-
getCatchName
public java.lang.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 aClass.forName(java.lang.String)
call.
-
getCatchType
public java.lang.Class getCatchType()
Return theClass
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(java.lang.String name)
Set the class of the exception type, or null for catch-all clauses used with finally blocks.
-
setCatch
public void setCatch(java.lang.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 interfaceInstructionPtr
-
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 interfaceInstructionPtr
-
getProject
public Project getProject()
Description copied from interface:BCEntity
Return the project of the current class.- Specified by:
getProject
in interfaceBCEntity
-
getPool
public ConstantPool getPool()
Description copied from interface:BCEntity
Return the constant pool of the current class.
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Description copied from interface:BCEntity
Return the class loader to use when loading related classes.- Specified by:
getClassLoader
in interfaceBCEntity
-
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.
-
acceptVisit
public void acceptVisit(BCVisitor visit)
Description copied from interface:VisitAcceptor
Accept a visit from aBCVisitor
, 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 interfaceVisitAcceptor
-
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()
-
-