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 voidacceptVisit(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.BCClassgetCatchBC()Return the bytecode of the exception type; returns null for catch-all clauses used to implement finally blocks.intgetCatchIndex()Return the index into the classConstantPoolof theClassEntrydescribing the exception type this handler catches.java.lang.StringgetCatchName()Return the name of the exception type; returns null for catch-all clauses used to implement finally blocks.java.lang.ClassgetCatchType()Return theClassof the exception type; returns null for catch-all clauses used to implement finally blocks.java.lang.ClassLoadergetClassLoader()Return the class loader to use when loading related classes.CodegetCode()Return the owning code block.InstructiongetHandlerStart()Return the instruction marking the beginning of the catch {} block.intgetHandlerStartPc()ConstantPoolgetPool()Return the constant pool of the current class.ProjectgetProject()Return the project of the current class.InstructiongetTryEnd()Return the instruction at the end of the try {} block.intgetTryEndPc()Return the program counter end position for this exception handler.InstructiongetTryStart()Return the instruction marking the beginning of the try {} block.intgetTryStartPc()booleanisValid()Return false if this entity has been removed from its parent; in this case the results of any operations on the entity are undefined.voidreplaceTarget(Instruction oldTarget, Instruction newTarget)Replace the given old, likely invalid, target with a new target.voidsetCatch(java.lang.Class type)Set the class of the exception type, or null for catch-all clauses used for finally blocks.voidsetCatch(java.lang.String name)Set the class of the exception type, or null for catch-all clauses used with finally blocks.voidsetCatch(BCClass type)Set the class of the exception type, or null for catch-all clauses used for finally blocks.voidsetCatchIndex(int catchTypeIndex)Set the index into the classConstantPoolof theClassEntrydescribing the exception type this handler catches.voidsetHandlerStart(int handler)voidsetHandlerStart(Instruction instruction)Set theInstructionmarking the beginning of the catch block.voidsetTryEnd(int end)voidsetTryEnd(Instruction instruction)Set the Instruction at the end of the try block.voidsetTryStart(int start)voidsetTryStart(Instruction instruction)Set theInstructionmarking the beginning of the try block.voidupdateTargets()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:
getCodein interfaceInstructionPtr
-
getTryStart
public Instruction getTryStart()
Return the instruction marking the beginning of the try {} block.
-
setTryStart
public void setTryStart(Instruction instruction)
Set theInstructionmarking 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 theInstructionmarking 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 classConstantPoolof theClassEntrydescribing the exception type this handler catches.
-
setCatchIndex
public void setCatchIndex(int catchTypeIndex)
Set the index into the classConstantPoolof theClassEntrydescribing 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 theClassof 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:InstructionPtrUse 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:
updateTargetsin interfaceInstructionPtr
-
replaceTarget
public void replaceTarget(Instruction oldTarget, Instruction newTarget)
Description copied from interface:InstructionPtrReplace 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:
replaceTargetin interfaceInstructionPtr
-
getProject
public Project getProject()
Description copied from interface:BCEntityReturn the project of the current class.- Specified by:
getProjectin interfaceBCEntity
-
getPool
public ConstantPool getPool()
Description copied from interface:BCEntityReturn the constant pool of the current class.
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Description copied from interface:BCEntityReturn the class loader to use when loading related classes.- Specified by:
getClassLoaderin interfaceBCEntity
-
isValid
public boolean isValid()
Description copied from interface:BCEntityReturn 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:VisitAcceptorAccept 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:
acceptVisitin 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()
-
-