KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > Modifier


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997-1999 Raja Vallee-Rai
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27
28
29 // Incomplete class
30

31 package soot;
32
33
34
35
36 /**
37  * A class that provides static methods and constants to represent and
38  * work with with Java modifiers (ie public, final,...)
39  * Represents Java modifiers as int constants that can be packed and
40  * combined by bitwise operations and methods to query these.
41  *
42  */

43 public class Modifier
44 {
45     public static final int ABSTRACT = 0x0400;
46     public static final int FINAL = 0x0010;
47     public static final int INTERFACE = 0x0200;
48     public static final int NATIVE = 0x0100;
49     public static final int PRIVATE = 0x0002;
50     public static final int PROTECTED = 0x0004;
51     public static final int PUBLIC = 0x0001;
52     public static final int STATIC = 0x0008;
53     public static final int SYNCHRONIZED = 0x0020;
54     public static final int TRANSIENT = 0x0080; /* VARARGS for methods */
55     public static final int VOLATILE = 0x0040; /* BRIDGE for methods */
56     public static final int STRICTFP = 0x0800;
57     public static final int ANNOTATION = 0x2000;
58     public static final int ENUM = 0x4000;
59     
60     private Modifier()
61     {
62     }
63
64     public static boolean isAbstract(int m)
65     {
66         return (m & ABSTRACT) != 0;
67     }
68
69     public static boolean isFinal(int m )
70     {
71         return (m & FINAL) != 0;
72     }
73
74     public static boolean isInterface(int m)
75     {
76         return (m & INTERFACE) != 0;
77     }
78
79     public static boolean isNative(int m)
80     {
81         return (m & NATIVE) != 0;
82     }
83
84     public static boolean isPrivate(int m)
85     {
86         return (m & PRIVATE) != 0;
87     }
88
89     public static boolean isProtected(int m)
90     {
91         return (m & PROTECTED) != 0;
92     }
93
94     public static boolean isPublic(int m)
95     {
96         return (m & PUBLIC) != 0;
97     }
98
99     public static boolean isStatic(int m)
100     {
101         return (m & STATIC) != 0;
102     }
103
104     public static boolean isSynchronized(int m)
105     {
106         return (m & SYNCHRONIZED) != 0;
107     }
108
109     public static boolean isTransient(int m )
110     {
111         return (m & TRANSIENT) != 0;
112     }
113
114     public static boolean isVolatile(int m)
115     {
116         return (m & VOLATILE) != 0;
117     }
118
119     public static boolean isStrictFP(int m)
120     {
121         return (m & STRICTFP) != 0;
122     }
123     
124     public static boolean isAnnotation(int m)
125     {
126         return (m & ANNOTATION) != 0;
127     }
128     
129     public static boolean isEnum(int m)
130     {
131         return (m & ENUM) != 0;
132     }
133     
134     /**
135      * Converts the given modifiers to their string representation, in canonical form.
136      * @param m a modifier set
137      * @return a textual representation of the modifiers.
138      */

139     public static String JavaDoc toString(int m)
140     {
141         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
142
143         if(isPublic(m))
144             buffer.append("public ");
145         else if(isPrivate(m))
146             buffer.append("private ");
147         else if(isProtected(m))
148             buffer.append("protected ");
149
150         if(isAbstract(m))
151             buffer.append("abstract ");
152
153         if(isInterface(m))
154             buffer.append("interface ");
155
156         if(isStatic(m))
157             buffer.append("static ");
158
159         if(isFinal(m))
160             buffer.append("final ");
161
162         if(isSynchronized(m))
163             buffer.append("synchronized ");
164
165         if(isNative(m))
166             buffer.append("native ");
167
168         if(isTransient(m))
169             buffer.append("transient ");
170
171         if(isVolatile(m))
172             buffer.append("volatile ");
173
174         if(isStrictFP(m))
175             buffer.append("strictfp ");
176         
177         if(isAnnotation(m))
178             buffer.append("annotation ");
179         
180         if(isEnum(m))
181             buffer.append("enum ");
182         
183         return (buffer.toString()).trim();
184     }
185
186 }
187
Popular Tags