1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.bcel.classfile;
20
21 import java.io.DataOutputStream;
22 import java.io.IOException;
23
24
25
26
27 public class EnumElementValue extends ElementValue {
28
29 private final int typeIdx;
30
31 private final int valueIdx;
32
33 public EnumElementValue(final int type, final int typeIdx, final int valueIdx, final ConstantPool cpool) {
34 super(type, cpool);
35 if (type != ENUM_CONSTANT) {
36 throw new ClassFormatException("Only element values of type enum can be built with this ctor - type specified: " + type);
37 }
38 this.typeIdx = typeIdx;
39 this.valueIdx = valueIdx;
40 }
41
42 @Override
43 public void dump(final DataOutputStream dos) throws IOException {
44 dos.writeByte(super.getType());
45 dos.writeShort(typeIdx);
46 dos.writeShort(valueIdx);
47 }
48
49 public String getEnumTypeString() {
50 return super.getConstantPool().getConstantUtf8(typeIdx).getBytes();
51 }
52
53 public String getEnumValueString() {
54 return super.getConstantPool().getConstantUtf8(valueIdx).getBytes();
55 }
56
57 public int getTypeIndex() {
58 return typeIdx;
59 }
60
61 public int getValueIndex() {
62 return valueIdx;
63 }
64
65 @Override
66 public String stringifyValue() {
67 return super.getConstantPool().getConstantUtf8(valueIdx).getBytes();
68 }
69 }