KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > AbstractTrap


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997-1999 Raja Vallee-Rai
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27 package soot;
28
29 import soot.*;
30 import soot.jimple.*;
31 import soot.util.*;
32 import java.util.*;
33 import java.io.*;
34
35 /** Partial implementation of trap (exception catcher), used within Body
36  * classes. */

37 public class AbstractTrap implements Trap, Serializable
38 {
39     /** The exception being caught. */
40     protected transient SootClass exception;
41
42     /** The first unit being trapped. */
43     protected UnitBox beginUnitBox;
44
45     /** The unit just before the last unit being trapped. */
46     protected UnitBox endUnitBox;
47
48     /** The unit to which execution flows after the caught exception is triggered. */
49     protected UnitBox handlerUnitBox;
50
51     /** The list of unitBoxes referred to in this Trap (begin, end and handler. */
52     protected List unitBoxes;
53
54     private void readObject( ObjectInputStream in) throws IOException, ClassNotFoundException JavaDoc
55     {
56     in.defaultReadObject();
57     exception = Scene.v().getSootClass( (String JavaDoc) in.readObject());
58     }
59
60     private void writeObject( ObjectOutputStream out) throws IOException
61     {
62     out.defaultWriteObject();
63     out.writeObject( exception.getName());
64     }
65
66
67     /** Creates an AbstractTrap with the given exception, handler, begin and end units. */
68     protected AbstractTrap(SootClass exception, UnitBox beginUnitBox,
69                    UnitBox endUnitBox, UnitBox handlerUnitBox)
70     {
71         this.exception = exception; this.beginUnitBox = beginUnitBox;
72         this.endUnitBox = endUnitBox; this.handlerUnitBox = handlerUnitBox;
73
74         unitBoxes = new ArrayList();
75         unitBoxes.add(beginUnitBox);
76         unitBoxes.add(endUnitBox);
77         unitBoxes.add(handlerUnitBox);
78         unitBoxes = Collections.unmodifiableList(unitBoxes);
79     }
80
81     public Unit getBeginUnit()
82     {
83         return beginUnitBox.getUnit();
84     }
85
86     public Unit getEndUnit()
87     {
88         return endUnitBox.getUnit();
89     }
90
91     public Unit getHandlerUnit()
92     {
93         return handlerUnitBox.getUnit();
94     }
95
96     public UnitBox getHandlerUnitBox()
97     {
98         return beginUnitBox;
99     }
100
101     public UnitBox getBeginUnitBox()
102     {
103         return beginUnitBox;
104     }
105
106     public UnitBox getEndUnitBox()
107     {
108         return endUnitBox;
109     }
110
111     public List getUnitBoxes()
112     {
113         return unitBoxes;
114     }
115
116     public void clearUnitBoxes()
117     {
118         Iterator boxesIt = getUnitBoxes().iterator();
119         while(boxesIt.hasNext()){
120             UnitBox box = (UnitBox) boxesIt.next();
121             box.setUnit(null);
122         }
123     }
124     
125     public SootClass getException()
126     {
127         return exception;
128     }
129
130     public void setBeginUnit(Unit beginUnit)
131     {
132         beginUnitBox.setUnit(beginUnit);
133     }
134
135     public void setEndUnit(Unit endUnit)
136     {
137         endUnitBox.setUnit(endUnit);
138     }
139
140     public void setHandlerUnit(Unit handlerUnit)
141     {
142         handlerUnitBox.setUnit(handlerUnit);
143     }
144
145     public void setException(SootClass exception)
146     {
147         this.exception = exception;
148     }
149
150     public Object JavaDoc clone()
151     {
152         throw new RuntimeException JavaDoc();
153     }
154 }
155
Popular Tags