KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > percederberg > grammatica > code > java > JavaClass


1 /*
2  * JavaClass.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.java;
35
36 import java.io.PrintWriter JavaDoc;
37
38 import net.percederberg.grammatica.code.CodeStyle;
39
40 /**
41  * A class generating a Java class declaration.
42  *
43  * @author Per Cederberg, <per at percederberg dot net>
44  * @version 1.0
45  */

46 public class JavaClass extends JavaType {
47
48     /**
49      * The public access modifier constant.
50      */

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

57     public static final int PROTECTED = JavaModifier.PROTECTED;
58
59     /**
60      * The package local access modifier constant (i.e. no modifier).
61      */

62     public static final int PACKAGE_LOCAL = JavaModifier.PACKAGE_LOCAL;
63
64     /**
65      * The private access modifier constant. May only be used when
66      * declared inside another class.
67      */

68     public static final int PRIVATE = JavaModifier.PRIVATE;
69
70     /**
71      * The static modifier constant. May only be used when declared
72      * inside another class.
73      */

74     public static final int STATIC = JavaModifier.STATIC;
75
76     /**
77      * The abstract modifier constant.
78      */

79     public static final int ABSTRACT = JavaModifier.ABSTRACT;
80
81     /**
82      * The final modifier constant.
83      */

84     public static final int FINAL = JavaModifier.FINAL;
85
86     /**
87      * The strictfp modifier constant.
88      */

89     public static final int STRICTFP = JavaModifier.STRICTFP;
90
91     /**
92      * Creates a new class code generator with a public access
93      * modifier.
94      *
95      * @param name the class name
96      */

97     public JavaClass(String JavaDoc name) {
98         this(PUBLIC, name);
99     }
100
101     /**
102      * Creates a new class code generator with the specified access
103      * modifier.
104      *
105      * @param modifiers the modifier constant flags
106      * @param name the class name
107      */

108     public JavaClass(int modifiers, String JavaDoc name) {
109         this(modifiers, name, "");
110     }
111
112     /**
113      * Creates a new class code generator with the specified access
114      * modifier that extends the specified class.
115      *
116      * @param modifiers the modifier constant flags
117      * @param name the class name
118      * @param extendClass the class to extend
119      */

120     public JavaClass(int modifiers, String JavaDoc name, String JavaDoc extendClass) {
121         this(modifiers, name, extendClass, "");
122     }
123
124     /**
125      * Creates a new class code generator with the specified access
126      * modifier that extends and implements the specified classes or
127      * interfaces.
128      *
129      * @param modifiers the modifier constant flags
130      * @param name the class name
131      * @param extendClass the class to extend
132      * @param implementClass the class to implement
133      */

134     public JavaClass(int modifiers,
135                      String JavaDoc name,
136                      String JavaDoc extendClass,
137                      String JavaDoc implementClass) {
138
139         super(modifiers, name, extendClass, implementClass);
140     }
141
142     /**
143      * Creates a new class code generator with the specified access
144      * modifier that extends and implements the specified classes or
145      * interfaces.
146      *
147      * @param modifiers the modifier constant flags
148      * @param name the class name
149      * @param extendClass the class to extend
150      * @param implementClasses the classes to implement
151      */

152     public JavaClass(int modifiers,
153                      String JavaDoc name,
154                      String JavaDoc extendClass,
155                      String JavaDoc[] implementClasses) {
156
157         super(modifiers, name, extendClass, implementClasses);
158     }
159
160     /**
161      * Adds an inner class to this class.
162      *
163      * @param member the member to add
164      */

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

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

184     public void addMethod(JavaMethod member) {
185         addElement(member);
186     }
187
188     /**
189      * Adds a variable to the class.
190      *
191      * @param member the member to add
192      */

193     public void addVariable(JavaVariable member) {
194         addElement(member);
195     }
196
197     /**
198      * Returns a numeric category number for the code element. A lower
199      * category number implies that the code element should be placed
200      * before code elements with a higher category number within a
201      * declaration.
202      *
203      * @return the category number
204      */

205     public int category() {
206         return 9;
207     }
208
209     /**
210      * Prints the code element to the specified output stream.
211      *
212      * @param out the output stream
213      * @param style the code style to use
214      * @param indent the indentation level
215      */

216     public void print(PrintWriter JavaDoc out, CodeStyle style, int indent) {
217         print(out, style, indent, "class");
218     }
219 }
220
Popular Tags