KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.io.PrintWriter JavaDoc;
24
25 /**
26  * @author Gerald Brose
27  * @version $Id: PrimaryExpr.java,v 1.18 2004/05/06 12:39:58 nicolas Exp $
28  */

29
30 class PrimaryExpr
31     extends IdlSymbol
32 {
33     public IdlSymbol symbol;
34
35     private boolean contained = false;
36     private ConstDecl declared_in;
37
38     public PrimaryExpr( int num )
39     {
40         super( num );
41     }
42
43     public void print( PrintWriter JavaDoc ps )
44     {
45         if( symbol instanceof ConstExpr )
46         {
47             ps.print( "(" );
48             symbol.print( ps );
49             ps.print( ")" );
50         }
51         else if( symbol instanceof ScopedName )
52         {
53             ps.print( ( (ScopedName)symbol ).resolvedName() );
54         }
55         else // Literal
56
symbol.print( ps );
57     }
58
59     public void parse()
60     {
61         symbol.parse();
62     }
63
64     public void setDeclaration( ConstDecl declared_in )
65     {
66         this.declared_in = declared_in;
67         if( symbol instanceof Literal )
68             ( (Literal)symbol ).setDeclaration( declared_in );
69     }
70
71     public void setPackage( String JavaDoc s )
72     {
73         s = parser.pack_replace( s );
74         if( pack_name.length() > 0 )
75             pack_name = s + "." + pack_name;
76         else
77             pack_name = s;
78
79         symbol.setPackage( s );
80     }
81
82     int pos_int_const()
83     {
84         if( symbol instanceof ConstExpr )
85         {
86             return ( (ConstExpr)symbol ).pos_int_const();
87         }
88         else if( symbol instanceof ScopedName )
89         {
90             ConstExprEvaluator eval =
91                 new ConstExprEvaluator( ConstDecl.namedValue( (ScopedName)symbol ));
92             if( logger.isDebugEnabled() )
93                 logger.debug( "PrimaryExpr: returning value " + eval.getValue().intValue());
94
95             return eval.getValue().intValue();
96         }
97         else
98             return Integer.parseInt( ( (Literal)symbol ).toString() );
99     }
100
101     public String JavaDoc value()
102     {
103         if( symbol instanceof ConstExpr )
104         {
105             return "(" + ( (ConstExpr)symbol ).value() + ")";
106         }
107         else if( symbol instanceof ScopedName )
108         {
109             return ConstDecl.namedValue( (ScopedName)symbol );
110         }
111         else
112             return ( (Literal)symbol ).toString();
113     }
114
115     public String JavaDoc toString()
116     {
117         if( symbol instanceof ConstExpr )
118         {
119             return "(" + ( (ConstExpr)symbol ).toString() + ")";
120         }
121         else if( symbol instanceof ScopedName )
122         {
123             return ( (ScopedName)symbol ).resolvedName();
124         }
125         else
126         {
127             return ( (Literal)symbol ).toString();
128         }
129     }
130
131     public str_token get_token()
132     {
133         return symbol.get_token();
134     }
135 }
136
Popular Tags