KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > generator > JTryCatchFinallyStatement


1 /*
2  * Copyright 2004 The Apache Software Foundation or its licensors, as
3  * applicable.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19 package gcc.generator;
20
21 import gcc.generator.JCatchStatement;
22 import gcc.generator.JFinallyStatement;
23 import gcc.generator.JStatement;
24
25 import java.util.Vector;
26
27 public class JTryCatchFinallyStatement extends JStatement
28 {
29     protected JTryStatement _TryStatement;
30     protected Vector _catchStatements;
31     protected JFinallyStatement _FinallyStatement;
32
33     public JTryCatchFinallyStatement( )
34     {
35         _TryStatement = new JTryStatement();
36         _catchStatements = new Vector();
37         _FinallyStatement = new JFinallyStatement();
38     }
39
40     public void addTryStatement( JStatement s )
41     {
42         _TryStatement.addStatement( s );
43     }
44
45     public JTryStatement getTryStatement()
46     {
47         return _TryStatement;
48     }
49
50     public JCatchStatement getCatch( JVariable v )
51     {
52         JCatchStatement rc = null;
53         int index = _catchStatements.indexOf( v );
54
55         if (index >= 0)
56         {
57             rc = (JCatchStatement)_catchStatements.get( index );
58         }
59
60         return rc;
61     }
62
63     public JCatchStatement newCatch( JVariable v )
64     {
65         JCatchStatement rc = getCatch( v );
66
67         if (rc == null)
68         {
69             rc = new JCatchStatement( v );
70             _catchStatements.add(rc);
71         }
72
73         return rc;
74     }
75
76     public void addCatchStatement( JVariable v, JStatement s )
77     {
78         JCatchStatement cs = getCatch( v );
79
80         if (cs == null)
81         {
82             cs = newCatch( v );
83         }
84
85         cs.addStatement( s );
86     }
87
88     public Vector getCatches()
89     {
90         return _catchStatements;
91     }
92
93     public void addFinallyStatement( JStatement s )
94     {
95         _FinallyStatement.addStatement( s );
96     }
97
98     public JFinallyStatement getFinallyStatement()
99     {
100         return _FinallyStatement;
101     }
102 }
103
Popular Tags