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