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