KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > percederberg > grammatica > code > visualbasic > VisualBasicFile


1 /*
2  * VisualBasicFile.java
3  *
4  * This work is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  *
9  * This work is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA
18  *
19  * As a special exception, the copyright holders of this library give
20  * you permission to link this library with independent modules to
21  * produce an executable, regardless of the license terms of these
22  * independent modules, and to copy and distribute the resulting
23  * executable under terms of your choice, provided that you also meet,
24  * for each linked independent module, the terms and conditions of the
25  * license of that module. An independent module is a module which is
26  * not derived from or based on this library. If you modify this
27  * library, you may extend this exception to your version of the
28  * library, but you are not obligated to do so. If you do not wish to
29  * do so, delete this exception statement from your version.
30  *
31  * Copyright (c) 2004 Adrian Moore. All rights reserved.
32  * Copyright (c) 2004 Per Cederberg. All rights reserved.
33  */

34
35 package net.percederberg.grammatica.code.visualbasic;
36
37 import java.io.File JavaDoc;
38 import java.io.FileWriter JavaDoc;
39 import java.io.IOException JavaDoc;
40 import java.io.PrintWriter JavaDoc;
41
42 import net.percederberg.grammatica.code.CodeElementContainer;
43 import net.percederberg.grammatica.code.CodeStyle;
44
45 /**
46  * A class generating a Visual Basic source code file.
47  *
48  * @author Adrian Moore, <adrianrob at hotmail dot com>
49  * @author Per Cederberg, <per at percederberg dot net>
50  * @version 1.5
51  * @since 1.5
52  */

53 public class VisualBasicFile extends CodeElementContainer {
54
55     /**
56      * The file to write to.
57      */

58     private File JavaDoc file;
59
60     /**
61      * Creates a new Visual Basic source code file.
62      *
63      * @param basedir the base output directory
64      * @param basename the base file name (without extension)
65      */

66     public VisualBasicFile(File JavaDoc basedir, String JavaDoc basename) {
67         this.file = new File JavaDoc(basedir, basename + ".vb");
68     }
69
70     /**
71      * Returns the file name.
72      *
73      * @return the file name.
74      */

75     public String JavaDoc toString() {
76         return file.getName();
77     }
78
79     /**
80      * Returns a numeric category number for the code element. A lower
81      * category number implies that the code element should be placed
82      * before code elements with a higher category number within a
83      * declaration.
84      *
85      * @return the category number
86      */

87     public int category() {
88         return 0;
89     }
90
91     /**
92      * Adds a file comment.
93      *
94      * @param comment the file comment to add
95      */

96     public void addComment(VisualBasicComment comment) {
97         addElement(comment);
98     }
99
100     /**
101      * Adds an imports declaration to the file.
102      *
103      * @param imports the imports declaration to add
104      */

105     public void addImports(VisualBasicImports imports) {
106         addElement(imports);
107     }
108
109     /**
110      * Adds a namespace declaration to the file.
111      *
112      * @param namespace the namespace declaration to add
113      */

114     public void addNamespace(VisualBasicNamespace namespace) {
115         addElement(namespace);
116     }
117
118     /**
119      * Adds a class declaration to the file.
120      *
121      * @param c the class declaration to add
122      */

123     public void addClass(VisualBasicClass c) {
124         addElement(c);
125     }
126
127     /**
128      * Adds an enumeration declaration to the file.
129      *
130      * @param e the enumeration to add
131      */

132     public void addEnumeration(VisualBasicEnumeration e) {
133         addElement(e);
134     }
135
136     /**
137      * Writes the source code for this file. Any previous file with
138      * this name will be overwritten.
139      *
140      * @param style the code style to use
141      *
142      * @throws IOException if the file could not be written properly
143      */

144     public void writeCode(CodeStyle style) throws IOException JavaDoc {
145         PrintWriter JavaDoc out;
146
147         createFile(file);
148         out = new PrintWriter JavaDoc(new FileWriter JavaDoc(file));
149         print(out, style, 0);
150         out.close();
151     }
152
153     /**
154      * Prints the file contents to the specified output stream.
155      *
156      * @param out the output stream
157      * @param style the code style to use
158      * @param indent the indentation level
159      */

160     public void print(PrintWriter JavaDoc out, CodeStyle style, int indent) {
161         printContents(out, style, indent);
162     }
163 }
164
Popular Tags