Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/chaoswg/xtc4y/classdesc/FieldAccessFlags.java


1   //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/FieldAccessFlags.java,v 1.2 2003/09/08 21:04:11 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:11 $, by $Author: toggm $            *
9    * Version: $Revision: 1.2 $                                                  *
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 FieldAccessFlags extends AccessFlags {
29      private short access;    
30      
31      /**
32       * Constructs a new field access flag
33       * @param access initial access flag
34       **/
35      public FieldAccessFlags(short access) {
36    super(access);
37      }
38  
39      /**
40       * Creates a FieldAccessFlags and initializes it from a DataInputStream
41       * @param dis the DataInputStream to read from
42       **/
43      protected FieldAccessFlags(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 public
66       **/
67      public boolean isPublic() {
68    return (access & ACC_PUBLIC) == ACC_PUBLIC;
69      }
70  
71      /**
72       * @return true if it is private
73       **/
74      public boolean isPrivate() {
75    return (access & ACC_PRIVATE) == ACC_PRIVATE;
76      }
77  
78      /**
79       * @return true if it is protected
80       **/
81      public boolean isProtected() {
82    return (access & ACC_PROTECTED) == ACC_PROTECTED;
83      }
84  
85      /**
86       * @return true if it is static
87       **/
88      public boolean isStatic() {
89    return (access & ACC_STATIC) == ACC_STATIC;
90      }
91  
92      /**
93       * @return true if field is final
94       **/
95      public boolean isFinal() {
96    return (access & ACC_FINAL) == ACC_FINAL;
97      }
98  
99      /**
100      * @return true if field is volatile
101      **/
102     public boolean isVolatile() {
103   return (access & ACC_VOLATILE) == ACC_VOLATILE;
104     }
105     
106     /**
107      * @return true if field is transient
108      **/
109     public boolean isTransient() {
110   return (access & ACC_TRANSIENT) == ACC_TRANSIENT;
111     }
112 
113     /**
114      * Set the field to be public
115      **/
116     public void setPublic() {   
117   access &= MASK_ACCESS;
118   access |= ACC_PUBLIC;  
119     }
120 
121     /**
122      * Set the field to be private
123      **/
124     public void setPrivate() {   
125   access &= MASK_ACCESS;
126   access |= ACC_PRIVATE;  
127     }
128 
129     /**
130      * Set the field to be protected
131      **/
132     public void setProtected() {   
133   access &= MASK_ACCESS;
134   access |= ACC_PROTECTED;  
135     }
136 
137     /**
138      * Set the static flag
139      * @param value true or false
140      **/
141     public void setIsStatic(boolean value) {
142   if (value) {
143       access |= ACC_STATIC;
144   }
145   else {
146       //reset flag
147       access &= ACC_STATIC;
148   }
149     }
150 
151     /**
152      * Set the final flag
153      * @param value true or false
154      **/
155     public void setIsFinal(boolean value) {
156   if (value) {
157       if (isVolatile()) {
158     throw new IllegalStateException("A volatile field can't be "+
159             "set to final. First unset "+
160             "the volatile flag if "+
161             "desired");
162       }
163       access |= ACC_FINAL;
164   }
165   else {
166       //reset flag
167       access &= ACC_FINAL_COMP;
168   }
169     }
170 
171     /**
172      * Set the voaltile flag
173      * @param value true or false
174      **/
175     public void setIsVolatile(boolean value) {
176   if (value) {
177       if (isFinal()) {
178     throw new IllegalStateException("A final field can't be "+
179             "set to volatile. First unset"+
180             " the final flag if "+
181             "desired");
182       }
183       access |= ACC_VOLATILE;
184   }
185   else {
186       //reset flag
187       access &= ACC_VOLATILE_COMP;
188   }
189     }
190 
191     /**
192      * Set the transient flag
193      * @param value true or false
194      **/
195     public void setIsTransient(boolean value) {
196   if (value) {
197       access |= ACC_TRANSIENT;
198   }
199   else {
200       //reset flag
201       access &= ACC_TRANSIENT_COMP;
202   }
203     }
204 }