218 * href="http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html"><em>The 219 * Java Language Specification, Second Edition</em></a> sections 220 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#21613">§8.1.1</a>, 221 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#78091">§8.3.1</a>, 222 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#78188">§8.4.3</a>, 223 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#42018">§8.8.3</a>, and 224 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html#235947">§9.1.1</a>. 225 * The full modifier ordering used by this method is: 226 * <blockquote> {@code 227 * public protected private abstract static final transient 228 * volatile synchronized native strictfp 229 * interface } </blockquote> 230 * The {@code interface} modifier discussed in this class is 231 * not a true modifier in the Java language and it appears after 232 * all other modifiers listed by this method. This method may 233 * return a string of modifiers that are not valid modifiers of a 234 * Java entity; in other words, no checking is done on the 235 * possible validity of the combination of modifiers represented 236 * by the input. 237 * 238 * @param mod a set of modifiers 239 * @return a string representation of the set of modifiers 240 * represented by {@code mod} 241 */ 242 public static String toString(int mod) { 243 StringBuffer sb = new StringBuffer(); 244 int len; 245 246 if ((mod & PUBLIC) != 0) sb.append("public "); 247 if ((mod & PROTECTED) != 0) sb.append("protected "); 248 if ((mod & PRIVATE) != 0) sb.append("private "); 249 250 /* Canonical order */ 251 if ((mod & ABSTRACT) != 0) sb.append("abstract "); 252 if ((mod & STATIC) != 0) sb.append("static "); 253 if ((mod & FINAL) != 0) sb.append("final "); 254 if ((mod & TRANSIENT) != 0) sb.append("transient "); 255 if ((mod & VOLATILE) != 0) sb.append("volatile "); 256 if ((mod & SYNCHRONIZED) != 0) sb.append("synchronized "); 257 if ((mod & NATIVE) != 0) sb.append("native "); 336 public static final int ABSTRACT = 0x00000400; 337 338 /** 339 * The {@code int} value representing the {@code strictfp} 340 * modifier. 341 */ 342 public static final int STRICT = 0x00000800; 343 344 // Bits not (yet) exposed in the public API either because they 345 // have different meanings for fields and methods and there is no 346 // way to distinguish between the two in this class, or because 347 // they are not Java programming language keywords 348 static final int BRIDGE = 0x00000040; 349 static final int VARARGS = 0x00000080; 350 static final int SYNTHETIC = 0x00001000; 351 static final int ANNOTATION= 0x00002000; 352 static final int ENUM = 0x00004000; 353 static boolean isSynthetic(int mod) { 354 return (mod & SYNTHETIC) != 0; 355 } 356 } | 218 * href="http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html"><em>The 219 * Java Language Specification, Second Edition</em></a> sections 220 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#21613">§8.1.1</a>, 221 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#78091">§8.3.1</a>, 222 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#78188">§8.4.3</a>, 223 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#42018">§8.8.3</a>, and 224 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html#235947">§9.1.1</a>. 225 * The full modifier ordering used by this method is: 226 * <blockquote> {@code 227 * public protected private abstract static final transient 228 * volatile synchronized native strictfp 229 * interface } </blockquote> 230 * The {@code interface} modifier discussed in this class is 231 * not a true modifier in the Java language and it appears after 232 * all other modifiers listed by this method. This method may 233 * return a string of modifiers that are not valid modifiers of a 234 * Java entity; in other words, no checking is done on the 235 * possible validity of the combination of modifiers represented 236 * by the input. 237 * 238 * Note that to perform such checking for a known kind of entity, 239 * such as a constructor or method, first AND the argument of 240 * {@code toString} with the appropriate mask from a method like 241 * {@link #constructorModifiers} or {@link #methodModifiers}. 242 * 243 * @param mod a set of modifiers 244 * @return a string representation of the set of modifiers 245 * represented by {@code mod} 246 */ 247 public static String toString(int mod) { 248 StringBuffer sb = new StringBuffer(); 249 int len; 250 251 if ((mod & PUBLIC) != 0) sb.append("public "); 252 if ((mod & PROTECTED) != 0) sb.append("protected "); 253 if ((mod & PRIVATE) != 0) sb.append("private "); 254 255 /* Canonical order */ 256 if ((mod & ABSTRACT) != 0) sb.append("abstract "); 257 if ((mod & STATIC) != 0) sb.append("static "); 258 if ((mod & FINAL) != 0) sb.append("final "); 259 if ((mod & TRANSIENT) != 0) sb.append("transient "); 260 if ((mod & VOLATILE) != 0) sb.append("volatile "); 261 if ((mod & SYNCHRONIZED) != 0) sb.append("synchronized "); 262 if ((mod & NATIVE) != 0) sb.append("native "); 341 public static final int ABSTRACT = 0x00000400; 342 343 /** 344 * The {@code int} value representing the {@code strictfp} 345 * modifier. 346 */ 347 public static final int STRICT = 0x00000800; 348 349 // Bits not (yet) exposed in the public API either because they 350 // have different meanings for fields and methods and there is no 351 // way to distinguish between the two in this class, or because 352 // they are not Java programming language keywords 353 static final int BRIDGE = 0x00000040; 354 static final int VARARGS = 0x00000080; 355 static final int SYNTHETIC = 0x00001000; 356 static final int ANNOTATION= 0x00002000; 357 static final int ENUM = 0x00004000; 358 static boolean isSynthetic(int mod) { 359 return (mod & SYNTHETIC) != 0; 360 } 361 362 /** 363 * See JLSv3 section 8.1.1. 364 */ 365 private static final int CLASS_MODIFIERS = 366 Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | 367 Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | 368 Modifier.STRICT; 369 370 /** 371 * See JLSv3 section 9.1.1. 372 */ 373 private static final int INTERFACE_MODIFIERS = 374 Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | 375 Modifier.ABSTRACT | Modifier.STATIC | Modifier.STRICT; 376 377 378 /** 379 * See JLSv3 section 8.8.3. 380 */ 381 private static final int CONSTRUCTOR_MODIFIERS = 382 Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE; 383 384 /** 385 * See JLSv3 section 8.4.3. 386 */ 387 private static final int METHOD_MODIFIERS = 388 Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | 389 Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | 390 Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT; 391 392 /** 393 * See JLSv3 section 8.3.1. 394 */ 395 private static final int FIELD_MODIFIERS = 396 Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | 397 Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT | 398 Modifier.VOLATILE; 399 400 /** 401 * Return an {@code int} value OR-ing together the source language 402 * modifiers that can be applied to a class. 403 * @return an {@code int} value OR-ing together the source language 404 * modifiers that can be applied to a class. 405 * 406 * @jls3 8.1.1 Class Modifiers 407 * @since 1.7 408 */ 409 public static int classModifiers() { 410 return CLASS_MODIFIERS; 411 } 412 413 /** 414 * Return an {@code int} value OR-ing together the source language 415 * modifiers that can be applied to an interface. 416 * @return an {@code int} value OR-ing together the source language 417 * modifiers that can be applied to an inteface. 418 * 419 * @jls3 9.1.1 Interface Modifiers 420 * @since 1.7 421 */ 422 public static int interfaceModifiers() { 423 return INTERFACE_MODIFIERS; 424 } 425 426 /** 427 * Return an {@code int} value OR-ing together the source language 428 * modifiers that can be applied to a constructor. 429 * @return an {@code int} value OR-ing together the source language 430 * modifiers that can be applied to a constructor. 431 * 432 * @jls3 8.8.3 Constructor Modifiers 433 * @since 1.7 434 */ 435 public static int constructorModifiers() { 436 return CONSTRUCTOR_MODIFIERS; 437 } 438 439 /** 440 * Return an {@code int} value OR-ing together the source language 441 * modifiers that can be applied to a method. 442 * @return an {@code int} value OR-ing together the source language 443 * modifiers that can be applied to a method. 444 * 445 * @jls3 8.4.3 Method Modifiers 446 * @since 1.7 447 */ 448 public static int methodModifiers() { 449 return METHOD_MODIFIERS; 450 } 451 452 453 /** 454 * Return an {@code int} value OR-ing together the source language 455 * modifiers that can be applied to a field. 456 * @return an {@code int} value OR-ing together the source language 457 * modifiers that can be applied to a field. 458 * 459 * @jls3 8.3.1 Field Modifiers 460 * @since 1.7 461 */ 462 public static int fieldModifiers() { 463 return FIELD_MODIFIERS; 464 } 465 } |