KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * VisualBasicClass.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.PrintWriter JavaDoc;
38
39 import net.percederberg.grammatica.code.CodeElement;
40 import net.percederberg.grammatica.code.CodeStyle;
41
42 /**
43  * A class generating a Visual Basic class declaration.
44  *
45  * @author Adrian Moore, <adrianrob at hotmail dot com>
46  * @author Per Cederberg, <per at percederberg dot net>
47  * @version 1.5
48  * @since 1.5
49  */

50 public class VisualBasicClass extends VisualBasicType {
51
52     /**
53      * The public access modifier constant.
54      */

55     public static final int PUBLIC = VisualBasicModifier.PUBLIC;
56
57     /**
58      * The protected internal access modifier constant. May only be
59      * used when declared inside another type.
60      */

61     public static final int PROTECTED_FRIEND =
62         VisualBasicModifier.PROTECTED_FRIEND;
63
64     /**
65      * The protected access modifier constant. May only be used when
66      * declared inside another type.
67      */

68     public static final int PROTECTED = VisualBasicModifier.PROTECTED;
69
70     /**
71      * The internal access modifier constant.
72      */

73     public static final int FRIEND = VisualBasicModifier.FRIEND;
74
75     /**
76      * The private access modifier constant. May only be used when
77      * declared inside another type.
78      */

79     public static final int PRIVATE = VisualBasicModifier.PRIVATE;
80
81     /**
82      * The must inherit modifier constant.
83      */

84     public static final int MUST_INHERIT = VisualBasicModifier.MUST_INHERIT;
85
86     /**
87      * The not inheritable modifier constant.
88      */

89     public static final int NOT_INHERITABLE =
90         VisualBasicModifier.NOT_INHERITABLE;
91
92     /**
93      * The shadows modifier constant. May only be used when declared
94      * inside another type.
95      */

96     public static final int SHADOWS = VisualBasicModifier.SHADOWS;
97
98     /**
99      * Creates a new class code generator with a public access
100      * modifier.
101      *
102      * @param name the class name
103      */

104     public VisualBasicClass(String JavaDoc name) {
105         this(PUBLIC, name);
106     }
107
108     /**
109      * Creates a new class code generator with the specified
110      * modifiers.
111      *
112      * @param modifiers the modifier flag constants
113      * @param name the class name
114      */

115     public VisualBasicClass(int modifiers, String JavaDoc name) {
116         this(modifiers, name, "");
117     }
118
119     /**
120      * Creates a new class code generator with the specified access
121      * modifier that extends the specified class.
122      *
123      * @param modifiers the modifier flag constants
124      * @param name the class name
125      * @param extendsClass the class to extend or implement
126      */

127     public VisualBasicClass(int modifiers, String JavaDoc name, String JavaDoc extendsClass) {
128         super(modifiers, name, extendsClass);
129     }
130
131     /**
132      * Creates a new class code generator with the specified access
133      * modifier that extends and implements the specified classes or
134      * interfaces.
135      *
136      * @param modifiers the modifier flag constants
137      * @param name the class name
138      * @param extendClasses the classes to extend or implement
139      */

140     public VisualBasicClass(int modifiers,
141                             String JavaDoc name,
142                             String JavaDoc[] extendClasses) {
143
144         super(modifiers, name, extendClasses);
145     }
146
147     /**
148      * Returns a numeric category number for the code element. A lower
149      * category number implies that the code element should be placed
150      * before code elements with a higher category number within a
151      * declaration.
152      *
153      * @return the category number
154      */

155     public int category() {
156         return 10;
157     }
158
159     /**
160      * Adds an inner class as a member.
161      *
162      * @param member the inner class to add
163      */

164     public void addClass(VisualBasicClass member) {
165         addElement(member);
166     }
167
168     /**
169      * Adds an enumeration as a member.
170      *
171      * @param member the enumeration to add
172      */

173     public void addEnumeration(VisualBasicEnumeration member) {
174         addElement(member);
175     }
176
177     /**
178      * Adds a constructor to the class.
179      *
180      * @param member the member to add
181      */

182     public void addConstructor(VisualBasicConstructor member) {
183         member.setVisualBasicClass(this);
184         addElement(member);
185     }
186
187     /**
188      * Adds a method to the class.
189      *
190      * @param member the member to add
191      */

192     public void addMethod(VisualBasicMethod member) {
193         addElement(member);
194     }
195
196     /**
197      * Prints the class to the specified stream.
198      *
199      * @param out the output stream
200      * @param style the code style to use
201      * @param indent the indentation level
202      */

203     public void print(PrintWriter JavaDoc out, CodeStyle style, int indent) {
204         print(out, style, indent, "Class");
205     }
206
207     /**
208      * Prints the lines separating two elements.
209      *
210      * @param out the output stream
211      * @param style the code style to use
212      * @param prev the previous element, or null if first
213      * @param next the next element, or null if last
214      */

215     protected void printSeparator(PrintWriter JavaDoc out,
216                                   CodeStyle style,
217                                   CodeElement prev,
218                                   CodeElement next) {
219
220         if (next == null) {
221             // Do nothing
222
} else {
223             out.println();
224         }
225     }
226 }
227
Popular Tags