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.Const;
21  
22  /**
23   * Super class for all objects that have modifiers like private, final, ... I.e. classes, fields, and methods.
24   *
25   */
26  public abstract class AccessFlags {
27  
28      /**
29       * @deprecated (since 6.0) will be made private; do not access directly, use getter/setter
30       */
31      @java.lang.Deprecated
32      protected int access_flags; // TODO not used externally at present
33  
34      public AccessFlags() {
35      }
36  
37      /**
38       * @param a
39       *            inital access flags
40       */
41      public AccessFlags(final int a) {
42          access_flags = a;
43      }
44  
45      /**
46       * @return Access flags of the object aka. "modifiers".
47       */
48      public final int getAccessFlags() {
49          return access_flags;
50      }
51  
52      /**
53       * @return Access flags of the object aka. "modifiers".
54       */
55      public final int getModifiers() {
56          return access_flags;
57      }
58  
59      /**
60       * Set access flags aka "modifiers".
61       *
62       * @param access_flags
63       *            Access flags of the object.
64       */
65      public final void setAccessFlags(final int access_flags) {
66          this.access_flags = access_flags;
67      }
68  
69      /**
70       * Set access flags aka "modifiers".
71       *
72       * @param access_flags
73       *            Access flags of the object.
74       */
75      public final void setModifiers(final int access_flags) {
76          setAccessFlags(access_flags);
77      }
78  
79      private void setFlag(final int flag, final 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      public final void isPublic(final boolean flag) {
92          setFlag(Const.ACC_PUBLIC, flag);
93      }
94  
95      public final boolean isPublic() {
96          return (access_flags & Const.ACC_PUBLIC) != 0;
97      }
98  
99      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 }