KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > alt > jiapi > reflect > TryBlock


1 /*
2  * Copyright (C) 2001 Mika Riekkinen, Joni Suominen
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 Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package alt.jiapi.reflect;
20
21 import java.util.LinkedList JavaDoc;
22
23 import alt.jiapi.reflect.Instruction;
24 import alt.jiapi.reflect.InstructionList;
25
26 /**
27  * This class represents a try block in Java source code.
28  *
29  * @author Mika Riekkinen
30  * @author Joni Suominen
31  * @version $Revision: 1.7 $ $Date: 2004/02/22 16:13:37 $
32  */

33 public class TryBlock {
34     private InstructionList instructions;
35     private LinkedList JavaDoc exceptionHandlers = new LinkedList JavaDoc();
36
37     // Package protected for the moment
38
TryBlock(InstructionList instructions) {
39         this.instructions = instructions;
40     }
41
42     // Package protected for the moment
43
void addExceptionHandler(String JavaDoc name, Instruction handlerStart) {
44         exceptionHandlers.add(new ExceptionHandler(name, handlerStart));
45     }
46
47     /**
48      * Get the exception handlers this try block has.
49      * @return an array of <code>ExceptionHandler</code>s
50      */

51     public ExceptionHandler[] getExceptionHandlers() {
52         ExceptionHandler[] handlers =
53             new ExceptionHandler[exceptionHandlers.size()];
54         handlers = (ExceptionHandler[])exceptionHandlers.toArray(handlers);
55
56         return handlers;
57     }
58
59     /**
60      * Get the InstructionList, that corresponds to <code>
61      * try {...}</code> block in Java source code.
62      * @return InstructionList
63      */

64     public InstructionList getInstructionList() {
65         return instructions;
66     }
67
68     /**
69      * This class represents a <code>catch(...) { ... }</code> block in Java
70      * source code.
71      */

72     public class ExceptionHandler {
73         private Instruction handlerStart;
74         private String JavaDoc name;
75
76         // Package protected for the moment
77
ExceptionHandler(String JavaDoc name, Instruction handlerStart) {
78             this.name = name;
79             this.handlerStart = handlerStart;
80         }
81
82         /**
83          * Get the instructions of this ExceptionHandler.
84          * Only the start of the returned InstructionList is guaranteed
85          * to belong to corresponding <code>catch(...) {...}</code>
86          * statement in Java language. End of the list is set to
87          * end of the methods instruction list.
88          *
89          * @return InstructionList
90          */

91         public Instruction getHandlerStart() {
92             return handlerStart;
93         }
94
95         /**
96          * Get the name of this ExceptionHandler.
97          * @return name
98          */

99         public String JavaDoc getName() {
100             return name;
101         }
102     }
103 }
104
105
Popular Tags