169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/* 269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Javassist, a Java-bytecode translator toolkit. 369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Copyright (C) 1999-2007 Shigeru Chiba. All Rights Reserved. 469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * The contents of this file are subject to the Mozilla Public License Version 669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 1.1 (the "License"); you may not use this file except in compliance with 769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the License. Alternatively, the contents of this file may be used under 869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the terms of the GNU Lesser General Public License Version 2.1 or later. 969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 1069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Software distributed under the License is distributed on an "AS IS" basis, 1169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 1269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * for the specific language governing rights and limitations under the 1369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * License. 1469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 1569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 1669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpackage javassist.bytecode; 1769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 1869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/** 1969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * A support class providing static methods and constants 2069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * for access modifiers such as public, rivate, ... 2169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 2269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpublic class AccessFlag { 2369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int PUBLIC = 0x0001; 2469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int PRIVATE = 0x0002; 2569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int PROTECTED = 0x0004; 2669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int STATIC = 0x0008; 2769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int FINAL = 0x0010; 2869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int SYNCHRONIZED = 0x0020; 2969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int VOLATILE = 0x0040; 3069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int BRIDGE = 0x0040; // for method_info 3169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int TRANSIENT = 0x0080; 3269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int VARARGS = 0x0080; // for method_info 3369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int NATIVE = 0x0100; 3469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int INTERFACE = 0x0200; 3569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int ABSTRACT = 0x0400; 3669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int STRICT = 0x0800; 3769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int SYNTHETIC = 0x1000; 3869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int ANNOTATION = 0x2000; 3969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int ENUM = 0x4000; 4069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 4169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static final int SUPER = 0x0020; 4269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 4369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal // Note: 0x0020 is assigned to both ACC_SUPER and ACC_SYNCHRONIZED 4469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal // although java.lang.reflect.Modifier does not recognize ACC_SUPER. 4569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 4669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 4769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Truns the public bit on. The protected and private bits are 4869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * cleared. 4969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 5069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static int setPublic(int accflags) { 5169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return (accflags & ~(PRIVATE | PROTECTED)) | PUBLIC; 5269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 5369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 5469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 5569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Truns the protected bit on. The protected and public bits are 5669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * cleared. 5769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 5869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static int setProtected(int accflags) { 5969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return (accflags & ~(PRIVATE | PUBLIC)) | PROTECTED; 6069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 6169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 6269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 6369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Truns the private bit on. The protected and private bits are 6469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * cleared. 6569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 6669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static int setPrivate(int accflags) { 6769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return (accflags & ~(PROTECTED | PUBLIC)) | PRIVATE; 6869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 6969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 7069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 7169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Clears the public, protected, and private bits. 7269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 7369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static int setPackage(int accflags) { 7469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return (accflags & ~(PROTECTED | PUBLIC | PRIVATE)); 7569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 7669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 7769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 7869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Returns true if the access flags include the public bit. 7969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 8069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static boolean isPublic(int accflags) { 8169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return (accflags & PUBLIC) != 0; 8269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 8369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 8469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 8569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Returns true if the access flags include the protected bit. 8669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 8769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static boolean isProtected(int accflags) { 8869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return (accflags & PROTECTED) != 0; 8969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 9069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 9169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 9269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Returns true if the access flags include the private bit. 9369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 9469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static boolean isPrivate(int accflags) { 9569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return (accflags & PRIVATE) != 0; 9669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 9769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 9869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 9969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Returns true if the access flags include neither public, protected, 10069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * or private. 10169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 10269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static boolean isPackage(int accflags) { 10369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return (accflags & (PROTECTED | PUBLIC | PRIVATE)) == 0; 10469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 10569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 10669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 10769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Clears a specified bit in <code>accflags</code>. 10869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 10969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static int clear(int accflags, int clearBit) { 11069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return accflags & ~clearBit; 11169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 11269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 11369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 11469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Converts a javassist.Modifier into 11569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * a javassist.bytecode.AccessFlag. 11669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 11769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * @param modifier javassist.Modifier 11869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 11969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static int of(int modifier) { 12069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return modifier; 12169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 12269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 12369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 12469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Converts a javassist.bytecode.AccessFlag 12569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * into a javassist.Modifier. 12669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 12769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * @param accflags javassist.bytecode.Accessflag 12869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 12969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public static int toModifier(int accflags) { 13069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return accflags; 13169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 13269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal} 133