KickJava   Java API By Example, From Geeks To Geeks.

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


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

22
23 /**
24  *
25  * @version $Id: ElementSpec.java,v 1.19 2004/05/06 12:39:58 nicolas Exp $
26  */

27
28 class ElementSpec
29     extends IdlSymbol
30 {
31     public TypeSpec t = new TypeSpec( new_num() );
32     public Declarator d = null;
33     private UnionType containingUnion;
34
35     public ElementSpec( int num )
36     {
37         super( num );
38     }
39
40     public void setPackage( String JavaDoc s )
41     {
42         s = parser.pack_replace( s );
43         if( pack_name.length() > 0 )
44             pack_name = s + "." + pack_name;
45         else
46             pack_name = s;
47         t.setPackage( s );
48         d.setPackage( s );
49     }
50
51     public void setUnion( UnionType ut )
52     {
53         containingUnion = ut;
54
55         // If its a constrType and is a pseudoscope add union name
56
if (t.typeSpec () instanceof ConstrTypeSpec)
57         {
58            String JavaDoc tmpRef = ((ConstrTypeSpec)t.typeSpec ()).c_type_spec.pack_name;
59
60            if (tmpRef.endsWith ("PackagePackage") || ! tmpRef.startsWith ("_") && tmpRef.endsWith ("Package"))
61            {
62               tmpRef = tmpRef.substring( 0, tmpRef.lastIndexOf( "Package" ) );
63            }
64            if (ScopedName.isPseudoScope (tmpRef))
65            {
66               ((ConstrTypeSpec)t.typeSpec ()).c_type_spec.pack_name =
67                  ((ConstrTypeSpec)t.typeSpec ()).c_type_spec.pack_name + "." + ut.name + "Package";
68            }
69         }
70     }
71
72     public void setEnclosingSymbol( IdlSymbol s )
73     {
74         t.setEnclosingSymbol( s );
75         d.setEnclosingSymbol( s );
76     }
77
78     public void parse()
79     {
80
81         if( logger.isDebugEnabled() )
82         {
83             logger.debug("EelementSpec.parse(): element_spec is " + t.typeSpec().getClass().getName());
84         }
85
86         if( t.typeSpec() instanceof TemplateTypeSpec ||
87             t.typeSpec() instanceof ConstrTypeSpec )
88         {
89             t.parse();
90             if( t.typeSpec() instanceof SequenceType )
91             {
92                 TypeSpec ts = ( (SequenceType)t.typeSpec() ).elementTypeSpec().typeSpec();
93                 SequenceType seqTs = (SequenceType)t.typeSpec();
94                 while( ts instanceof SequenceType )
95                 {
96                     seqTs = (SequenceType)ts;
97                     ts = ( (SequenceType)ts.typeSpec() ).elementTypeSpec().typeSpec();
98                 }
99
100                 // if( ts.typeName().equals( containingUnion.typeName() ) ||
101
if( ScopedName.isRecursionScope( ts.typeName() ) )
102                 {
103                     ( (SequenceType)seqTs.typeSpec() ).setRecursive();
104                 }
105             }
106         }
107         else if( t.typeSpec() instanceof ScopedName )
108         {
109             TypeSpec ts = ( (ScopedName)t.typeSpec() ).resolvedTypeSpec();
110             if( ts.typeName().equals( containingUnion.typeName() ) )
111             {
112                 parser.error( "Illegal recursion in union " + containingUnion.full_name(), token );
113             }
114
115             containingUnion.addImportedName( ts.typeName() );
116
117             // if( ts != null )
118

119             // fix for bug#115: only set the element spec's type spec to the resolved
120
// type if it is not an Interface! Otherwise the compile may loop!
121
if( ! ( ts instanceof ConstrTypeSpec &&
122                     ((ConstrTypeSpec)ts).declaration() instanceof Interface) )
123             {
124                 t = ts;
125             }
126         }
127
128         try
129         {
130             NameTable.define( containingUnion.full_name() + "." + d.name(), "declarator" );
131         }
132         catch( NameAlreadyDefined nad )
133         {
134             parser.error( "Declarator " + d.name() +
135                     " already defined in union " + containingUnion.full_name(), token );
136         }
137
138         if( logger.isDebugEnabled() )
139         {
140             logger.debug("ElementSpec.parse-end(): element_spec is " + t.typeSpec().getClass().getName());
141         }
142     }
143
144     public void print( java.io.PrintWriter JavaDoc ps )
145     {
146         if( t.typeSpec() instanceof TemplateTypeSpec ||
147                 t.typeSpec() instanceof ConstrTypeSpec )
148         {
149             t.print( ps );
150         }
151     }
152
153
154 }
155
Popular Tags