KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Byte constant value.
22  *
23  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
24  * @author Shigeru Chiba
25  */

26 public class ByteMemberValue extends MemberValue {
27     int valueIndex;
28
29     /**
30      * Constructs a byte 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 ByteMemberValue(int index, ConstPool cp) {
36         super('B', cp);
37         this.valueIndex = index;
38     }
39
40     /**
41      * Constructs a byte constant value.
42      *
43      * @param b the initial value.
44      */

45     public ByteMemberValue(byte b, ConstPool cp) {
46         super('B', cp);
47         setValue(b);
48     }
49
50     /**
51      * Constructs a byte constant value. The initial value is 0.
52      */

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

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

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

75     public String JavaDoc toString() {
76         return Byte.toString(getValue());
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.visitByteMemberValue(this);
88     }
89 }
90
Popular Tags