001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 *  Unless required by applicable law or agreed to in writing, software
012 *  distributed under the License is distributed on an "AS IS" BASIS,
013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 *  See the License for the specific language governing permissions and
015 *  limitations under the License.
016 *
017 */
018package org.apache.bcel.classfile;
019
020import org.apache.bcel.Const;
021
022/**
023 * Super class for all objects that have modifiers like private, final, ... I.e. classes, fields, and methods.
024 *
025 */
026public abstract class AccessFlags {
027
028    /**
029     * @deprecated (since 6.0) will be made private; do not access directly, use getter/setter
030     */
031    @java.lang.Deprecated
032    protected int access_flags; // TODO not used externally at present
033
034    public AccessFlags() {
035    }
036
037    /**
038     * @param a
039     *            inital access flags
040     */
041    public AccessFlags(final int a) {
042        access_flags = a;
043    }
044
045    /**
046     * @return Access flags of the object aka. "modifiers".
047     */
048    public final int getAccessFlags() {
049        return access_flags;
050    }
051
052    /**
053     * @return Access flags of the object aka. "modifiers".
054     */
055    public final int getModifiers() {
056        return access_flags;
057    }
058
059    /**
060     * Set access flags aka "modifiers".
061     *
062     * @param access_flags
063     *            Access flags of the object.
064     */
065    public final void setAccessFlags(final int access_flags) {
066        this.access_flags = access_flags;
067    }
068
069    /**
070     * Set access flags aka "modifiers".
071     *
072     * @param access_flags
073     *            Access flags of the object.
074     */
075    public final void setModifiers(final int access_flags) {
076        setAccessFlags(access_flags);
077    }
078
079    private void setFlag(final int flag, final boolean set) {
080        if ((access_flags & flag) != 0) { // Flag is set already
081            if (!set) {
082                access_flags ^= flag;
083            }
084        } else { // Flag not set
085            if (set) {
086                access_flags |= flag;
087            }
088        }
089    }
090
091    public final void isPublic(final boolean flag) {
092        setFlag(Const.ACC_PUBLIC, flag);
093    }
094
095    public final boolean isPublic() {
096        return (access_flags & Const.ACC_PUBLIC) != 0;
097    }
098
099    public final void isPrivate(final boolean flag) {
100        setFlag(Const.ACC_PRIVATE, flag);
101    }
102
103    public final boolean isPrivate() {
104        return (access_flags & Const.ACC_PRIVATE) != 0;
105    }
106
107    public final void isProtected(final boolean flag) {
108        setFlag(Const.ACC_PROTECTED, flag);
109    }
110
111    public final boolean isProtected() {
112        return (access_flags & Const.ACC_PROTECTED) != 0;
113    }
114
115    public final void isStatic(final boolean flag) {
116        setFlag(Const.ACC_STATIC, flag);
117    }
118
119    public final boolean isStatic() {
120        return (access_flags & Const.ACC_STATIC) != 0;
121    }
122
123    public final void isFinal(final boolean flag) {
124        setFlag(Const.ACC_FINAL, flag);
125    }
126
127    public final boolean isFinal() {
128        return (access_flags & Const.ACC_FINAL) != 0;
129    }
130
131    public final void isSynchronized(final boolean flag) {
132        setFlag(Const.ACC_SYNCHRONIZED, flag);
133    }
134
135    public final boolean isSynchronized() {
136        return (access_flags & Const.ACC_SYNCHRONIZED) != 0;
137    }
138
139    public final void isVolatile(final boolean flag) {
140        setFlag(Const.ACC_VOLATILE, flag);
141    }
142
143    public final boolean isVolatile() {
144        return (access_flags & Const.ACC_VOLATILE) != 0;
145    }
146
147    public final void isTransient(final boolean flag) {
148        setFlag(Const.ACC_TRANSIENT, flag);
149    }
150
151    public final boolean isTransient() {
152        return (access_flags & Const.ACC_TRANSIENT) != 0;
153    }
154
155    public final void isNative(final boolean flag) {
156        setFlag(Const.ACC_NATIVE, flag);
157    }
158
159    public final boolean isNative() {
160        return (access_flags & Const.ACC_NATIVE) != 0;
161    }
162
163    public final void isInterface(final boolean flag) {
164        setFlag(Const.ACC_INTERFACE, flag);
165    }
166
167    public final boolean isInterface() {
168        return (access_flags & Const.ACC_INTERFACE) != 0;
169    }
170
171    public final void isAbstract(final boolean flag) {
172        setFlag(Const.ACC_ABSTRACT, flag);
173    }
174
175    public final boolean isAbstract() {
176        return (access_flags & Const.ACC_ABSTRACT) != 0;
177    }
178
179    public final void isStrictfp(final boolean flag) {
180        setFlag(Const.ACC_STRICT, flag);
181    }
182
183    public final boolean isStrictfp() {
184        return (access_flags & Const.ACC_STRICT) != 0;
185    }
186
187    public final void isSynthetic(final boolean flag) {
188        setFlag(Const.ACC_SYNTHETIC, flag);
189    }
190
191    public final boolean isSynthetic() {
192        return (access_flags & Const.ACC_SYNTHETIC) != 0;
193    }
194
195    public final void isAnnotation(final boolean flag) {
196        setFlag(Const.ACC_ANNOTATION, flag);
197    }
198
199    public final boolean isAnnotation() {
200        return (access_flags & Const.ACC_ANNOTATION) != 0;
201    }
202
203    public final void isEnum(final boolean flag) {
204        setFlag(Const.ACC_ENUM, flag);
205    }
206
207    public final boolean isEnum() {
208        return (access_flags & Const.ACC_ENUM) != 0;
209    }
210
211    public final void isVarArgs(final boolean flag) {
212        setFlag(Const.ACC_VARARGS, flag);
213    }
214
215    public final boolean isVarArgs() {
216        return (access_flags & Const.ACC_VARARGS) != 0;
217    }
218}