1 7 8 package java.lang.reflect; 9 10 import java.security.AccessController ; 11 import sun.reflect.LangReflectAccess; 12 import sun.reflect.ReflectionFactory; 13 14 34 public 35 class Modifier { 36 37 41 static { 42 sun.reflect.ReflectionFactory factory = 43 (sun.reflect.ReflectionFactory) AccessController.doPrivileged( 44 new ReflectionFactory.GetReflectionFactoryAction() 45 ); 46 factory.setLangReflectAccess(new java.lang.reflect.ReflectAccess ()); 47 } 48 49 57 public static boolean isPublic(int mod) { 58 return (mod & PUBLIC) != 0; 59 } 60 61 69 public static boolean isPrivate(int mod) { 70 return (mod & PRIVATE) != 0; 71 } 72 73 81 public static boolean isProtected(int mod) { 82 return (mod & PROTECTED) != 0; 83 } 84 85 93 public static boolean isStatic(int mod) { 94 return (mod & STATIC) != 0; 95 } 96 97 105 public static boolean isFinal(int mod) { 106 return (mod & FINAL) != 0; 107 } 108 109 117 public static boolean isSynchronized(int mod) { 118 return (mod & SYNCHRONIZED) != 0; 119 } 120 121 129 public static boolean isVolatile(int mod) { 130 return (mod & VOLATILE) != 0; 131 } 132 133 141 public static boolean isTransient(int mod) { 142 return (mod & TRANSIENT) != 0; 143 } 144 145 153 public static boolean isNative(int mod) { 154 return (mod & NATIVE) != 0; 155 } 156 157 165 public static boolean isInterface(int mod) { 166 return (mod & INTERFACE) != 0; 167 } 168 169 177 public static boolean isAbstract(int mod) { 178 return (mod & ABSTRACT) != 0; 179 } 180 181 189 public static boolean isStrict(int mod) { 190 return (mod & STRICT) != 0; 191 } 192 193 225 public static String toString(int mod) { 226 StringBuffer sb = new StringBuffer (); 227 int len; 228 229 if ((mod & PUBLIC) != 0) sb.append("public "); 230 if ((mod & PROTECTED) != 0) sb.append("protected "); 231 if ((mod & PRIVATE) != 0) sb.append("private "); 232 233 234 if ((mod & ABSTRACT) != 0) sb.append("abstract "); 235 if ((mod & STATIC) != 0) sb.append("static "); 236 if ((mod & FINAL) != 0) sb.append("final "); 237 if ((mod & TRANSIENT) != 0) sb.append("transient "); 238 if ((mod & VOLATILE) != 0) sb.append("volatile "); 239 if ((mod & SYNCHRONIZED) != 0) sb.append("synchronized "); 240 if ((mod & NATIVE) != 0) sb.append("native "); 241 if ((mod & STRICT) != 0) sb.append("strictfp "); 242 if ((mod & INTERFACE) != 0) sb.append("interface "); 243 244 if ((len = sb.length()) > 0) 245 return sb.toString().substring(0, len-1); 246 return ""; 247 } 248 249 254 255 259 public static final int PUBLIC = 0x00000001; 260 261 265 public static final int PRIVATE = 0x00000002; 266 267 271 public static final int PROTECTED = 0x00000004; 272 273 277 public static final int STATIC = 0x00000008; 278 279 283 public static final int FINAL = 0x00000010; 284 285 289 public static final int SYNCHRONIZED = 0x00000020; 290 291 295 public static final int VOLATILE = 0x00000040; 296 297 301 public static final int TRANSIENT = 0x00000080; 302 303 307 public static final int NATIVE = 0x00000100; 308 309 313 public static final int INTERFACE = 0x00000200; 314 315 319 public static final int ABSTRACT = 0x00000400; 320 321 325 public static final int STRICT = 0x00000800; 326 327 static final int BRIDGE = 0x00000040; 332 static final int VARARGS = 0x00000080; 333 static final int SYNTHETIC = 0x00001000; 334 static final int ANNOTATION= 0x00002000; 335 static final int ENUM = 0x00004000; 336 static boolean isSynthetic(int mod) { 337 return (mod & SYNTHETIC) != 0; 338 } 339 } 340 | Popular Tags |