1/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements.  See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22package com.sun.org.apache.bcel.internal.classfile;
23
24
25import  com.sun.org.apache.bcel.internal.Constants;
26
27/**
28 * Super class for all objects that have modifiers like private, final, ...
29 * I.e. classes, fields, and methods.
30 *
31 * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
32 */
33public abstract class AccessFlags implements java.io.Serializable {
34  protected int access_flags;
35
36  public AccessFlags() {}
37
38  /**
39   * @param a inital access flags
40   */
41  public AccessFlags(int a) {
42    access_flags = a;
43  }
44
45  /**
46   * @return Access flags of the object aka. "modifiers".
47   */
48  public final int getAccessFlags() { return access_flags; }
49
50  /**
51   * @return Access flags of the object aka. "modifiers".
52   */
53  public final int getModifiers() { return access_flags; }
54
55  /** Set access flags aka "modifiers".
56   * @param access_flags Access flags of the object.
57   */
58  public final void setAccessFlags(int access_flags) {
59    this.access_flags = access_flags;
60  }
61
62  /** Set access flags aka "modifiers".
63   * @param access_flags Access flags of the object.
64   */
65  public final void setModifiers(int access_flags) {
66    setAccessFlags(access_flags);
67  }
68
69  private final void setFlag(int flag, boolean set) {
70    if((access_flags & flag) != 0) { // Flag is set already
71      if(!set) // Delete flag ?
72        access_flags ^= flag;
73    } else {   // Flag not set
74      if(set)  // Set flag ?
75        access_flags |= flag;
76    }
77  }
78
79  public final void isPublic(boolean flag) { setFlag(Constants.ACC_PUBLIC, flag); }
80  public final boolean isPublic() {
81    return (access_flags & Constants.ACC_PUBLIC) != 0;
82  }
83
84  public final void isPrivate(boolean flag) { setFlag(Constants.ACC_PRIVATE, flag); }
85  public final boolean isPrivate() {
86    return (access_flags & Constants.ACC_PRIVATE) != 0;
87  }
88
89  public final void isProtected(boolean flag) { setFlag(Constants.ACC_PROTECTED, flag); }
90  public final boolean isProtected() {
91    return (access_flags & Constants.ACC_PROTECTED) != 0;
92  }
93
94  public final void isStatic(boolean flag) { setFlag(Constants.ACC_STATIC, flag); }
95  public final boolean isStatic() {
96    return (access_flags & Constants.ACC_STATIC) != 0;
97  }
98
99  public final void isFinal(boolean flag) { setFlag(Constants.ACC_FINAL, flag); }
100  public final boolean isFinal() {
101    return (access_flags & Constants.ACC_FINAL) != 0;
102  }
103
104  public final void isSynchronized(boolean flag) { setFlag(Constants.ACC_SYNCHRONIZED, flag); }
105  public final boolean isSynchronized() {
106    return (access_flags & Constants.ACC_SYNCHRONIZED) != 0;
107  }
108
109  public final void isVolatile(boolean flag) { setFlag(Constants.ACC_VOLATILE, flag); }
110  public final boolean isVolatile() {
111    return (access_flags & Constants.ACC_VOLATILE) != 0;
112  }
113
114  public final void isTransient(boolean flag) { setFlag(Constants.ACC_TRANSIENT, flag); }
115  public final boolean isTransient() {
116    return (access_flags & Constants.ACC_TRANSIENT) != 0;
117  }
118
119  public final void isNative(boolean flag) { setFlag(Constants.ACC_NATIVE, flag); }
120  public final boolean isNative() {
121    return (access_flags & Constants.ACC_NATIVE) != 0;
122  }
123
124  public final void isInterface(boolean flag) { setFlag(Constants.ACC_INTERFACE, flag); }
125  public final boolean isInterface() {
126    return (access_flags & Constants.ACC_INTERFACE) != 0;
127  }
128
129  public final void isAbstract(boolean flag) { setFlag(Constants.ACC_ABSTRACT, flag); }
130  public final boolean isAbstract() {
131    return (access_flags & Constants.ACC_ABSTRACT) != 0;
132  }
133
134  public final void isStrictfp(boolean flag) { setFlag(Constants.ACC_STRICT, flag); }
135  public final boolean isStrictfp() {
136    return (access_flags & Constants.ACC_STRICT) != 0;
137  }
138}
139