KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * JavaInterface.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 interface declaration.
42  *
43  * @author Per Cederberg, <per at percederberg dot net>
44  * @version 1.0
45  */

46 public class JavaInterface 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 a 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 a 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 a class.
73      */

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

79     public static final int STRICTFP = JavaModifier.STRICTFP;
80
81     /**
82      * Creates a new interface code generator with a public access
83      * modifier.
84      *
85      * @param name the class name
86      */

87     public JavaInterface(String JavaDoc name) {
88         this(PUBLIC, name);
89     }
90
91     /**
92      * Creates a new interface code generator with the specified
93      * access modifier.
94      *
95      * @param modifiers the modifier constant flags
96      * @param name the class name
97      */

98     public JavaInterface(int modifiers, String JavaDoc name) {
99         this(modifiers, name, "");
100     }
101
102     /**
103      * Creates a new class code generator with the specified access
104      * modifier that extends the specified class.
105      *
106      * @param modifiers the modifier constant flags
107      * @param name the class name
108      * @param extendType the type to extend
109      */

110     public JavaInterface(int modifiers, String JavaDoc name, String JavaDoc extendType) {
111         super(modifiers, name, extendType, "");
112     }
113
114     /**
115      * Adds a method declaration to the interface.
116      *
117      * @param member the member to add
118      */

119     public void addMethod(JavaMethod member) {
120         member.setPrintCode(false);
121         addElement(member);
122     }
123
124     /**
125      * Adds a variable to the interface.
126      *
127      * @param member the member to add
128      */

129     public void addVariable(JavaVariable member) {
130         addElement(member);
131     }
132
133     /**
134      * Returns a numeric category number for the code element. A lower
135      * category number implies that the code element should be placed
136      * before code elements with a higher category number within a
137      * declaration.
138      *
139      * @return the category number
140      */

141     public int category() {
142         return 9;
143     }
144
145     /**
146      * Prints the code element to the specified output stream.
147      *
148      * @param out the output stream
149      * @param style the code style to use
150      * @param indent the indentation level
151      */

152     public void print(PrintWriter JavaDoc out, CodeStyle style, int indent) {
153         super.print(out, style, indent, "interface");
154     }
155 }
156
Popular Tags