Source code: com/chaoswg/xtc4y/classdesc/InnerClassAccessFlags.java
1 //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/InnerClassAccessFlags.java,v 1.1 2003/09/08 21:04:54 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/09/08 21:04:54 $, by $Author: toggm $ *
9 * Version: $Revision: 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 a inner class
26 * @author Mike Toggweiler
27 **/
28 public class InnerClassAccessFlags extends AccessFlags {
29 private short access;
30
31 /**
32 * Constructs a new class access flag
33 * @param access initial access flag
34 **/
35 public InnerClassAccessFlags(short access) {
36 super(access);
37 }
38
39 /**
40 * Creates a ClassAccessFlags and initializes it from a DataInputStream
41 * @param dis the DataInputStream to read from
42 **/
43 protected InnerClassAccessFlags(DataInputStream dis) throws IOException {
44 super(dis);
45 }
46
47 /**
48 * Set the read access flag
49 * @param access flag
50 **/
51 protected void setAccessFlag(short access) {
52 this.access = access;
53 }
54
55 /**
56 * Read the possibly modified access flags
57 * @return the current access flags
58 **/
59 protected short getAccessFlag() {
60 return access;
61 }
62
63
64 /**
65 * @return true if it is an interface
66 **/
67 public boolean isInterface() {
68 return ((access & ACC_INTERFACE) == ACC_INTERFACE &&
69 (access & ACC_ABSTRACT) == ACC_ABSTRACT);
70 }
71
72 /**
73 * @return true if it is abstract class or interface
74 **/
75 public boolean isAbstract() {
76 return (access & ACC_ABSTRACT) == ACC_ABSTRACT;
77 }
78
79 /**
80 * @return true if it is public, may be set on an interface, but not
81 * necessary. (an interface implies to be public)
82 **/
83 public boolean isPublic() {
84 return (access & ACC_PUBLIC) == ACC_PUBLIC;
85 }
86
87 /**
88 * @return true if it is private
89 **/
90 public boolean isPrivate() {
91 return (access & ACC_PRIVATE) == ACC_PRIVATE;
92 }
93
94 /**
95 * @return true if it is protected
96 **/
97 public boolean isProtected() {
98 return (access & ACC_PROTECTED) == ACC_PROTECTED;
99 }
100
101 /**
102 * @return true if class is static
103 **/
104 public boolean isStatic() {
105 return (access & ACC_STATIC) == ACC_STATIC;
106 }
107
108 /**
109 * @return true if class is final
110 **/
111 public boolean isFinal() {
112 return (access & ACC_FINAL) == ACC_FINAL;
113 }
114
115 /**
116 * Set the interface flag
117 * @param value true or false
118 **/
119 public void setIsInterface(boolean value) {
120 if (value) {
121 access |= ACC_INTERFACE;
122 setIsAbstract(value);
123 }
124 else {
125 //reset flag
126 access &= ACC_INTERFACE_COMP;
127 }
128 }
129
130 /**
131 * Set the abstract flag
132 * @param value true or false
133 **/
134 public void setIsAbstract(boolean value) {
135 if (value) {
136 if (isFinal()) {
137 throw new IllegalStateException("An abstract class can't be"+
138 "set to final. First unset "+
139 "the abstract flag if "+
140 "desired");
141 }
142 access |= ACC_ABSTRACT;
143 }
144 else {
145 //reset flag
146 access &= ACC_ABSTRACT_COMP;
147 }
148 }
149
150 /**
151 * Set the field to be public
152 **/
153 public void setPublic() {
154 access &= MASK_ACCESS;
155 access |= ACC_PUBLIC;
156 }
157
158 /**
159 * Set the field to be private
160 **/
161 public void setPrivate() {
162 access &= MASK_ACCESS;
163 access |= ACC_PRIVATE;
164 }
165
166 /**
167 * Set the field to be protected
168 **/
169 public void setProtected() {
170 access &= MASK_ACCESS;
171 access |= ACC_PROTECTED;
172 }
173
174 /**
175 * Set the final flag
176 * @param value true or false
177 **/
178 public void setIsFinal(boolean value) {
179 if (value) {
180 if (isAbstract()) {
181 throw new IllegalStateException("A final class can't be set"+
182 " to abstract. First unset "+
183 "the final flag if desired");
184 }
185 access |= ACC_FINAL;
186 }
187 else {
188 //reset flag
189 access &= ACC_FINAL_COMP;
190 }
191 }
192
193 /**
194 * Set the static flag
195 * @param value true or false
196 **/
197 public void setIsStatic(boolean value) {
198 if (value) {
199 access |= ACC_STATIC;
200 }
201 else {
202 //reset flag
203 access &= ACC_STATIC;
204 }
205 }
206 }