KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > percederberg > grammatica > code > csharp > CSharpClass


1 /*
2  * CSharpClass.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) 2003 Per Cederberg. All rights reserved.
32  */

33
34 package net.percederberg.grammatica.code.csharp;
35
36 import java.io.PrintWriter JavaDoc;
37
38 import net.percederberg.grammatica.code.CodeElement;
39 import net.percederberg.grammatica.code.CodeStyle;
40
41 /**
42  * A class generating a C# class declaration.
43  *
44  * @author Per Cederberg, <per at percederberg dot net>
45  * @version 1.0
46  */

47 public class CSharpClass extends CSharpType {
48
49     /**
50      * The public access modifier constant.
51      */

52     public static final int PUBLIC = CSharpModifier.PUBLIC;
53
54     /**
55      * The protected internal access modifier constant. May only be
56      * used when declared inside another type.
57      */

58     public static final int PROTECTED_INTERNAL =
59         CSharpModifier.PROTECTED_INTERNAL;
60
61     /**
62      * The protected access modifier constant. May only be used when
63      * declared inside another type.
64      */

65     public static final int PROTECTED = CSharpModifier.PROTECTED;
66
67     /**
68      * The internal access modifier constant.
69      */

70     public static final int INTERNAL = CSharpModifier.INTERNAL;
71
72     /**
73      * The private access modifier constant. May only be used when
74      * declared inside another type.
75      */

76     public static final int PRIVATE = CSharpModifier.PRIVATE;
77
78     /**
79      * The abstract modifier constant.
80      */

81     public static final int ABSTRACT = CSharpModifier.ABSTRACT;
82
83     /**
84      * The sealed modifier constant.
85      */

86     public static final int SEALED = CSharpModifier.SEALED;
87
88     /**
89      * The new modifier constant. May only be used when declared
90      * inside another type.
91      */

92     public static final int NEW = CSharpModifier.NEW;
93
94     /**
95      * Creates a new class code generator with a public access
96      * modifier.
97      *
98      * @param name the class name
99      */

100     public CSharpClass(String JavaDoc name) {
101         this(PUBLIC, name);
102     }
103
104     /**
105      * Creates a new class code generator with the specified
106      * modifiers.
107      *
108      * @param modifiers the modifier flag constants
109      * @param name the class name
110      */

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

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

136     public CSharpClass(int modifiers, String JavaDoc name, String JavaDoc[] extendClasses) {
137         super(modifiers, name, extendClasses);
138     }
139
140     /**
141      * Returns a numeric category number for the code element. A lower
142      * category number implies that the code element should be placed
143      * before code elements with a higher category number within a
144      * declaration.
145      *
146      * @return the category number
147      */

148     public int category() {
149         return 10;
150     }
151
152     /**
153      * Adds an inner class as a member.
154      *
155      * @param member the inner class to add
156      */

157     public void addClass(CSharpClass member) {
158         addElement(member);
159     }
160
161     /**
162      * Adds an enumeration as a member.
163      *
164      * @param member the enumeration to add
165      */

166     public void addEnumeration(CSharpEnumeration member) {
167         addElement(member);
168     }
169
170     /**
171      * Adds a constructor to the class.
172      *
173      * @param member the member to add
174      */

175     public void addConstructor(CSharpConstructor member) {
176         member.setCSharpClass(this);
177         addElement(member);
178     }
179
180     /**
181      * Adds a method to the class.
182      *
183      * @param member the member to add
184      */

185     public void addMethod(CSharpMethod member) {
186         addElement(member);
187     }
188
189     /**
190      * Prints the class to the specified stream.
191      *
192      * @param out the output stream
193      * @param style the code style to use
194      * @param indent the indentation level
195      */

196     public void print(PrintWriter JavaDoc out, CodeStyle style, int indent) {
197         print(out, style, indent, "class");
198     }
199
200     /**
201      * Prints the lines separating two elements.
202      *
203      * @param out the output stream
204      * @param style the code style to use
205      * @param prev the previous element, or null if first
206      * @param next the next element, or null if last
207      */

208     protected void printSeparator(PrintWriter JavaDoc out,
209                                   CodeStyle style,
210                                   CodeElement prev,
211                                   CodeElement next) {
212
213         if (next == null) {
214             // Do nothing
215
} else {
216             out.println();
217         }
218     }
219 }
220
Popular Tags