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