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