KickJava   Java API By Example, From Geeks To Geeks.

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


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
16 package javassist.bytecode.annotation;
17
18 import javassist.bytecode.ConstPool;
19 import javassist.bytecode.Descriptor;
20 import java.io.IOException JavaDoc;
21
22 /**
23  * Enum constant value.
24  *
25  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
26  * @author Shigeru Chiba
27  */

28 public class EnumMemberValue extends MemberValue {
29     int typeIndex, valueIndex;
30
31     /**
32      * Constructs an enum constant value. The initial value is specified
33      * by the constant pool entries at the given indexes.
34      *
35      * @param type the index of a CONSTANT_Utf8_info structure
36      * representing the enum type.
37      * @param value the index of a CONSTANT_Utf8_info structure.
38      * representing the enum value.
39      */

40     public EnumMemberValue(int type, int value, ConstPool cp) {
41         super('e', cp);
42         this.typeIndex = type;
43         this.valueIndex = value;
44     }
45
46     /**
47      * Constructs an enum constant value.
48      * The initial value is not specified.
49      */

50     public EnumMemberValue(ConstPool cp) {
51         super('e', cp);
52         typeIndex = valueIndex = 0;
53     }
54
55     /**
56      * Obtains the enum type name.
57      *
58      * @return a fully-qualified type name.
59      */

60     public String JavaDoc getType() {
61         return Descriptor.toClassName(cp.getUtf8Info(typeIndex));
62     }
63
64     /**
65      * Changes the enum type name.
66      *
67      * @param typename a fully-qualified type name.
68      */

69     public void setType(String JavaDoc typename) {
70         typeIndex = cp.addUtf8Info(Descriptor.of(typename));
71     }
72
73     /**
74      * Obtains the name of the enum constant value.
75      */

76     public String JavaDoc getValue() {
77         return cp.getUtf8Info(valueIndex);
78     }
79
80     /**
81      * Changes the name of the enum constant value.
82      */

83     public void setValue(String JavaDoc name) {
84         valueIndex = cp.addUtf8Info(name);
85     }
86
87     public String JavaDoc toString() {
88         return getType() + "." + getValue();
89     }
90
91     void write(AnnotationsWriter writer) throws IOException JavaDoc {
92         writer.enumConstValue(getType(), getValue());
93     }
94
95     /**
96      * Accepts a visitor.
97      */

98     public void accept(MemberValueVisitor visitor) {
99         visitor.visitEnumMemberValue(this);
100     }
101 }
102
Popular Tags