blob: 81e69d419c25b7cad684e6b2d446281b19db7d4c (
plain)
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
85
86
87
88
89
90
91
92
93
|
package org.apache.bcel.generic;
import java.io.DataOutputStream;
import java.io.IOException;
import org.apache.bcel.classfile.ConstantUtf8;
import org.apache.bcel.classfile.ElementValue;
import org.apache.bcel.classfile.ElementValuePair;
public class ElementValuePairGen
{
private int nameIdx;
private ElementValueGen value;
private ConstantPoolGen cpool;
public ElementValuePairGen(ElementValuePair nvp, ConstantPoolGen cpool,
boolean copyPoolEntries)
{
this.cpool = cpool;
// J5ASSERT:
// Could assert nvp.getNameString() points to the same thing as
// cpool.getConstant(nvp.getNameIndex())
// if
// (!nvp.getNameString().equals(((ConstantUtf8)cpool.getConstant(nvp.getNameIndex())).getBytes()))
// {
// throw new RuntimeException("envp buggered");
// }
if (copyPoolEntries)
{
nameIdx = cpool.addUtf8(nvp.getNameString());
}
else
{
nameIdx = nvp.getNameIndex();
}
value = ElementValueGen.copy(nvp.getValue(), cpool, copyPoolEntries);
}
/**
* Retrieve an immutable version of this ElementNameValuePairGen
*/
public ElementValuePair getElementNameValuePair()
{
ElementValue immutableValue = value.getElementValue();
return new ElementValuePair(nameIdx, immutableValue, cpool
.getConstantPool());
}
protected ElementValuePairGen(int idx, ElementValueGen value,
ConstantPoolGen cpool)
{
this.nameIdx = idx;
this.value = value;
this.cpool = cpool;
}
public ElementValuePairGen(String name, ElementValueGen value,
ConstantPoolGen cpool)
{
this.nameIdx = cpool.addUtf8(name);
this.value = value;
this.cpool = cpool;
}
protected void dump(DataOutputStream dos) throws IOException
{
dos.writeShort(nameIdx); // u2 name of the element
value.dump(dos);
}
public int getNameIndex()
{
return nameIdx;
}
public final String getNameString()
{
// ConstantString cu8 = (ConstantString)cpool.getConstant(nameIdx);
return ((ConstantUtf8) cpool.getConstant(nameIdx)).getBytes();
}
public final ElementValueGen getValue()
{
return value;
}
public String toString()
{
return "ElementValuePair:[" + getNameString() + "="
+ value.stringifyValue() + "]";
}
}
|