KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

54     public static final int PROTECTED = 1;
55
56     /**
57      * The package local access modifier constant (i.e. no modifier).
58      */

59     public static final int PACKAGE_LOCAL = 2;
60
61     /**
62      * The private access modifier constant.
63      */

64     public static final int PRIVATE = 3;
65
66     /**
67      * The static modifier.
68      */

69     public static final int STATIC = 4;
70
71     /**
72      * The abstract modifier.
73      */

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

79     public static final int FINAL = 16;
80
81     /**
82      * The synchronized modifier.
83      */

84     public static final int SYNCHRONIZED = 32;
85
86     /**
87      * The abstract modifier.
88      */

89     public static final int NATIVE = 64;
90
91     /**
92      * The transient modifier.
93      */

94     public static final int TRANSIENT = 128;
95
96     /**
97      * The volatile modifier.
98      */

99     public static final int VOLATILE = 256;
100
101     /**
102      * The synchronized modifier.
103      */

104     public static final int STRICTFP = 512;
105
106     /**
107      * Creates a string with the specified modifiers.
108      *
109      * @param modifiers the modfier values
110      *
111      * @return a string description of the modfiers
112      */

113     public static String JavaDoc createModifierDecl(int modifiers) {
114         StringBuffer JavaDoc res = new StringBuffer JavaDoc();
115
116         // Set access modifier
117
switch (modifiers % 4) {
118         case PUBLIC:
119             res.append("public ");
120             break;
121         case PROTECTED:
122             res.append("protected ");
123             break;
124         case PACKAGE_LOCAL:
125             break;
126         case PRIVATE:
127             res.append("private ");
128             break;
129         }
130
131         // Set other modifiers
132
if ((modifiers & STATIC) > 0) {
133             res.append("static ");
134         }
135         if ((modifiers & ABSTRACT) > 0) {
136             res.append("abstract ");
137         }
138         if ((modifiers & FINAL) > 0) {
139             res.append("final ");
140         }
141         if ((modifiers & SYNCHRONIZED) > 0) {
142             res.append("synchronized ");
143         }
144         if ((modifiers & NATIVE) > 0) {
145             res.append("native ");
146         }
147         if ((modifiers & TRANSIENT) > 0) {
148             res.append("transient ");
149         }
150         if ((modifiers & VOLATILE) > 0) {
151             res.append("volatile ");
152         }
153         if ((modifiers & STRICTFP) > 0) {
154             res.append("strictfp ");
155         }
156
157         return res.toString();
158     }
159 }
160
Popular Tags