KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > filter > etcl > TCLCleanUp


1 package org.jacorb.notification.filter.etcl;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-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 import antlr.collections.AST;
25
26 /**
27  * Visitor for TCL Trees. Does some Restructuration of a TCL Tree.
28  *
29  * @author Alphonse Bendt
30  * @version $Id: TCLCleanUp.java,v 1.5 2005/02/14 00:07:08 alphonse.bendt Exp $
31  */

32
33 public class TCLCleanUp extends AbstractTCLVisitor implements TCLParserTokenTypes
34 {
35     public void fix( AbstractTCLNode node )
36     {
37         try
38         {
39             node.acceptPostOrder( this );
40         }
41         catch ( VisitorException e )
42         {
43             throw new RuntimeException JavaDoc(e.getMessage());
44         }
45     }
46
47     public void visitComponent( ETCLComponentName component )
48         throws VisitorException
49     {
50         insertComponentName( component );
51     }
52
53     public void visitUnionPosition( UnionPositionOperator op )
54         throws VisitorException
55     {
56         fixUnionPosition( op );
57     }
58
59     /**
60      * insert the Complete Name of a Component in the
61      * ComponentOperator node.
62      */

63     void insertComponentName( ETCLComponentName comp )
64     {
65         StringBuffer JavaDoc _name =
66             new StringBuffer JavaDoc( comp.toString() );
67
68         AbstractTCLNode _cursor =
69             comp.left();
70
71         while ( _cursor != null )
72         {
73             _name.append( _cursor.toString() );
74             _cursor = ( AbstractTCLNode ) _cursor.getNextSibling();
75         }
76
77         comp.setComponentName( _name.toString() );
78     }
79
80     private void fixUnionPosition( UnionPositionOperator node )
81     {
82         AST _nextSibling = node.getNextSibling();
83
84         if ( _nextSibling == null )
85         {
86             node.setDefault();
87         }
88         else
89         {
90             switch ( _nextSibling.getType() )
91             {
92                 case NUMBER:
93                     Double JavaDoc _position = ( ( NumberValue ) _nextSibling ).getNumber();
94                     node.setPosition( _position );
95                     node.setNextSibling( _nextSibling.getNextSibling() );
96
97                     // fallthrough
98
case PLUS:
99                     // fallthrough
100
case MINUS:
101                     // fallthrough
102
case STRING:
103                     break;
104
105                 default:
106                     node.setDefault();
107                     break;
108             }
109         }
110     }
111 }
112
Popular Tags