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.DataInput;
20 import java.io.DataOutputStream;
21 import java.io.IOException;
22
23 import org.apache.bcel.Constants;
24 import org.apache.bcel.util.Args;
25
26
27
28
29
30
31
32
33
34
35
36
37
38 public final class LocalVariable implements Cloneable, Node, Constants {
39
40 static final LocalVariable[] EMPTY_ARRAY = {};
41
42
43 private int startPc;
44
45 private int length;
46
47
48 private int nameIndex;
49
50
51
52
53 private int signatureIndex;
54
55
56
57
58 private int index;
59
60 private ConstantPool constantPool;
61
62
63 private final int origIndex;
64
65
66
67
68
69
70
71 LocalVariable(final DataInput file, final ConstantPool constantPool) throws IOException {
72 this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), constantPool);
73 }
74
75
76
77
78
79
80
81
82
83 public LocalVariable(final int startPc, final int length, final int nameIndex, final int signatureIndex, final int index, final ConstantPool constantPool) {
84 this(startPc, length, nameIndex, signatureIndex, index, constantPool, index);
85 }
86
87
88
89
90
91
92
93
94
95
96 public LocalVariable(final int startPc, final int length, final int nameIndex, final int signatureIndex, final int index, final ConstantPool constantPool,
97 final int origIndex) {
98 this.startPc = Args.requireU2(startPc, "startPc");
99 this.length = Args.requireU2(length, "length");
100 this.nameIndex = Args.requireU2(nameIndex, "nameIndex");
101 this.signatureIndex = Args.requireU2(signatureIndex, "signatureIndex");
102 this.index = Args.requireU2(index, "index");
103 this.origIndex = Args.requireU2(origIndex, "origIndex");
104 this.constantPool = constantPool;
105 }
106
107
108
109
110
111
112
113 public LocalVariable(final LocalVariable localVariable) {
114 this(localVariable.getStartPC(), localVariable.getLength(), localVariable.getNameIndex(), localVariable.getSignatureIndex(), localVariable.getIndex(),
115 localVariable.getConstantPool());
116 }
117
118
119
120
121
122
123
124 @Override
125 public void accept(final Visitor v) {
126 v.visitLocalVariable(this);
127 }
128
129
130
131
132 public LocalVariable copy() {
133 try {
134 return (LocalVariable) clone();
135 } catch (final CloneNotSupportedException e) {
136
137 }
138 return null;
139 }
140
141
142
143
144
145
146
147
148 public void dump(final DataOutputStream dataOutputStream) throws IOException {
149 dataOutputStream.writeShort(startPc);
150 dataOutputStream.writeShort(length);
151 dataOutputStream.writeShort(nameIndex);
152 dataOutputStream.writeShort(signatureIndex);
153 dataOutputStream.writeShort(index);
154 }
155
156
157
158
159 public ConstantPool getConstantPool() {
160 return constantPool;
161 }
162
163
164
165
166 public int getIndex() {
167 return index;
168 }
169
170
171
172
173 public int getLength() {
174 return length;
175 }
176
177
178
179
180 public String getName() {
181 return constantPool.getConstantUtf8(nameIndex).getBytes();
182 }
183
184
185
186
187 public int getNameIndex() {
188 return nameIndex;
189 }
190
191
192
193
194 public int getOrigIndex() {
195 return origIndex;
196 }
197
198
199
200
201 public String getSignature() {
202 return constantPool.getConstantUtf8(signatureIndex).getBytes();
203 }
204
205
206
207
208 public int getSignatureIndex() {
209 return signatureIndex;
210 }
211
212
213
214
215 public int getStartPC() {
216 return startPc;
217 }
218
219
220
221
222 public void setConstantPool(final ConstantPool constantPool) {
223 this.constantPool = constantPool;
224 }
225
226
227
228
229 public void setIndex(final int index) {
230 this.index = index;
231 }
232
233
234
235
236 public void setLength(final int length) {
237 this.length = length;
238 }
239
240
241
242
243 public void setNameIndex(final int nameIndex) {
244 this.nameIndex = nameIndex;
245 }
246
247
248
249
250 public void setSignatureIndex(final int signatureIndex) {
251 this.signatureIndex = signatureIndex;
252 }
253
254
255
256
257 public void setStartPC(final int startPc) {
258 this.startPc = startPc;
259 }
260
261
262
263
264 @Override
265 public String toString() {
266 return toStringShared(false);
267 }
268
269
270
271
272 String toStringShared(final boolean typeTable) {
273 final String name = getName();
274 final String signature = Utility.signatureToString(getSignature(), false);
275 final String label = "LocalVariable" + (typeTable ? "Types" : "");
276 return label + "(startPc = " + startPc + ", length = " + length + ", index = " + index + ":" + signature + " " + name + ")";
277 }
278 }