KickJava   Java API By Example, From Geeks To Geeks.

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


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: TypeDeclaration.java,v 1.24 2004/05/06 12:39:59 nicolas Exp $
26  */

27
28 import java.io.PrintWriter JavaDoc;
29 import java.util.*;
30
31 public class TypeDeclaration
32     extends Declaration
33 {
34     boolean typedefd = false;
35
36     public TypeDeclaration type_decl;
37
38     public TypeDeclaration( int num )
39     {
40         super( num );
41         pack_name = "";
42     }
43
44     public Object JavaDoc clone()
45     {
46         return type_decl.clone();
47     }
48
49
50     public TypeDeclaration declaration()
51     {
52         return type_decl;
53     };
54
55     public String JavaDoc typeName()
56     {
57         return type_decl.typeName();
58     }
59
60     /**
61      * get this types's mapped Java name
62      */

63
64     public String JavaDoc getJavaTypeName()
65     {
66         return type_decl.getJavaTypeName();
67     }
68
69
70     /**
71      * get this symbol's IDL type name
72      */

73
74     public String JavaDoc getIDLTypeName()
75     {
76         return type_decl.getIDLTypeName();
77     }
78
79
80
81     /**
82      * we have to be able to distinguish between explicitly typedef'd
83      * type names and anonymously defined type names
84      */

85
86     public void markTypeDefd( String JavaDoc alias )
87     {
88         type_decl.markTypeDefd( alias );
89     }
90
91     public String JavaDoc getRecursiveTypeCodeExpression()
92     {
93         if( type_decl == null )
94             return "org.omg.CORBA.ORB.init().create_recursive_tc "
95             + "(\"" + id() + "\")";
96         else
97             return type_decl.getRecursiveTypeCodeExpression();
98     }
99
100     /**
101      * Returns a type code expression (for use in generated code) for
102      * this type. If `knownTypes' contains this type,
103      * then a recursive type code is returned.
104      */

105
106     public String JavaDoc getTypeCodeExpression( Set knownTypes )
107     {
108         if( type_decl instanceof Value )
109             return type_decl.getTypeCodeExpression( knownTypes );
110         else
111             return type_decl.getTypeCodeExpression();
112     }
113
114     /**
115      * @return a string for an expression of type TypeCode
116      * that describes this type
117      */

118     public String JavaDoc getTypeCodeExpression()
119     {
120         return type_decl.getTypeCodeExpression();
121     }
122
123     public boolean basic()
124     {
125         return type_decl.basic();
126     }
127
128     public void setPackage( String JavaDoc s )
129     {
130         s = parser.pack_replace( s );
131         type_decl.setPackage( s );
132     }
133
134     public void set_included( boolean i )
135     {
136         included = i;
137         type_decl.set_included( i );
138     }
139
140     public void parse()
141     {
142         type_decl.parse();
143     }
144
145     public String JavaDoc holderName()
146     {
147         return type_decl.holderName();
148     }
149
150     public void print( PrintWriter JavaDoc ps )
151     {
152         type_decl.print( ps );
153     }
154
155     public String JavaDoc toString()
156     {
157         return type_decl.toString();
158     }
159
160     public void setEnclosingSymbol( IdlSymbol s )
161     {
162         if( enclosing_symbol != null && enclosing_symbol != s )
163         {
164             logger.error("was " + enclosing_symbol.getClass().getName() + " now: " + s.getClass().getName() );
165             throw new RuntimeException JavaDoc( "Compiler Error: trying to reassign container for " + name );
166         }
167         enclosing_symbol = s;
168         type_decl.setEnclosingSymbol( s );
169     }
170
171     public String JavaDoc printReadExpression( String JavaDoc streamname )
172     {
173         return type_decl.printReadExpression( streamname );
174     }
175
176     public String JavaDoc printReadStatement( String JavaDoc var_name, String JavaDoc streamname )
177     {
178         return var_name + "=" + printReadExpression( streamname ) + ";";
179     }
180
181     public String JavaDoc printWriteStatement( String JavaDoc var_name, String JavaDoc streamname )
182     {
183         return type_decl.printWriteStatement( var_name, streamname );
184     }
185
186     public void accept( IDLTreeVisitor visitor )
187     {
188         type_decl.accept( visitor );
189     }
190 }
191
Popular Tags