KickJava   Java API By Example, From Geeks To Geeks.

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


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

26 public class ArrayMemberValue extends MemberValue {
27     MemberValue type;
28     MemberValue[] values;
29
30     /**
31      * Constructs an array. The initial value or type are not specified.
32      */

33     public ArrayMemberValue(ConstPool cp) {
34         super('[', cp);
35         type = null;
36         values = null;
37     }
38
39     /**
40      * Constructs an array. The initial value is not specified.
41      *
42      * @param t the type of the array elements.
43      */

44     public ArrayMemberValue(MemberValue t, ConstPool cp) {
45         super('[', cp);
46         type = t;
47         values = null;
48     }
49
50     /**
51      * Obtains the type of the elements.
52      *
53      * @return null if the type is not specified.
54      */

55     public MemberValue getType() {
56         return type;
57     }
58
59     /**
60      * Obtains the elements of the array.
61      */

62     public MemberValue[] getValue() {
63         return values;
64     }
65
66     /**
67      * Sets the elements of the array.
68      */

69     public void setValue(MemberValue[] elements) {
70         values = elements;
71         if (elements != null && elements.length > 0)
72             type = elements[0];
73     }
74
75     /**
76      * Obtains the string representation of this object.
77      */

78     public String JavaDoc toString() {
79         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("{");
80         if (values != null) {
81             for (int i = 0; i < values.length; i++) {
82                 buf.append(values[i].toString());
83                 if (i + 1 < values.length)
84                     buf.append(", ");
85                 }
86         }
87
88         buf.append("}");
89         return buf.toString();
90     }
91
92     void write(AnnotationsWriter writer) throws IOException JavaDoc {
93         int num = values.length;
94         writer.arrayValue(num);
95         for (int i = 0; i < num; ++i)
96             values[i].write(writer);
97     }
98
99     /**
100      * Accepts a visitor.
101      */

102     public void accept(MemberValueVisitor visitor) {
103         visitor.visitArrayMemberValue(this);
104     }
105 }
106
Popular Tags