KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * VisualBasicModifier.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 /**
38  * A class containing the Visual Basic modifier constants. This class
39  * shouldn't be used directly, but each class should declare it's own
40  * constants being equal to the constants here.
41  *
42  * @author Adrian Moore, <adrianrob at hotmail dot com>
43  * @author Per Cederberg, <per at percederberg dot net>
44  * @version 1.5
45  * @since 1.5
46  */

47 abstract class VisualBasicModifier {
48
49     /**
50      * The public access modifier constant.
51      */

52     public static final int PUBLIC = 1;
53
54     /**
55      * The protected friend access modifier constant.
56      */

57     public static final int PROTECTED_FRIEND = 2;
58
59     /**
60      * The protected access modifier constant.
61      */

62     public static final int PROTECTED = 3;
63
64     /**
65      * The friend access modifier constant.
66      */

67     public static final int FRIEND = 4;
68
69     /**
70      * The private access modifier constant.
71      */

72     public static final int PRIVATE = 5;
73
74     /**
75      * The must inherit modifier constant.
76      */

77     public static final int MUST_INHERIT = 8;
78
79     /**
80      * The not inheritable modifier constant.
81      */

82     public static final int NOT_INHERITABLE = 16;
83
84     /**
85      * The shared modifier constant.
86      */

87     public static final int SHARED = 32;
88
89     /**
90      * The shadows modifier constant.
91      */

92     public static final int SHADOWS = 64;
93
94     /**
95      * The overridable modifier constant.
96      */

97     public static final int OVERRIDABLE = 128;
98
99     /**
100      * The not overridable modifier constant.
101      */

102     public static final int NOT_OVERRIDABLE = 256;
103
104     /**
105      * The overrides modifier constant.
106      */

107     public static final int OVERRIDES = 512;
108
109     /**
110      * The must override modifier constant.
111      */

112     public static final int MUST_OVERRIDE = 1024;
113
114     /**
115      * The overloads modifier constant.
116      */

117     public static final int OVERLOADS = 2048;
118
119     /**
120      * Creates a string with the specified modifiers.
121      *
122      * @param modifiers the modifier flags
123      *
124      * @return a string representation of the modfier flags
125      */

126     public static String JavaDoc createModifierDecl(int modifiers) {
127         StringBuffer JavaDoc res = new StringBuffer JavaDoc();
128
129         // Append access modifier
130
switch (modifiers % 8) {
131         case PUBLIC:
132             res.append("Public ");
133             break;
134         case PROTECTED_FRIEND:
135             res.append("Protected Friend ");
136             break;
137         case PROTECTED:
138             res.append("Protected ");
139             break;
140         case FRIEND:
141             res.append("Friend ");
142             break;
143         case PRIVATE:
144             res.append("Private ");
145             break;
146         }
147
148         // Append other modifiers
149
if ((modifiers & MUST_INHERIT) > 0) {
150             res.append("MustInherit ");
151         }
152         if ((modifiers & NOT_INHERITABLE) > 0) {
153             res.append("NotInheritable ");
154         }
155         if ((modifiers & SHARED) > 0) {
156             res.append("Shared ");
157         }
158         if ((modifiers & SHADOWS) > 0) {
159             res.append("Shadows ");
160         }
161         if ((modifiers & OVERRIDABLE) > 0) {
162             res.append("Overridable ");
163         }
164         if ((modifiers & NOT_OVERRIDABLE) > 0) {
165             res.append("NotOverridable ");
166         }
167         if ((modifiers & OVERRIDES) > 0) {
168             res.append("Overrides ");
169         }
170         if ((modifiers & MUST_OVERRIDE) > 0) {
171             res.append("MustOverride ");
172         }
173         if ((modifiers & OVERLOADS) > 0) {
174             res.append("Overloads ");
175         }
176
177         return res.toString();
178     }
179 }
180
Popular Tags