1. /*
  2. * @(#)Modifier.java 1.17 00/02/02
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.lang.reflect;
  11. /**
  12. * The Modifier class provides static methods and constants to decode
  13. * class and member access modifiers.
  14. *
  15. * @see Class#getModifiers()
  16. * @see Member#getModifiers()
  17. *
  18. * @author Nakul Saraiya
  19. */
  20. public
  21. class Modifier {
  22. /**
  23. * Return true if the specified integer includes the <tt>public</tt>
  24. * modifier.
  25. */
  26. public static boolean isPublic(int mod) {
  27. return (mod & PUBLIC) != 0;
  28. }
  29. /**
  30. * Return true if the specifier integer includes the <tt>private</tt>
  31. * modifier.
  32. */
  33. public static boolean isPrivate(int mod) {
  34. return (mod & PRIVATE) != 0;
  35. }
  36. /**
  37. * Return true if the specifier integer includes the <tt>protected</tt>
  38. * modifier.
  39. */
  40. public static boolean isProtected(int mod) {
  41. return (mod & PROTECTED) != 0;
  42. }
  43. /**
  44. * Return true if the specifier integer includes the <tt>static</tt>
  45. * modifier.
  46. */
  47. public static boolean isStatic(int mod) {
  48. return (mod & STATIC) != 0;
  49. }
  50. /**
  51. * Return true if the specified integer includes the <tt>final</tt>
  52. * modifier.
  53. */
  54. public static boolean isFinal(int mod) {
  55. return (mod & FINAL) != 0;
  56. }
  57. /**
  58. * Return true if the specified integer includes the <tt>synchronized</tt>
  59. * modifier.
  60. */
  61. public static boolean isSynchronized(int mod) {
  62. return (mod & SYNCHRONIZED) != 0;
  63. }
  64. /**
  65. * Return true if the specified integer includes the <tt>volatile</tt>
  66. * modifier.
  67. */
  68. public static boolean isVolatile(int mod) {
  69. return (mod & VOLATILE) != 0;
  70. }
  71. /**
  72. * Return true if the specifier integer includes the <tt>transient</tt>
  73. * modifier.
  74. */
  75. public static boolean isTransient(int mod) {
  76. return (mod & TRANSIENT) != 0;
  77. }
  78. /**
  79. * Return true if the specifier integer includes the <tt>native</tt>
  80. * modifier.
  81. */
  82. public static boolean isNative(int mod) {
  83. return (mod & NATIVE) != 0;
  84. }
  85. /**
  86. * Return true if the specifier integer includes the <tt>interface</tt>
  87. * modifier.
  88. */
  89. public static boolean isInterface(int mod) {
  90. return (mod & INTERFACE) != 0;
  91. }
  92. /**
  93. * Return true if the specifier integer includes the <tt>abstract</tt>
  94. * modifier.
  95. */
  96. public static boolean isAbstract(int mod) {
  97. return (mod & ABSTRACT) != 0;
  98. }
  99. /**
  100. * Return true if the specifier integer includes the <tt>strictfp</tt>
  101. * modifier.
  102. */
  103. public static boolean isStrict(int mod) {
  104. return (mod & STRICT) != 0;
  105. }
  106. /**
  107. * Return a string describing the access modifier flags in
  108. * the specified modifier. For example:
  109. * <blockquote><pre>
  110. * public final synchronized
  111. * private transient volatile
  112. * </pre></blockquote>
  113. * The modifier names are return in canonical order, as
  114. * specified by <em>The Java Language Specification</em>.
  115. */
  116. public static String toString(int mod) {
  117. StringBuffer sb = new StringBuffer();
  118. int len;
  119. if ((mod & PUBLIC) != 0) sb.append("public ");
  120. if ((mod & PRIVATE) != 0) sb.append("private ");
  121. if ((mod & PROTECTED) != 0) sb.append("protected ");
  122. /* Canonical order */
  123. if ((mod & ABSTRACT) != 0) sb.append("abstract ");
  124. if ((mod & STATIC) != 0) sb.append("static ");
  125. if ((mod & FINAL) != 0) sb.append("final ");
  126. if ((mod & TRANSIENT) != 0) sb.append("transient ");
  127. if ((mod & VOLATILE) != 0) sb.append("volatile ");
  128. if ((mod & NATIVE) != 0) sb.append("native ");
  129. if ((mod & SYNCHRONIZED) != 0) sb.append("synchronized ");
  130. if ((mod & INTERFACE) != 0) sb.append("interface ");
  131. if ((mod & STRICT) != 0) sb.append("strictfp ");
  132. if ((len = sb.length()) > 0) /* trim trailing space */
  133. return sb.toString().substring(0, len-1);
  134. return "";
  135. }
  136. /*
  137. * Access modifier flag constants from <em>The Java Virtual
  138. * Machine Specification</em>, Table 4.1.
  139. */
  140. /**
  141. * The <code>int</code> value representing the <code>public</code>
  142. * modifier.
  143. */
  144. public static final int PUBLIC = 0x00000001;
  145. /**
  146. * The <code>int</code> value representing the <code>private</code>
  147. * modifier.
  148. */
  149. public static final int PRIVATE = 0x00000002;
  150. /**
  151. * The <code>int</code> value representing the <code>protected</code>
  152. * modifier.
  153. */
  154. public static final int PROTECTED = 0x00000004;
  155. /**
  156. * The <code>int</code> value representing the <code>static</code>
  157. * modifier.
  158. */
  159. public static final int STATIC = 0x00000008;
  160. /**
  161. * The <code>int</code> value representing the <code>final</code>
  162. * modifier.
  163. */
  164. public static final int FINAL = 0x00000010;
  165. /**
  166. * The <code>int</code> value representing the <code>synchronized</code>
  167. * modifier.
  168. */
  169. public static final int SYNCHRONIZED = 0x00000020;
  170. /**
  171. * The <code>int</code> value representing the <code>volatile</code>
  172. * modifier.
  173. */
  174. public static final int VOLATILE = 0x00000040;
  175. /**
  176. * The <code>int</code> value representing the <code>transient</code>
  177. * modifier.
  178. */
  179. public static final int TRANSIENT = 0x00000080;
  180. /**
  181. * The <code>int</code> value representing the <code>native</code>
  182. * modifier.
  183. */
  184. public static final int NATIVE = 0x00000100;
  185. /**
  186. * The <code>int</code> value representing the <code>interface</code>
  187. * modifier.
  188. */
  189. public static final int INTERFACE = 0x00000200;
  190. /**
  191. * The <code>int</code> value representing the <code>abstract</code>
  192. * modifier.
  193. */
  194. public static final int ABSTRACT = 0x00000400;
  195. /**
  196. * The <code>int</code> value representing the <code>strictfp</code>
  197. * modifier.
  198. */
  199. public static final int STRICT = 0x00000800;
  200. }