KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > generator > JIfElseIfElseStatement


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 java.util.Vector;
22
23 public class JIfElseIfElseStatement extends JStatement
24 {
25     protected JIfStatement _ifStatement;
26     protected Vector _elseifStatements;
27     protected JElseStatement _elseStatement;
28
29     public JIfElseIfElseStatement( JExpression if_expr )
30     {
31         _ifStatement = new JIfStatement( if_expr );
32         _elseifStatements = new Vector();
33         _elseStatement = new JElseStatement();
34     }
35
36     public void addIfStatement( JStatement s )
37     {
38         _ifStatement.addStatement( s );
39     }
40
41     public JIfStatement getIfStatement()
42     {
43         return _ifStatement;
44     }
45
46     public Vector getIfStatements()
47     {
48         return _ifStatement.getStatements();
49     }
50
51     public void addElseStatement( JStatement s )
52     {
53         _elseStatement.addStatement( s );
54     }
55
56     public JElseStatement getElseStatement()
57     {
58         return _elseStatement;
59     }
60
61     public Vector getElseStatements()
62     {
63         return _elseStatement.getStatements();
64     }
65
66     public JElseIfStatement getElseIf( JExpression e )
67     {
68         JElseIfStatement rc = null;
69         int index = _elseifStatements.indexOf( e );
70
71         if (index >= 0)
72         {
73             rc = (JElseIfStatement)_elseifStatements.get( index );
74         }
75
76         return rc;
77     }
78
79     public JElseIfStatement newElseIf( JExpression e )
80     {
81         JElseIfStatement rc = getElseIf( e );
82
83         if (rc == null)
84         {
85             rc = new JElseIfStatement( e );
86             _elseifStatements.add(rc);
87         }
88
89         return rc;
90     }
91
92     public void addCatchStatement( JExpression e, JStatement s )
93     {
94         JElseIfStatement eis = getElseIf( e );
95
96         if (eis == null)
97         {
98             eis = newElseIf( e );
99         }
100
101         eis.addStatement( s );
102     }
103
104     public Vector getElseIfs()
105     {
106         return _elseifStatements;
107     }
108 }
109
Popular Tags