1/*
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3 */
4/*
5 * Licensed to the Apache Software Foundation (ASF) under one or more
6 * contributor license agreements.  See the NOTICE file distributed with
7 * this work for additional information regarding copyright ownership.
8 * The ASF licenses this file to You under the Apache License, Version 2.0
9 * (the "License"); you may not use this file except in compliance with
10 * the License.  You may obtain a copy of the License at
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20package com.sun.org.apache.bcel.internal.classfile;
21
22import com.sun.org.apache.bcel.internal.Const;
23
24/**
25 * Super class for all objects that have modifiers like private, final, ... I.e.
26 * classes, fields, and methods.
27 *
28 * @version $Id: AccessFlags.java 1748636 2016-06-15 20:45:17Z dbrosius $
29 */
30public abstract class AccessFlags {
31
32    private int access_flags;
33
34    public AccessFlags() {
35    }
36
37    /**
38     * @param a inital access flags
39     */
40    public AccessFlags(final int a) {
41        access_flags = a;
42    }
43
44    /**
45     * @return Access flags of the object aka. "modifiers".
46     */
47    public final int getAccessFlags() {
48        return access_flags;
49    }
50
51    /**
52     * @return Access flags of the object aka. "modifiers".
53     */
54    public final int getModifiers() {
55        return access_flags;
56    }
57
58    /**
59     * Set access flags aka "modifiers".
60     *
61     * @param access_flags Access flags of the object.
62     */
63    public final void setAccessFlags(final int access_flags) {
64        this.access_flags = access_flags;
65    }
66
67    /**
68     * Set access flags aka "modifiers".
69     *
70     * @param access_flags Access flags of the object.
71     */
72    public final void setModifiers(final int access_flags) {
73        setAccessFlags(access_flags);
74    }
75
76    private void setFlag(final int flag, final boolean set) {
77        if ((access_flags & flag) != 0) { // Flag is set already
78            if (!set) {
79                access_flags ^= flag;
80            }
81        } else { // Flag not set
82            if (set) {
83                access_flags |= flag;
84            }
85        }
86    }
87
88    public final void isPublic(final boolean flag) {
89        setFlag(Const.ACC_PUBLIC, flag);
90    }
91
92    public final boolean isPublic() {
93        return (access_flags & Const.ACC_PUBLIC) != 0;
94    }
95
96    public final void isPrivate(final boolean flag) {
97        setFlag(Const.ACC_PRIVATE, flag);
98    }
99
100    public final boolean isPrivate() {
101        return (access_flags & Const.ACC_PRIVATE) != 0;
102    }
103
104    public final void isProtected(final boolean flag) {
105        setFlag(Const.ACC_PROTECTED, flag);
106    }
107
108    public final boolean isProtected() {
109        return (access_flags & Const.ACC_PROTECTED) != 0;
110    }
111
112    public final void isStatic(final boolean flag) {
113        setFlag(Const.ACC_STATIC, flag);
114    }
115
116    public final boolean isStatic() {
117        return (access_flags & Const.ACC_STATIC) != 0;
118    }
119
120    public final void isFinal(final boolean flag) {
121        setFlag(Const.ACC_FINAL, flag);
122    }
123
124    public final boolean isFinal() {
125        return (access_flags & Const.ACC_FINAL) != 0;
126    }
127
128    public final void isSynchronized(final boolean flag) {
129        setFlag(Const.ACC_SYNCHRONIZED, flag);
130    }
131
132    public final boolean isSynchronized() {
133        return (access_flags & Const.ACC_SYNCHRONIZED) != 0;
134    }
135
136    public final void isVolatile(final boolean flag) {
137        setFlag(Const.ACC_VOLATILE, flag);
138    }
139
140    public final boolean isVolatile() {
141        return (access_flags & Const.ACC_VOLATILE) != 0;
142    }
143
144    public final void isTransient(final boolean flag) {
145        setFlag(Const.ACC_TRANSIENT, flag);
146    }
147
148    public final boolean isTransient() {
149        return (access_flags & Const.ACC_TRANSIENT) != 0;
150    }
151
152    public final void isNative(final boolean flag) {
153        setFlag(Const.ACC_NATIVE, flag);
154    }
155
156    public final boolean isNative() {
157        return (access_flags & Const.ACC_NATIVE) != 0;
158    }
159
160    public final void isInterface(final boolean flag) {
161        setFlag(Const.ACC_INTERFACE, flag);
162    }
163
164    public final boolean isInterface() {
165        return (access_flags & Const.ACC_INTERFACE) != 0;
166    }
167
168    public final void isAbstract(final boolean flag) {
169        setFlag(Const.ACC_ABSTRACT, flag);
170    }
171
172    public final boolean isAbstract() {
173        return (access_flags & Const.ACC_ABSTRACT) != 0;
174    }
175
176    public final void isStrictfp(final boolean flag) {
177        setFlag(Const.ACC_STRICT, flag);
178    }
179
180    public final boolean isStrictfp() {
181        return (access_flags & Const.ACC_STRICT) != 0;
182    }
183
184    public final void isSynthetic(final boolean flag) {
185        setFlag(Const.ACC_SYNTHETIC, flag);
186    }
187
188    public final boolean isSynthetic() {
189        return (access_flags & Const.ACC_SYNTHETIC) != 0;
190    }
191
192    public final void isAnnotation(final boolean flag) {
193        setFlag(Const.ACC_ANNOTATION, flag);
194    }
195
196    public final boolean isAnnotation() {
197        return (access_flags & Const.ACC_ANNOTATION) != 0;
198    }
199
200    public final void isEnum(final boolean flag) {
201        setFlag(Const.ACC_ENUM, flag);
202    }
203
204    public final boolean isEnum() {
205        return (access_flags & Const.ACC_ENUM) != 0;
206    }
207
208    public final void isVarArgs(final boolean flag) {
209        setFlag(Const.ACC_VARARGS, flag);
210    }
211
212    public final boolean isVarArgs() {
213        return (access_flags & Const.ACC_VARARGS) != 0;
214    }
215}
216