Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AccessFlag.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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, rivate, ...
  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 SUPER = 0x0020;
  40. // Note: 0x0020 is assigned to both ACC_SUPER and ACC_SYNCHRONIZED
  41. // although java.lang.reflect.Modifier does not recognize ACC_SUPER.
  42. /**
  43. * Truns the public bit on. The protected and private bits are
  44. * cleared.
  45. */
  46. public static int setPublic(int accflags) {
  47. return (accflags & ~(PRIVATE | PROTECTED)) | PUBLIC;
  48. }
  49. /**
  50. * Truns the protected bit on. The protected and public bits are
  51. * cleared.
  52. */
  53. public static int setProtected(int accflags) {
  54. return (accflags & ~(PRIVATE | PUBLIC)) | PROTECTED;
  55. }
  56. /**
  57. * Truns the private bit on. The protected and private bits are
  58. * cleared.
  59. */
  60. public static int setPrivate(int accflags) {
  61. return (accflags & ~(PROTECTED | PUBLIC)) | PRIVATE;
  62. }
  63. /**
  64. * Clears the public, protected, and private bits.
  65. */
  66. public static int setPackage(int accflags) {
  67. return (accflags & ~(PROTECTED | PUBLIC | PRIVATE));
  68. }
  69. /**
  70. * Returns true if the access flags include the public bit.
  71. */
  72. public static boolean isPublic(int accflags) {
  73. return (accflags & PUBLIC) != 0;
  74. }
  75. /**
  76. * Returns true if the access flags include the protected bit.
  77. */
  78. public static boolean isProtected(int accflags) {
  79. return (accflags & PROTECTED) != 0;
  80. }
  81. /**
  82. * Returns true if the access flags include the private bit.
  83. */
  84. public static boolean isPrivate(int accflags) {
  85. return (accflags & PRIVATE) != 0;
  86. }
  87. /**
  88. * Returns true if the access flags include neither public, protected,
  89. * or private.
  90. */
  91. public static boolean isPackage(int accflags) {
  92. return (accflags & (PROTECTED | PUBLIC | PRIVATE)) == 0;
  93. }
  94. /**
  95. * Clears a specified bit in <code>accflags</code>.
  96. */
  97. public static int clear(int accflags, int clearBit) {
  98. return accflags & ~clearBit;
  99. }
  100. /**
  101. * Converts a javassist.Modifier into
  102. * a javassist.bytecode.AccessFlag.
  103. *
  104. * @param modifier javassist.Modifier
  105. */
  106. public static int of(int modifier) {
  107. return modifier;
  108. }
  109. /**
  110. * Converts a javassist.bytecode.AccessFlag
  111. * into a javassist.Modifier.
  112. *
  113. * @param accflags javassist.bytecode.Accessflag
  114. */
  115. public static int toModifier(int accflags) {
  116. return accflags;
  117. }
  118. }