1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.generic;
18
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21
22 import org.apache.bcel.classfile.ClassElementValue;
23 import org.apache.bcel.classfile.ConstantUtf8;
24 import org.apache.bcel.classfile.ElementValue;
25
26
27
28
29 public class ClassElementValueGen extends ElementValueGen {
30
31
32
33 private final int idx;
34
35 public ClassElementValueGen(final ClassElementValue value, final ConstantPoolGen cpool, final boolean copyPoolEntries) {
36 super(CLASS, cpool);
37 if (copyPoolEntries) {
38
39 idx = cpool.addUtf8(value.getClassString());
40 } else {
41 idx = value.getIndex();
42 }
43 }
44
45 protected ClassElementValueGen(final int typeIdx, final ConstantPoolGen cpool) {
46 super(CLASS, cpool);
47 this.idx = typeIdx;
48 }
49
50 public ClassElementValueGen(final ObjectType t, final ConstantPoolGen cpool) {
51 super(CLASS, cpool);
52
53 idx = cpool.addUtf8(t.getSignature());
54 }
55
56 @Override
57 public void dump(final DataOutputStream dos) throws IOException {
58 dos.writeByte(super.getElementValueType());
59 dos.writeShort(idx);
60 }
61
62 public String getClassString() {
63 final ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(idx);
64 return cu8.getBytes();
65
66
67
68
69 }
70
71
72
73
74 @Override
75 public ElementValue getElementValue() {
76 return new ClassElementValue(super.getElementValueType(), idx, getConstantPool().getConstantPool());
77 }
78
79 public int getIndex() {
80 return idx;
81 }
82
83 @Override
84 public String stringifyValue() {
85 return getClassString();
86 }
87 }