001: /*
002: * Javassist, a Java-bytecode translator toolkit.
003: * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
004: *
005: * The contents of this file are subject to the Mozilla Public License Version
006: * 1.1 (the "License"); you may not use this file except in compliance with
007: * the License. Alternatively, the contents of this file may be used under
008: * the terms of the GNU Lesser General Public License Version 2.1 or later.
009: *
010: * Software distributed under the License is distributed on an "AS IS" basis,
011: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
012: * for the specific language governing rights and limitations under the
013: * License.
014: */
015:
016: package javassist.bytecode;
017:
018: /**
019: * A support class providing static methods and constants
020: * for access modifiers such as public, rivate, ...
021: */
022: public class AccessFlag {
023: public static final int PUBLIC = 0x0001;
024: public static final int PRIVATE = 0x0002;
025: public static final int PROTECTED = 0x0004;
026: public static final int STATIC = 0x0008;
027: public static final int FINAL = 0x0010;
028: public static final int SYNCHRONIZED = 0x0020;
029: public static final int VOLATILE = 0x0040;
030: public static final int BRIDGE = 0x0040; // for method_info
031: public static final int TRANSIENT = 0x0080;
032: public static final int VARARGS = 0x0080; // for method_info
033: public static final int NATIVE = 0x0100;
034: public static final int INTERFACE = 0x0200;
035: public static final int ABSTRACT = 0x0400;
036: public static final int STRICT = 0x0800;
037: public static final int SYNTHETIC = 0x1000;
038: public static final int ANNOTATION = 0x2000;
039: public static final int ENUM = 0x4000;
040:
041: public static final int SUPER = 0x0020;
042:
043: // Note: 0x0020 is assigned to both ACC_SUPER and ACC_SYNCHRONIZED
044: // although java.lang.reflect.Modifier does not recognize ACC_SUPER.
045:
046: /**
047: * Truns the public bit on. The protected and private bits are
048: * cleared.
049: */
050: public static int setPublic(int accflags) {
051: return (accflags & ~(PRIVATE | PROTECTED)) | PUBLIC;
052: }
053:
054: /**
055: * Truns the protected bit on. The protected and public bits are
056: * cleared.
057: */
058: public static int setProtected(int accflags) {
059: return (accflags & ~(PRIVATE | PUBLIC)) | PROTECTED;
060: }
061:
062: /**
063: * Truns the private bit on. The protected and private bits are
064: * cleared.
065: */
066: public static int setPrivate(int accflags) {
067: return (accflags & ~(PROTECTED | PUBLIC)) | PRIVATE;
068: }
069:
070: /**
071: * Clears the public, protected, and private bits.
072: */
073: public static int setPackage(int accflags) {
074: return (accflags & ~(PROTECTED | PUBLIC | PRIVATE));
075: }
076:
077: /**
078: * Returns true if the access flags include the public bit.
079: */
080: public static boolean isPublic(int accflags) {
081: return (accflags & PUBLIC) != 0;
082: }
083:
084: /**
085: * Returns true if the access flags include the protected bit.
086: */
087: public static boolean isProtected(int accflags) {
088: return (accflags & PROTECTED) != 0;
089: }
090:
091: /**
092: * Returns true if the access flags include the private bit.
093: */
094: public static boolean isPrivate(int accflags) {
095: return (accflags & PRIVATE) != 0;
096: }
097:
098: /**
099: * Returns true if the access flags include neither public, protected,
100: * or private.
101: */
102: public static boolean isPackage(int accflags) {
103: return (accflags & (PROTECTED | PUBLIC | PRIVATE)) == 0;
104: }
105:
106: /**
107: * Clears a specified bit in <code>accflags</code>.
108: */
109: public static int clear(int accflags, int clearBit) {
110: return accflags & ~clearBit;
111: }
112:
113: /**
114: * Converts a javassist.Modifier into
115: * a javassist.bytecode.AccessFlag.
116: *
117: * @param modifier javassist.Modifier
118: */
119: public static int of(int modifier) {
120: return modifier;
121: }
122:
123: /**
124: * Converts a javassist.bytecode.AccessFlag
125: * into a javassist.Modifier.
126: *
127: * @param accflags javassist.bytecode.Accessflag
128: */
129: public static int toModifier(int accflags) {
130: return accflags;
131: }
132: }
|