1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
/* *******************************************************************
* Copyright (c) 2004 IBM
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v 2.0
* which accompanies this distribution and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
*
* Contributors:
* Andy Clement - initial implementation {date}
* ******************************************************************/
package org.aspectj.apache.bcel.classfile.annotation;
import java.io.DataOutputStream;
import java.io.IOException;
import org.aspectj.apache.bcel.classfile.ConstantPool;
public class ArrayElementValue extends ElementValue {
private static final ElementValue[] NO_VALUES = new ElementValue[0];
// J5TODO: Should we make this an array or a list? A list would be easier to modify ...
private ElementValue[] evalues = NO_VALUES;
public ElementValue[] getElementValuesArray() {
return evalues;
}
public int getElementValuesArraySize() {
return evalues.length;
}
public ArrayElementValue(ConstantPool cp) {
super(ARRAY, cp);
}
public ArrayElementValue(int type, ElementValue[] datums, ConstantPool cpool) {
super(type, cpool);
if (type != ARRAY)
throw new RuntimeException("Only element values of type array can be built with this ctor");
this.evalues = datums;
}
public ArrayElementValue(ArrayElementValue value, ConstantPool cpool, boolean copyPoolEntries) {
super(ARRAY, cpool);
evalues = new ElementValue[value.getElementValuesArraySize()];
ElementValue[] in = value.getElementValuesArray();
for (int i = 0; i < in.length; i++) {
evalues[i] = ElementValue.copy(in[i], cpool, copyPoolEntries);
}
}
@Override
public void dump(DataOutputStream dos) throws IOException {
dos.writeByte(type); // u1 type of value (ARRAY == '[')
dos.writeShort(evalues.length);
for (ElementValue evalue : evalues) {
evalue.dump(dos);
}
}
@Override
public String stringifyValue() {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i = 0; i < evalues.length; i++) {
ElementValue element = evalues[i];
sb.append(element.stringifyValue());
if ((i + 1) < evalues.length)
sb.append(",");
}
sb.append("]");
return sb.toString();
}
public void addElement(ElementValue gen) {
ElementValue[] old = evalues;
evalues = new ElementValue[evalues.length + 1];
System.arraycopy(old, 0, evalues, 0, old.length);
evalues[old.length] = gen;
}
}
|