KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * CSharpModifier.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 /**
37  * A class containing the C# modifier constants. This class shouldn't
38  * be used directly, but each class should declare it's own constants
39  * being equal to the constants here.
40  *
41  * @author Per Cederberg, <per at percederberg dot net>
42  * @version 1.0
43  */

44 abstract class CSharpModifier {
45
46     /**
47      * The public access modifier constant.
48      */

49     public static final int PUBLIC = 1;
50
51     /**
52      * The protected internal access modifier constant.
53      */

54     public static final int PROTECTED_INTERNAL = 2;
55
56     /**
57      * The protected access modifier constant.
58      */

59     public static final int PROTECTED = 3;
60
61     /**
62      * The internal access modifier constant.
63      */

64     public static final int INTERNAL = 4;
65
66     /**
67      * The private access modifier constant.
68      */

69     public static final int PRIVATE = 5;
70
71     /**
72      * The static modifier constant.
73      */

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

79     public static final int NEW = 16;
80
81     /**
82      * The virtual modifier constant.
83      */

84     public static final int VIRTUAL = 32;
85
86     /**
87      * The sealed modifier constant.
88      */

89     public static final int SEALED = 64;
90
91     /**
92      * The override modifier constant.
93      */

94     public static final int OVERRIDE = 128;
95
96     /**
97      * The abstract modifier constant.
98      */

99     public static final int ABSTRACT = 256;
100
101     /**
102      * The extern modifier constant.
103      */

104     public static final int EXTERN = 512;
105
106     /**
107      * The const modifier constant.
108      */

109     public static final int CONST = 1024;
110
111     /**
112      * The readonly modifier constant.
113      */

114     public static final int READONLY = 2048;
115
116     /**
117      * The volatile modifier constant.
118      */

119     public static final int VOLATILE = 4096;
120
121     /**
122      * Creates a string with the specified modifiers.
123      *
124      * @param modifiers the modifier flags
125      *
126      * @return a string representation of the modfier flags
127      */

128     public static String JavaDoc createModifierDecl(int modifiers) {
129         StringBuffer JavaDoc res = new StringBuffer JavaDoc();
130
131         // Append access modifier
132
switch (modifiers % 8) {
133         case PUBLIC:
134             res.append("public ");
135             break;
136         case PROTECTED_INTERNAL:
137             res.append("protected internal ");
138             break;
139         case PROTECTED:
140             res.append("protected ");
141             break;
142         case INTERNAL:
143             res.append("internal ");
144             break;
145         case PRIVATE:
146             res.append("private ");
147             break;
148         }
149
150         // Append other modifiers
151
if ((modifiers & STATIC) > 0) {
152             res.append("static ");
153         }
154         if ((modifiers & NEW) > 0) {
155             res.append("new ");
156         }
157         if ((modifiers & VIRTUAL) > 0) {
158             res.append("virtual ");
159         }
160         if ((modifiers & SEALED) > 0) {
161             res.append("sealed ");
162         }
163         if ((modifiers & OVERRIDE) > 0) {
164             res.append("override ");
165         }
166         if ((modifiers & ABSTRACT) > 0) {
167             res.append("abstract ");
168         }
169         if ((modifiers & EXTERN) > 0) {
170             res.append("extern ");
171         }
172         if ((modifiers & CONST) > 0) {
173             res.append("const ");
174         }
175         if ((modifiers & READONLY) > 0) {
176             res.append("readonly ");
177         }
178         if ((modifiers & VOLATILE) > 0) {
179             res.append("volatile ");
180         }
181
182         return res.toString();
183     }
184 }
185
Popular Tags