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