1 package com.sun.org.apache.bcel.internal.generic; 2 3 56 57 import com.sun.org.apache.bcel.internal.Constants; 58 import com.sun.org.apache.bcel.internal.classfile.*; 59 60 75 public final class CodeExceptionGen implements InstructionTargeter, Cloneable { 76 private InstructionHandle start_pc; 77 private InstructionHandle end_pc; 78 private InstructionHandle handler_pc; 79 private ObjectType catch_type; 80 81 90 public CodeExceptionGen(InstructionHandle start_pc, InstructionHandle end_pc, 91 InstructionHandle handler_pc, ObjectType catch_type) { 92 setStartPC(start_pc); 93 setEndPC(end_pc); 94 setHandlerPC(handler_pc); 95 this.catch_type = catch_type; 96 } 97 98 107 public CodeException getCodeException(ConstantPoolGen cp) { 108 return new CodeException(start_pc.getPosition(), 109 end_pc.getPosition() + end_pc.getInstruction().getLength(), 110 handler_pc.getPosition(), 111 (catch_type == null)? 0 : cp.addClass(catch_type)); 112 } 113 114 117 public void setStartPC(InstructionHandle start_pc) { 118 BranchInstruction.notifyTarget(this.start_pc, start_pc, this); 119 this.start_pc = start_pc; 120 } 121 122 125 public void setEndPC(InstructionHandle end_pc) { 126 BranchInstruction.notifyTarget(this.end_pc, end_pc, this); 127 this.end_pc = end_pc; 128 } 129 130 133 public void setHandlerPC(InstructionHandle handler_pc) { 134 BranchInstruction.notifyTarget(this.handler_pc, handler_pc, this); 135 this.handler_pc = handler_pc; 136 } 137 138 142 public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { 143 boolean targeted = false; 144 145 if(start_pc == old_ih) { 146 targeted = true; 147 setStartPC(new_ih); 148 } 149 150 if(end_pc == old_ih) { 151 targeted = true; 152 setEndPC(new_ih); 153 } 154 155 if(handler_pc == old_ih) { 156 targeted = true; 157 setHandlerPC(new_ih); 158 } 159 160 if(!targeted) 161 throw new ClassGenException("Not targeting " + old_ih + ", but {" + start_pc + ", " + 162 end_pc + ", " + handler_pc + "}"); 163 } 164 165 168 public boolean containsTarget(InstructionHandle ih) { 169 return (start_pc == ih) || (end_pc == ih) || (handler_pc == ih); 170 } 171 172 173 public void setCatchType(ObjectType catch_type) { this.catch_type = catch_type; } 174 175 public ObjectType getCatchType() { return catch_type; } 176 177 179 public InstructionHandle getStartPC() { return start_pc; } 180 181 183 public InstructionHandle getEndPC() { return end_pc; } 184 185 187 public InstructionHandle getHandlerPC() { return handler_pc; } 188 189 public String toString() { 190 return "CodeExceptionGen(" + start_pc + ", " + end_pc + ", " + handler_pc + ")"; 191 } 192 193 public Object clone() { 194 try { 195 return super.clone(); 196 } catch(CloneNotSupportedException e) { 197 System.err.println(e); 198 return null; 199 } 200 } 201 } 202 | Popular Tags |