KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javassist > bytecode > annotation > BooleanMemberValue


1 /*
2  * Javassist, a Java-bytecode translator toolkit.
3  * Copyright (C) 2004 Bill Burke. All Rights Reserved.
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. Alternatively, the contents of this file may be used under
8  * the terms of the GNU Lesser General Public License Version 2.1 or later.
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  */

15 package javassist.bytecode.annotation;
16
17 import javassist.bytecode.ConstPool;
18 import java.io.IOException JavaDoc;
19
20 /**
21  * Boolean constant value.
22  *
23  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
24  * @author Shigeru Chiba
25  */

26 public class BooleanMemberValue extends MemberValue {
27     int valueIndex;
28
29     /**
30      * Constructs a boolean constant value. The initial value is specified
31      * by the constant pool entry at the given index.
32      *
33      * @param index the index of a CONSTANT_Integer_info structure.
34      */

35     public BooleanMemberValue(int index, ConstPool cp) {
36         super('Z', cp);
37         this.valueIndex = index;
38     }
39
40     /**
41      * Constructs a boolean constant value.
42      *
43      * @param b the initial value.
44      */

45     public BooleanMemberValue(boolean b, ConstPool cp) {
46         super('Z', cp);
47         setValue(b);
48     }
49
50     /**
51      * Constructs a boolean constant value. The initial value is false.
52      */

53     public BooleanMemberValue(ConstPool cp) {
54         super('Z', cp);
55         setValue(false);
56     }
57
58     /**
59      * Obtains the value of the member.
60      */

61     public boolean getValue() {
62         return cp.getIntegerInfo(valueIndex) != 0;
63     }
64
65     /**
66      * Sets the value of the member.
67      */

68     public void setValue(boolean newValue) {
69         valueIndex = cp.addIntegerInfo(newValue ? 1 : 0);
70     }
71
72     /**
73      * Obtains the string representation of this object.
74      */

75     public String JavaDoc toString() {
76         return getValue() ? "true" : "false";
77     }
78
79     void write(AnnotationsWriter writer) throws IOException JavaDoc {
80         writer.constValueIndex(getValue());
81     }
82
83     /**
84      * Accepts a visitor.
85      */

86     public void accept(MemberValueVisitor visitor) {
87         visitor.visitBooleanMemberValue(this);
88     }
89 }
90
Popular Tags