1 17 package org.apache.bcel.generic; 18 19 import org.apache.bcel.classfile.CodeException; 20 21 36 public final class CodeExceptionGen implements InstructionTargeter, Cloneable , java.io.Serializable { 37 38 private InstructionHandle start_pc; 39 private InstructionHandle end_pc; 40 private InstructionHandle handler_pc; 41 private ObjectType catch_type; 42 43 44 53 public CodeExceptionGen(InstructionHandle start_pc, InstructionHandle end_pc, 54 InstructionHandle handler_pc, ObjectType catch_type) { 55 setStartPC(start_pc); 56 setEndPC(end_pc); 57 setHandlerPC(handler_pc); 58 this.catch_type = catch_type; 59 } 60 61 62 71 public CodeException getCodeException( ConstantPoolGen cp ) { 72 return new CodeException(start_pc.getPosition(), end_pc.getPosition() 73 + end_pc.getInstruction().getLength(), handler_pc.getPosition(), 74 (catch_type == null) ? 0 : cp.addClass(catch_type)); 75 } 76 77 78 81 public void setStartPC( InstructionHandle start_pc ) { 82 BranchInstruction.notifyTarget(this.start_pc, start_pc, this); 83 this.start_pc = start_pc; 84 } 85 86 87 90 public void setEndPC( InstructionHandle end_pc ) { 91 BranchInstruction.notifyTarget(this.end_pc, end_pc, this); 92 this.end_pc = end_pc; 93 } 94 95 96 99 public void setHandlerPC( InstructionHandle handler_pc ) { 100 BranchInstruction.notifyTarget(this.handler_pc, handler_pc, this); 101 this.handler_pc = handler_pc; 102 } 103 104 105 109 public void updateTarget( InstructionHandle old_ih, InstructionHandle new_ih ) { 110 boolean targeted = false; 111 if (start_pc == old_ih) { 112 targeted = true; 113 setStartPC(new_ih); 114 } 115 if (end_pc == old_ih) { 116 targeted = true; 117 setEndPC(new_ih); 118 } 119 if (handler_pc == old_ih) { 120 targeted = true; 121 setHandlerPC(new_ih); 122 } 123 if (!targeted) { 124 throw new ClassGenException("Not targeting " + old_ih + ", but {" + start_pc + ", " 125 + end_pc + ", " + handler_pc + "}"); 126 } 127 } 128 129 130 133 public boolean containsTarget( InstructionHandle ih ) { 134 return (start_pc == ih) || (end_pc == ih) || (handler_pc == ih); 135 } 136 137 138 139 public void setCatchType( ObjectType catch_type ) { 140 this.catch_type = catch_type; 141 } 142 143 144 145 public ObjectType getCatchType() { 146 return catch_type; 147 } 148 149 150 152 public InstructionHandle getStartPC() { 153 return start_pc; 154 } 155 156 157 159 public InstructionHandle getEndPC() { 160 return end_pc; 161 } 162 163 164 166 public InstructionHandle getHandlerPC() { 167 return handler_pc; 168 } 169 170 171 public String toString() { 172 return "CodeExceptionGen(" + start_pc + ", " + end_pc + ", " + handler_pc + ")"; 173 } 174 175 176 public Object clone() { 177 try { 178 return super.clone(); 179 } catch (CloneNotSupportedException e) { 180 System.err.println(e); 181 return null; 182 } 183 } 184 } 185 | Popular Tags |