You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Modifier.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. package javassist;
  16. import javassist.bytecode.AccessFlag;
  17. /**
  18. * The Modifier class provides static methods and constants to decode
  19. * class and member access modifiers. The constant values are equivalent
  20. * to the corresponding values in <code>javassist.bytecode.AccessFlag</code>.
  21. *
  22. * <p>All the methods/constants in this class are compatible with
  23. * ones in <code>java.lang.reflect.Modifier</code>.
  24. *
  25. * @see CtClass#getModifiers()
  26. */
  27. public class Modifier {
  28. public static final int PUBLIC = AccessFlag.PUBLIC;
  29. public static final int PRIVATE = AccessFlag.PRIVATE;
  30. public static final int PROTECTED = AccessFlag.PROTECTED;
  31. public static final int STATIC = AccessFlag.STATIC;
  32. public static final int FINAL = AccessFlag.FINAL;
  33. public static final int SYNCHRONIZED = AccessFlag.SYNCHRONIZED;
  34. public static final int VOLATILE = AccessFlag.VOLATILE;
  35. public static final int TRANSIENT = AccessFlag.TRANSIENT;
  36. public static final int NATIVE = AccessFlag.NATIVE;
  37. public static final int INTERFACE = AccessFlag.INTERFACE;
  38. public static final int ABSTRACT = AccessFlag.ABSTRACT;
  39. public static final int STRICT = AccessFlag.STRICT;
  40. /**
  41. * Returns true if the modifiers include the <tt>public</tt>
  42. * modifier.
  43. */
  44. public static boolean isPublic(int mod) {
  45. return (mod & PUBLIC) != 0;
  46. }
  47. /**
  48. * Returns true if the modifiers include the <tt>private</tt>
  49. * modifier.
  50. */
  51. public static boolean isPrivate(int mod) {
  52. return (mod & PRIVATE) != 0;
  53. }
  54. /**
  55. * Returns true if the modifiers include the <tt>protected</tt>
  56. * modifier.
  57. */
  58. public static boolean isProtected(int mod) {
  59. return (mod & PROTECTED) != 0;
  60. }
  61. /**
  62. * Returns true if the modifiers include the <tt>static</tt>
  63. * modifier.
  64. */
  65. public static boolean isStatic(int mod) {
  66. return (mod & STATIC) != 0;
  67. }
  68. /**
  69. * Returns true if the modifiers include the <tt>final</tt>
  70. * modifier.
  71. */
  72. public static boolean isFinal(int mod) {
  73. return (mod & FINAL) != 0;
  74. }
  75. /**
  76. * Returns true if the modifiers include the <tt>synchronized</tt>
  77. * modifier.
  78. */
  79. public static boolean isSynchronized(int mod) {
  80. return (mod & SYNCHRONIZED) != 0;
  81. }
  82. /**
  83. * Returns true if the modifiers include the <tt>volatile</tt>
  84. * modifier.
  85. */
  86. public static boolean isVolatile(int mod) {
  87. return (mod & VOLATILE) != 0;
  88. }
  89. /**
  90. * Returns true if the modifiers include the <tt>transient</tt>
  91. * modifier.
  92. */
  93. public static boolean isTransient(int mod) {
  94. return (mod & TRANSIENT) != 0;
  95. }
  96. /**
  97. * Returns true if the modifiers include the <tt>native</tt>
  98. * modifier.
  99. */
  100. public static boolean isNative(int mod) {
  101. return (mod & NATIVE) != 0;
  102. }
  103. /**
  104. * Returns true if the modifiers include the <tt>interface</tt>
  105. * modifier.
  106. */
  107. public static boolean isInterface(int mod) {
  108. return (mod & INTERFACE) != 0;
  109. }
  110. /**
  111. * Returns true if the modifiers include the <tt>abstract</tt>
  112. * modifier.
  113. */
  114. public static boolean isAbstract(int mod) {
  115. return (mod & ABSTRACT) != 0;
  116. }
  117. /**
  118. * Returns true if the modifiers include the <tt>strictfp</tt>
  119. * modifier.
  120. */
  121. public static boolean isStrict(int mod) {
  122. return (mod & STRICT) != 0;
  123. }
  124. /**
  125. * Truns the public bit on. The protected and private bits are
  126. * cleared.
  127. */
  128. public static int setPublic(int mod) {
  129. return (mod & ~(PRIVATE | PROTECTED)) | PUBLIC;
  130. }
  131. /**
  132. * Truns the protected bit on. The protected and public bits are
  133. * cleared.
  134. */
  135. public static int setProtected(int mod) {
  136. return (mod & ~(PRIVATE | PUBLIC)) | PROTECTED;
  137. }
  138. /**
  139. * Truns the private bit on. The protected and private bits are
  140. * cleared.
  141. */
  142. public static int setPrivate(int mod) {
  143. return (mod & ~(PROTECTED | PUBLIC)) | PRIVATE;
  144. }
  145. /**
  146. * Clears the public, protected, and private bits.
  147. */
  148. public static int setPackage(int mod) {
  149. return (mod & ~(PROTECTED | PUBLIC | PRIVATE));
  150. }
  151. /**
  152. * Clears a specified bit in <code>mod</code>.
  153. */
  154. public static int clear(int mod, int clearBit) {
  155. return mod & ~clearBit;
  156. }
  157. public static String toString(int mod) {
  158. return java.lang.reflect.Modifier.toString(mod);
  159. }
  160. }