/Users/lyon/j4p/src/javassist/Modifier.java

1    /* 
2     * Javassist, a Java-bytecode translator toolkit. 
3     * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved. 
4     * 
5     * The contents of this file are subject to the Mozilla Public License Version 
6     * 1.1 (the "License"); you may not use this file except in compliance with 
7     * the License.  Alternatively, the contents of this file may be used under 
8     * the terms of the GNU Lesser General Public License Version 2.1 or later. 
9     * 
10    * Software distributed under the License is distributed on an "AS IS" basis, 
11    * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
12    * for the specific language governing rights and limitations under the 
13    * License. 
14    */ 
15    
16   package javassist; 
17    
18   import javassist.bytecode.AccessFlag; 
19    
20   /** 
21    * The Modifier class provides static methods and constants to decode 
22    * class and member access modifiers.  The constant values are equivalent 
23    * to the corresponding values in <code>javassist.bytecode.AccessFlag</code>. 
24    * 
25    * <p>All the methods/constants in this class are compatible with 
26    * ones in <code>java.lang.reflect.Modifier</code>. 
27    * 
28    * @see CtClass#getModifiers() 
29    */ 
30   public class Modifier { 
31       public static final int PUBLIC = AccessFlag.PUBLIC; 
32       public static final int PRIVATE = AccessFlag.PRIVATE; 
33       public static final int PROTECTED = AccessFlag.PROTECTED; 
34       public static final int STATIC = AccessFlag.STATIC; 
35       public static final int FINAL = AccessFlag.FINAL; 
36       public static final int SYNCHRONIZED = AccessFlag.SYNCHRONIZED; 
37       public static final int VOLATILE = AccessFlag.VOLATILE; 
38       public static final int TRANSIENT = AccessFlag.TRANSIENT; 
39       public static final int NATIVE = AccessFlag.NATIVE; 
40       public static final int INTERFACE = AccessFlag.INTERFACE; 
41       public static final int ABSTRACT = AccessFlag.ABSTRACT; 
42       public static final int STRICT = AccessFlag.STRICT; 
43    
44       /** 
45        * Returns true if the modifiers include the <tt>public</tt> 
46        * modifier. 
47        */ 
48       public static boolean isPublic(int mod) { 
49           return (mod & PUBLIC) != 0; 
50       } 
51    
52       /** 
53        * Returns true if the modifiers include the <tt>private</tt> 
54        * modifier. 
55        */ 
56       public static boolean isPrivate(int mod) { 
57           return (mod & PRIVATE) != 0; 
58       } 
59    
60       /** 
61        * Returns true if the modifiers include the <tt>protected</tt> 
62        * modifier. 
63        */ 
64       public static boolean isProtected(int mod) { 
65           return (mod & PROTECTED) != 0; 
66       } 
67    
68       /** 
69        * Returns true if the modifiers include the <tt>static</tt> 
70        * modifier. 
71        */ 
72       public static boolean isStatic(int mod) { 
73           return (mod & STATIC) != 0; 
74       } 
75    
76       /** 
77        * Returns true if the modifiers include the <tt>final</tt> 
78        * modifier. 
79        */ 
80       public static boolean isFinal(int mod) { 
81           return (mod & FINAL) != 0; 
82       } 
83    
84       /** 
85        * Returns true if the modifiers include the <tt>synchronized</tt> 
86        * modifier. 
87        */ 
88       public static boolean isSynchronized(int mod) { 
89           return (mod & SYNCHRONIZED) != 0; 
90       } 
91    
92       /** 
93        * Returns true if the modifiers include the <tt>volatile</tt> 
94        * modifier. 
95        */ 
96       public static boolean isVolatile(int mod) { 
97           return (mod & VOLATILE) != 0; 
98       } 
99    
100      /** 
101       * Returns true if the modifiers include the <tt>transient</tt> 
102       * modifier. 
103       */ 
104      public static boolean isTransient(int mod) { 
105          return (mod & TRANSIENT) != 0; 
106      } 
107   
108      /** 
109       * Returns true if the modifiers include the <tt>native</tt> 
110       * modifier. 
111       */ 
112      public static boolean isNative(int mod) { 
113          return (mod & NATIVE) != 0; 
114      } 
115   
116      /** 
117       * Returns true if the modifiers include the <tt>interface</tt> 
118       * modifier. 
119       */ 
120      public static boolean isInterface(int mod) { 
121          return (mod & INTERFACE) != 0; 
122      } 
123   
124      /** 
125       * Returns true if the modifiers include the <tt>abstract</tt> 
126       * modifier. 
127       */ 
128      public static boolean isAbstract(int mod) { 
129          return (mod & ABSTRACT) != 0; 
130      } 
131   
132      /** 
133       * Returns true if the modifiers include the <tt>strictfp</tt> 
134       * modifier. 
135       */ 
136      public static boolean isStrict(int mod) { 
137          return (mod & STRICT) != 0; 
138      } 
139   
140      /** 
141       * Truns the public bit on.  The protected and private bits are 
142       * cleared. 
143       */ 
144      public static int setPublic(int mod) { 
145          return (mod & ~(PRIVATE | PROTECTED)) | PUBLIC; 
146      } 
147   
148      /** 
149       * Truns the protected bit on.  The protected and public bits are 
150       * cleared. 
151       */ 
152      public static int setProtected(int mod) { 
153          return (mod & ~(PRIVATE | PUBLIC)) | PROTECTED; 
154      } 
155   
156      /** 
157       * Truns the private bit on.  The protected and private bits are 
158       * cleared. 
159       */ 
160      public static int setPrivate(int mod) { 
161          return (mod & ~(PROTECTED | PUBLIC)) | PRIVATE; 
162      } 
163   
164      /** 
165       * Clears the public, protected, and private bits. 
166       */ 
167      public static int setPackage(int mod) { 
168          return (mod & ~(PROTECTED | PUBLIC | PRIVATE)); 
169      } 
170   
171      /** 
172       * Clears a specified bit in <code>mod</code>. 
173       */ 
174      public static int clear(int mod, int clearBit) { 
175          return mod & ~clearBit; 
176      } 
177   
178      public static String toString(int mod) { 
179          return java.lang.reflect.Modifier.toString(mod); 
180      } 
181  } 
182