KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > generator > JSwitchStatement


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.JCaseStatement;
22 import gcc.generator.JExpression;
23 import gcc.generator.JStatement;
24
25 import java.util.Vector;
26
27 public class JSwitchStatement extends JStatement
28 {
29     protected JExpression _switchExpr;
30     protected Vector _caseStatements;
31
32     public JSwitchStatement( JExpression e )
33     {
34         _switchExpr = e;
35         _caseStatements = new Vector();
36     }
37
38     public void setVariable( JExpression e )
39     {
40         _switchExpr = e;
41     }
42
43     public JExpression getExpression()
44     {
45         return _switchExpr;
46     }
47
48     public JCaseStatement getCase( JExpression e )
49     {
50         JCaseStatement rc = null;
51         int index = _caseStatements.indexOf( e );
52
53         if (index >= 0)
54         {
55             rc = (JCaseStatement)_caseStatements.get( index );
56         }
57
58         return rc;
59     }
60
61     public JCaseStatement newCase( JExpression e )
62     {
63         JCaseStatement rc = getCase( e );
64
65         if (rc == null)
66         {
67             rc = new JCaseStatement( e );
68             _caseStatements.add(rc);
69         }
70
71         return rc;
72     }
73
74     public void addCaseStatement( JExpression e, JStatement s )
75     {
76         JCaseStatement cs = getCase( e );
77
78         if (cs == null)
79         {
80             cs = newCase( e );
81         }
82
83         cs.addStatement( s );
84     }
85
86     public Vector getCases()
87     {
88         return _caseStatements;
89     }
90 }
91
Popular Tags