1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 /***
28 * This class allows easy access to ExceptionHandler objects.
29 *
30 * @version $Id: ExceptionHandlers.java 386056 2006-03-15 11:31:56Z tcurdt $
31 * @author Enver Haase
32 */
33 public class ExceptionHandlers{
34 /***
35 * The ExceptionHandler instances.
36 * Key: InstructionHandle objects, Values: HashSet<ExceptionHandler> instances.
37 */
38 private Hashtable exceptionhandlers;
39
40 /***
41 * Constructor. Creates a new ExceptionHandlers instance.
42 */
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 /***
61 * Returns all the ExceptionHandler instances representing exception
62 * handlers that protect the instruction ih.
63 */
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 }