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.

AccessFlag.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999- 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. * or the Apache License Version 2.0.
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. */
  16. package javassist.bytecode;
  17. /**
  18. * A support class providing static methods and constants
  19. * for access modifiers such as public, private, ...
  20. */
  21. public class AccessFlag {
  22. public static final int PUBLIC = 0x0001;
  23. public static final int PRIVATE = 0x0002;
  24. public static final int PROTECTED = 0x0004;
  25. public static final int STATIC = 0x0008;
  26. public static final int FINAL = 0x0010;
  27. public static final int SYNCHRONIZED = 0x0020;
  28. public static final int VOLATILE = 0x0040;
  29. public static final int BRIDGE = 0x0040; // for method_info
  30. public static final int TRANSIENT = 0x0080;
  31. public static final int VARARGS = 0x0080; // for method_info
  32. public static final int NATIVE = 0x0100;
  33. public static final int INTERFACE = 0x0200;
  34. public static final int ABSTRACT = 0x0400;
  35. public static final int STRICT = 0x0800;
  36. public static final int SYNTHETIC = 0x1000;
  37. public static final int ANNOTATION = 0x2000;
  38. public static final int ENUM = 0x4000;
  39. public static final int MANDATED = 0x8000;
  40. public static final int SUPER = 0x0020;
  41. public static final int MODULE = 0x8000;
  42. // Note: 0x0020 is assigned to both ACC_SUPER and ACC_SYNCHRONIZED
  43. // although java.lang.reflect.Modifier does not recognize ACC_SUPER.
  44. /**
  45. * Turns the public bit on. The protected and private bits are
  46. * cleared.
  47. */
  48. public static int setPublic(int accflags) {
  49. return (accflags & ~(PRIVATE | PROTECTED)) | PUBLIC;
  50. }
  51. /**
  52. * Turns the protected bit on. The protected and public bits are
  53. * cleared.
  54. */
  55. public static int setProtected(int accflags) {
  56. return (accflags & ~(PRIVATE | PUBLIC)) | PROTECTED;
  57. }
  58. /**
  59. * Truns the private bit on. The protected and private bits are
  60. * cleared.
  61. */
  62. public static int setPrivate(int accflags) {
  63. return (accflags & ~(PROTECTED | PUBLIC)) | PRIVATE;
  64. }
  65. /**
  66. * Clears the public, protected, and private bits.
  67. */
  68. public static int setPackage(int accflags) {
  69. return (accflags & ~(PROTECTED | PUBLIC | PRIVATE));
  70. }
  71. /**
  72. * Returns true if the access flags include the public bit.
  73. */
  74. public static boolean isPublic(int accflags) {
  75. return (accflags & PUBLIC) != 0;
  76. }
  77. /**
  78. * Returns true if the access flags include the protected bit.
  79. */
  80. public static boolean isProtected(int accflags) {
  81. return (accflags & PROTECTED) != 0;
  82. }
  83. /**
  84. * Returns true if the access flags include the private bit.
  85. */
  86. public static boolean isPrivate(int accflags) {
  87. return (accflags & PRIVATE) != 0;
  88. }
  89. /**
  90. * Returns true if the access flags include neither public, protected,
  91. * or private.
  92. */
  93. public static boolean isPackage(int accflags) {
  94. return (accflags & (PROTECTED | PUBLIC | PRIVATE)) == 0;
  95. }
  96. /**
  97. * Clears a specified bit in <code>accflags</code>.
  98. */
  99. public static int clear(int accflags, int clearBit) {
  100. return accflags & ~clearBit;
  101. }
  102. /**
  103. * Converts a javassist.Modifier into
  104. * a javassist.bytecode.AccessFlag.
  105. *
  106. * @param modifier javassist.Modifier
  107. */
  108. public static int of(int modifier) {
  109. return modifier;
  110. }
  111. /**
  112. * Converts a javassist.bytecode.AccessFlag
  113. * into a javassist.Modifier.
  114. *
  115. * @param accflags javassist.bytecode.Accessflag
  116. */
  117. public static int toModifier(int accflags) {
  118. return accflags;
  119. }
  120. }