KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > antlr > NameSpace


1 package antlr;
2
3 /**
4  * ANTLR Translator Generator
5  * Project led by Terence Parr at http://www.jGuru.com
6  * Software rights: http://www.antlr.org/RIGHTS.html
7  *
8  * Container for a C++ namespace specification. Namespaces can be
9  * nested, so this contains a vector of all the nested names.
10  *
11  * @author David Wagner (JPL/Caltech) 8-12-00
12  *
13  * $Id: //depot/code/org.antlr/main/main/antlr/NameSpace.java#5 $
14  */

15
16 import java.util.Vector JavaDoc;
17 import java.util.Enumeration JavaDoc;
18 import java.io.PrintWriter JavaDoc;
19 import java.util.StringTokenizer JavaDoc;
20
21 public class NameSpace {
22     private Vector JavaDoc names = new Vector JavaDoc();
23
24     public NameSpace(String JavaDoc name) {
25         parse(name);
26     }
27
28     /**
29      * Parse a C++ namespace declaration into seperate names
30      * splitting on :: We could easily parameterize this to make
31      * the delimiter a language-specific parameter, or use subclasses
32      * to support C++ namespaces versus java packages. -DAW
33      */

34     protected void parse(String JavaDoc name) {
35         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(name, "::");
36         while (tok.hasMoreTokens())
37             names.addElement(tok.nextToken());
38     }
39
40     /**
41      * Method to generate the required C++ namespace declarations
42      */

43     void emitDeclarations(PrintWriter JavaDoc out) {
44         for (Enumeration JavaDoc n = names.elements(); n.hasMoreElements();) {
45             String JavaDoc s = (String JavaDoc)n.nextElement();
46             out.println("ANTLR_BEGIN_NAMESPACE(" + s + ")");
47         }
48     }
49
50     /**
51      * Method to generate the required C++ namespace closures
52      */

53     void emitClosures(PrintWriter JavaDoc out) {
54         for (int i = 0; i < names.size(); ++i)
55             out.println("ANTLR_END_NAMESPACE");
56     }
57 }
58
Popular Tags