1 17 package org.apache.bcel.verifier.structurals; 18 19 20 import java.util.HashSet ; 21 import java.util.Hashtable ; 22 import java.util.Set ; 23 import org.apache.bcel.generic.CodeExceptionGen; 24 import org.apache.bcel.generic.InstructionHandle; 25 import org.apache.bcel.generic.MethodGen; 26 27 33 public class ExceptionHandlers{ 34 38 private Hashtable exceptionhandlers; 39 40 43 public ExceptionHandlers(MethodGen mg){ 44 exceptionhandlers = new Hashtable (); 45 CodeExceptionGen[] cegs = mg.getExceptionHandlers(); 46 for (int i=0; i<cegs.length; i++){ 47 ExceptionHandler eh = new ExceptionHandler(cegs[i].getCatchType(), cegs[i].getHandlerPC()); 48 for (InstructionHandle ih=cegs[i].getStartPC(); ih != cegs[i].getEndPC().getNext(); ih=ih.getNext()){ 49 Set hs; 50 hs = (Set ) exceptionhandlers.get(ih); 51 if (hs == null){ 52 hs = new HashSet (); 53 exceptionhandlers.put(ih, hs); 54 } 55 hs.add(eh); 56 } 57 } 58 } 59 60 64 public ExceptionHandler[] getExceptionHandlers(InstructionHandle ih){ 65 Set hs = (Set ) exceptionhandlers.get(ih); 66 if (hs == null) { 67 return new ExceptionHandler[0]; 68 } else{ 69 ExceptionHandler[] ret = new ExceptionHandler[hs.size()]; 70 return (ExceptionHandler[]) (hs.toArray(ret)); 71 } 72 } 73 74 } 75 | Popular Tags |