Source code: com/chaoswg/xtc4y/classdesc/MethodAccessFlags.java
1 //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/MethodAccessFlags.java,v 1.1.1.1 2003/08/07 13:40:28 toggm Exp $
2 /******************************************************************************
3 * XTC4y - eXtreme Testing Collection 4 you *
4 * -------------------------------------------------------------------------- *
5 * URL: http://www.chaoswg.com/xtc4y *
6 * Author: Mike Toggweiler (2.dog@gmx.ch) *
7 * *
8 * Last Updated: $Date: 2003/08/07 13:40:28 $, by $Author: toggm $ *
9 * Version: $Revision: 1.1.1.1 $ *
10 * -------------------------------------------------------------------------- *
11 * COPYRIGHT: (c) 2003 by Mike Toggweiler *
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 *****************************************************************************/
18 package com.chaoswg.xtc4y.classdesc;
19
20 import java.io.DataInputStream;
21 import java.io.DataOutputStream;
22 import java.io.IOException;
23
24 /**
25 * this class represents the accessflags configured for the current field
26 * @author Mike Toggweiler
27 **/
28 public class MethodAccessFlags extends AccessFlags {
29 private short access;
30
31 /**
32 * Some masks used
33 **/
34 private static final short MASK_ACCESS = (short)0xFFF0;
35
36 /**
37 * Constructs a new field access flag
38 * @param access initial access flag
39 **/
40 public MethodAccessFlags(short access) {
41 super(access);
42 }
43
44 /**
45 * Creates a MethodAccessFlags and initializes it from a DataInputStream
46 * @param dis the DataInputStream to read from
47 **/
48 protected MethodAccessFlags(DataInputStream dis) throws IOException {
49 super(dis);
50 }
51
52 /**
53 * Set the read access flag
54 * @param access flag
55 **/
56 protected void setAccessFlag(short access) {
57 this.access = access;
58 }
59
60 /**
61 * Read the possibly modified access flags
62 * @return the current access flags
63 **/
64 protected short getAccessFlag() {
65 return access;
66 }
67
68 /**
69 * @return true if it is public
70 **/
71 public boolean isPublic() {
72 return (access & ACC_PUBLIC) == ACC_PUBLIC;
73 }
74
75 /**
76 * @return true if it is private
77 **/
78 public boolean isPrivate() {
79 return (access & ACC_PRIVATE) == ACC_PRIVATE;
80 }
81
82 /**
83 * @return true if it is protected
84 **/
85 public boolean isProtected() {
86 return (access & ACC_PROTECTED) == ACC_PROTECTED;
87 }
88
89 /**
90 * @return true if it is static
91 **/
92 public boolean isStatic() {
93 return (access & ACC_STATIC) == ACC_STATIC;
94 }
95
96 /**
97 * @return true if field is final
98 **/
99 public boolean isFinal() {
100 return (access & ACC_FINAL) == ACC_FINAL;
101 }
102
103 /**
104 * @return true if field is synchronized
105 **/
106 public boolean isSynchronized() {
107 return (access & ACC_SYNCHRONIZED) == ACC_SYNCHRONIZED;
108 }
109
110 /**
111 * @return true if field is native
112 **/
113 public boolean isNative() {
114 return (access & ACC_NATIVE) == ACC_NATIVE;
115 }
116
117 /**
118 * @return true if field is abstract
119 **/
120 public boolean isAbstract() {
121 return (access & ACC_ABSTRACT) == ACC_ABSTRACT;
122 }
123
124 /**
125 * @return true if field is strict
126 **/
127 public boolean isStrict() {
128 return (access & ACC_STRICT) == ACC_STRICT;
129 }
130
131 /**
132 * Set the field to be public
133 **/
134 public void setPublic() {
135 access &= MASK_ACCESS;
136 access |= ACC_PUBLIC;
137 }
138
139 /**
140 * Set the field to be private
141 **/
142 public void setPrivate() {
143 if (isAbstract()) {
144 throw new IllegalStateException("A abstract method can't be "+
145 "set to private. First "+
146 "unset "+
147 "the abstract flag if "+
148 "desired");
149 }
150 access &= MASK_ACCESS;
151 access |= ACC_PRIVATE;
152 }
153
154 /**
155 * Set the field to be protected
156 **/
157 public void setProtected() {
158 access &= MASK_ACCESS;
159 access |= ACC_PROTECTED;
160 }
161
162 /**
163 * Set the static flag
164 * @param value true or false
165 **/
166 public void setIsStatic(boolean value) {
167 if (value) {
168 if (isAbstract()) {
169 throw new IllegalStateException("A abstract method can't be "+
170 "set to static. First unset "+
171 "the abstract flag if "+
172 "desired");
173 }
174 access |= ACC_STATIC;
175 }
176 else {
177 //reset flag
178 access &= ACC_STATIC;
179 }
180 }
181
182 /**
183 * Set the final flag
184 * @param value true or false
185 **/
186 public void setIsFinal(boolean value) {
187 if (value) {
188 if (isAbstract()) {
189 throw new IllegalStateException("A abstract method can't be "+
190 "set to final. First unset "+
191 "the abstract flag if "+
192 "desired");
193 }
194 access |= ACC_FINAL;
195 }
196 else {
197 //reset flag
198 access &= ACC_FINAL_COMP;
199 }
200 }
201
202 /**
203 * Set the synchronized flag
204 * @param value true or false
205 **/
206 public void setIsSynchronized(boolean value) {
207 if (value) {
208 if (isAbstract()) {
209 throw new IllegalStateException("A abstract method can't be "+
210 "set to synchonized. First "+
211 "unset "+
212 "the abstract flag if "+
213 "desired");
214 }
215 access |= ACC_SYNCHRONIZED;
216 }
217 else {
218 //reset flag
219 access &= ACC_SYNCHRONIZED_COMP;
220 }
221 }
222
223 /**
224 * Set the native flag
225 * @param value true or false
226 **/
227 public void setIsNative(boolean value) {
228 if (value) {
229 if (isAbstract()) {
230 throw new IllegalStateException("A abstract method can't be "+
231 "set to native. First "+
232 "unset "+
233 "the abstract flag if "+
234 "desired");
235 }
236 access |= ACC_NATIVE;
237 }
238 else {
239 //reset flag
240 access &= ACC_NATIVE_COMP;
241 }
242 }
243
244 /**
245 * Set the abstract flag
246 * @param value true or false
247 **/
248 public void setIsAbstract(boolean value) {
249 if (value) {
250 if (isFinal()) {
251 throw new IllegalStateException("A final method can't be "+
252 "set to abstract. First "+
253 "unset "+
254 "the final flag if "+
255 "desired");
256 }
257 if (isNative()) {
258 throw new IllegalStateException("A native method can't be "+
259 "set to abstract. First "+
260 "unset "+
261 "the native flag if "+
262 "desired");
263 }
264 if (isPrivate()) {
265 throw new IllegalStateException("A private method can't be "+
266 "set to abstract. First "+
267 "unset "+
268 "the private flag if "+
269 "desired");
270 }
271 if (isStatic()) {
272 throw new IllegalStateException("A static method can't be "+
273 "set to abstract. First "+
274 "unset "+
275 "the static flag if "+
276 "desired");
277 }
278 if (isStrict()) {
279 throw new IllegalStateException("A strict method can't be "+
280 "set to abstract. First "+
281 "unset "+
282 "the strict flag if "+
283 "desired");
284 }
285 if (isSynchronized()) {
286 throw new IllegalStateException("A synchronized method can't"+
287 " be "+
288 "set to abstract. First "+
289 "unset "+
290 "the synchonrized flag if "+
291 "desired");
292 }
293
294 access |= ACC_ABSTRACT;
295 }
296 else {
297 //reset flag
298 access &= ACC_ABSTRACT_COMP;
299 }
300 }
301
302 /**
303 * Set the strict flag
304 * @param value true or false
305 **/
306 public void setIsStrict(boolean value) {
307 if (value) {
308 if (isAbstract()) {
309 throw new IllegalStateException("A abstract method can't be "+
310 "set to strict. First "+
311 "unset "+
312 "the abstract flag if "+
313 "desired");
314 }
315 access |= ACC_STRICT;
316 }
317 else {
318 //reset flag
319 access &= ACC_STRICT_COMP;
320 }
321 }
322 }