    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 * @version $Id: AccessFlags.java 1748636 2016-06-15 20:45:17Z dbrosius $
    026 */
    027public abstract class AccessFlags {
    028
    029    /**
    030     * @deprecated (since 6.0) will be made private; do not access directly, use getter/setter
    031     */
    032    @java.lang.Deprecated
    033    protected int access_flags; // TODO not used externally at present
    034
    035    public AccessFlags() {
    036    }
    037
    038    /**
    039     * @param a
    040     *            inital access flags
    041     */
    042    public AccessFlags(final int a) {
    043        access_flags = a;
    044    }
    045
    046    /**
    047     * @return Access flags of the object aka. "modifiers".
    048     */
    049    public final int getAccessFlags() {
    050        return access_flags;
    051    }
    052
    053    /**
    054     * @return Access flags of the object aka. "modifiers".
    055     */
    056    public final int getModifiers() {
    057        return access_flags;
    058    }
    059
    060    /**
    061     * Set access flags aka "modifiers".
    062     *
    063     * @param access_flags
    064     *            Access flags of the object.
    065     */
    066    public final void setAccessFlags(final int access_flags) {
    067        this.access_flags = access_flags;
    068    }
    069
    070    /**
    071     * Set access flags aka "modifiers".
    072     *
    073     * @param access_flags
    074     *            Access flags of the object.
    075     */
    076    public final void setModifiers(final int access_flags) {
    077        setAccessFlags(access_flags);
    078    }
    079
    080    private void setFlag(final int flag, final boolean set) {
    081        if ((access_flags & flag) != 0) { // Flag is set already
    082            if (!set) {
    083                access_flags ^= flag;
    084            }
    085        } else { // Flag not set
    086            if (set) {
    087                access_flags |= flag;
    088            }
    089        }
    090    }
    091
    092    public final void isPublic(final boolean flag) {
    093        setFlag(Const.ACC_PUBLIC, flag);
    094    }
    095
    096    public final boolean isPublic() {
    097        return (access_flags & Const.ACC_PUBLIC) != 0;
    098    }
    099
    100    public final void isPrivate(final boolean flag) {
    101        setFlag(Const.ACC_PRIVATE, flag);
    102    }
    103
    104    public final boolean isPrivate() {
    105        return (access_flags & Const.ACC_PRIVATE) != 0;
    106    }
    107
    108    public final void isProtected(final boolean flag) {
    109        setFlag(Const.ACC_PROTECTED, flag);
    110    }
    111
    112    public final boolean isProtected() {
    113        return (access_flags & Const.ACC_PROTECTED) != 0;
    114    }
    115
    116    public final void isStatic(final boolean flag) {
    117        setFlag(Const.ACC_STATIC, flag);
    118    }
    119
    120    public final boolean isStatic() {
    121        return (access_flags & Const.ACC_STATIC) != 0;
    122    }
    123
    124    public final void isFinal(final boolean flag) {
    125        setFlag(Const.ACC_FINAL, flag);
    126    }
    127
    128    public final boolean isFinal() {
    129        return (access_flags & Const.ACC_FINAL) != 0;
    130    }
    131
    132    public final void isSynchronized(final boolean flag) {
    133        setFlag(Const.ACC_SYNCHRONIZED, flag);
    134    }
    135
    136    public final boolean isSynchronized() {
    137        return (access_flags & Const.ACC_SYNCHRONIZED) != 0;
    138    }
    139
    140    public final void isVolatile(final boolean flag) {
    141        setFlag(Const.ACC_VOLATILE, flag);
    142    }
    143
    144    public final boolean isVolatile() {
    145        return (access_flags & Const.ACC_VOLATILE) != 0;
    146    }
    147
    148    public final void isTransient(final boolean flag) {
    149        setFlag(Const.ACC_TRANSIENT, flag);
    150    }
    151
    152    public final boolean isTransient() {
    153        return (access_flags & Const.ACC_TRANSIENT) != 0;
    154    }
    155
    156    public final void isNative(final boolean flag) {
    157        setFlag(Const.ACC_NATIVE, flag);
    158    }
    159
    160    public final boolean isNative() {
    161        return (access_flags & Const.ACC_NATIVE) != 0;
    162    }
    163
    164    public final void isInterface(final boolean flag) {
    165        setFlag(Const.ACC_INTERFACE, flag);
    166    }
    167
    168    public final boolean isInterface() {
    169        return (access_flags & Const.ACC_INTERFACE) != 0;
    170    }
    171
    172    public final void isAbstract(final boolean flag) {
    173        setFlag(Const.ACC_ABSTRACT, flag);
    174    }
    175
    176    public final boolean isAbstract() {
    177        return (access_flags & Const.ACC_ABSTRACT) != 0;
    178    }
    179
    180    public final void isStrictfp(final boolean flag) {
    181        setFlag(Const.ACC_STRICT, flag);
    182    }
    183
    184    public final boolean isStrictfp() {
    185        return (access_flags & Const.ACC_STRICT) != 0;
    186    }
    187
    188    public final void isSynthetic(final boolean flag) {
    189        setFlag(Const.ACC_SYNTHETIC, flag);
    190    }
    191
    192    public final boolean isSynthetic() {
    193        return (access_flags & Const.ACC_SYNTHETIC) != 0;
    194    }
    195
    196    public final void isAnnotation(final boolean flag) {
    197        setFlag(Const.ACC_ANNOTATION, flag);
    198    }
    199
    200    public final boolean isAnnotation() {
    201        return (access_flags & Const.ACC_ANNOTATION) != 0;
    202    }
    203
    204    public final void isEnum(final boolean flag) {
    205        setFlag(Const.ACC_ENUM, flag);
    206    }
    207
    208    public final boolean isEnum() {
    209        return (access_flags & Const.ACC_ENUM) != 0;
    210    }
    211
    212    public final void isVarArgs(final boolean flag) {
    213        setFlag(Const.ACC_VARARGS, flag);
    214    }
    215
    216    public final boolean isVarArgs() {
    217        return (access_flags & Const.ACC_VARARGS) != 0;
    218    }
    219}