KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > idl > ArrayDeclarator


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-2004 Gerald Brose.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20
21 package org.jacorb.idl;
22
23 /**
24  * @author Gerald Brose
25  * @version $Id: ArrayDeclarator.java,v 1.18 2004/05/06 12:39:58 nicolas Exp $
26  */

27
28 import java.io.PrintWriter JavaDoc;
29 import java.util.*;
30
31 class ArrayDeclarator
32     extends Declarator
33 {
34     public SymbolList fixed_array_size_list;
35     private int[] dimensions = null;
36
37     public ArrayDeclarator( int num )
38     {
39         super( num );
40     }
41
42     public String JavaDoc name()
43     {
44         return name;
45     }
46
47     /**
48      */

49
50     public void escapeName()
51     {
52         if( !name.startsWith( "_" ) &&
53                 lexer.strictJavaEscapeCheck( name ) )
54         {
55             name = "_" + name;
56         }
57     }
58
59     public void setPackage( String JavaDoc s )
60     {
61         s = parser.pack_replace( s );
62         if( pack_name.length() > 0 )
63             pack_name = s + "." + pack_name;
64         else
65             pack_name = s;
66
67         for( Enumeration e = fixed_array_size_list.v.elements();
68              e.hasMoreElements();
69              ( (FixedArraySize)e.nextElement() ).setPackage( s ) ) ;
70
71     }
72
73     /**
74      * only needed to overwrite the delegating full_name()
75      * method from superclass Declarator, identical to method in
76      * class IdlSymbol
77      */

78
79     String JavaDoc full_name()
80     {
81         if( name.length() == 0 )
82             return null;
83         if( pack_name.length() > 0 )
84             return pack_name + "." + name;
85         else
86             return name;
87     }
88
89     public void parse()
90     {
91         for( Enumeration e = fixed_array_size_list.v.elements();
92              e.hasMoreElements();
93              ( (FixedArraySize)e.nextElement() ).parse()
94                 )
95             ;
96
97         for( Enumeration e = fixed_array_size_list.v.elements();
98              e.hasMoreElements();
99                 )
100             ( (FixedArraySize)e.nextElement() ).parse();
101     }
102
103     public void setEnclosingSymbol( IdlSymbol s )
104     {
105         if( enclosing_symbol != null && enclosing_symbol != s )
106             throw new RuntimeException JavaDoc( "Compiler Error: trying to reassign container for " + name );
107         enclosing_symbol = s;
108     }
109
110     public IdlSymbol getEnclosingSymbol()
111     {
112         return enclosing_symbol;
113     }
114
115     public int[] dimensions()
116     {
117         if( dimensions == null )
118         {
119             Vector dynlist = new Vector();
120             for( Enumeration e = fixed_array_size_list.v.elements(); e.hasMoreElements(); )
121                 dynlist.addElement( new Integer JavaDoc( ( (FixedArraySize)e.nextElement() ).value() ) );
122             dimensions = new int[ dynlist.size() ];
123             for( int i = 0; i < dimensions.length; i++ )
124                 dimensions[ i ] = ( (Integer JavaDoc)dynlist.elementAt( i ) ).intValue();
125
126         }
127         return dimensions;
128     }
129
130     public String JavaDoc toString()
131     {
132         return name();
133     }
134
135     public void print( PrintWriter JavaDoc ps )
136     {
137     }
138
139 }
140
Popular Tags