15346
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
46174
|
5 |
/*
|
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
7 |
* contributor license agreements. See the NOTICE file distributed with
|
|
8 |
* this work for additional information regarding copyright ownership.
|
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
10 |
* (the "License"); you may not use this file except in compliance with
|
|
11 |
* the License. You may obtain a copy of the License at
|
|
12 |
*
|
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0
|
15346
|
14 |
*
|
46174
|
15 |
* Unless required by applicable law or agreed to in writing, software
|
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18 |
* See the License for the specific language governing permissions and
|
|
19 |
* limitations under the License.
|
15346
|
20 |
*/
|
46174
|
21 |
package com.sun.org.apache.bcel.internal.classfile;
|
15346
|
22 |
|
46174
|
23 |
import java.io.DataInput;
|
|
24 |
import java.io.DataOutputStream;
|
|
25 |
import java.io.IOException;
|
55496
|
26 |
|
46174
|
27 |
import com.sun.org.apache.bcel.internal.Const;
|
15346
|
28 |
|
|
29 |
// The new table is used when generic types are about...
|
55496
|
30 |
|
15346
|
31 |
//LocalVariableTable_attribute {
|
46174
|
32 |
// u2 attribute_name_index;
|
|
33 |
// u4 attribute_length;
|
|
34 |
// u2 local_variable_table_length;
|
|
35 |
// { u2 start_pc;
|
|
36 |
// u2 length;
|
|
37 |
// u2 name_index;
|
|
38 |
// u2 descriptor_index;
|
|
39 |
// u2 index;
|
|
40 |
// } local_variable_table[local_variable_table_length];
|
|
41 |
// }
|
55496
|
42 |
|
15346
|
43 |
//LocalVariableTypeTable_attribute {
|
|
44 |
// u2 attribute_name_index;
|
|
45 |
// u4 attribute_length;
|
|
46 |
// u2 local_variable_type_table_length;
|
|
47 |
// {
|
|
48 |
// u2 start_pc;
|
|
49 |
// u2 length;
|
|
50 |
// u2 name_index;
|
|
51 |
// u2 signature_index;
|
|
52 |
// u2 index;
|
|
53 |
// } local_variable_type_table[local_variable_type_table_length];
|
|
54 |
// }
|
|
55 |
// J5TODO: Needs some testing !
|
55496
|
56 |
|
46174
|
57 |
/**
|
|
58 |
* @since 6.0
|
|
59 |
*/
|
15346
|
60 |
public class LocalVariableTypeTable extends Attribute {
|
|
61 |
|
46174
|
62 |
private LocalVariable[] local_variable_type_table; // variables
|
15346
|
63 |
|
46174
|
64 |
public LocalVariableTypeTable(final LocalVariableTypeTable c) {
|
|
65 |
this(c.getNameIndex(), c.getLength(), c.getLocalVariableTypeTable(), c.getConstantPool());
|
|
66 |
}
|
15346
|
67 |
|
55496
|
68 |
public LocalVariableTypeTable(final int name_index, final int length, final LocalVariable[] local_variable_table, final ConstantPool constant_pool) {
|
46174
|
69 |
super(Const.ATTR_LOCAL_VARIABLE_TYPE_TABLE, name_index, length, constant_pool);
|
|
70 |
this.local_variable_type_table = local_variable_table;
|
|
71 |
}
|
15346
|
72 |
|
55496
|
73 |
LocalVariableTypeTable(final int nameIdx, final int len, final DataInput input, final ConstantPool cpool) throws IOException {
|
46174
|
74 |
this(nameIdx, len, (LocalVariable[]) null, cpool);
|
15346
|
75 |
|
46174
|
76 |
final int local_variable_type_table_length = input.readUnsignedShort();
|
|
77 |
local_variable_type_table = new LocalVariable[local_variable_type_table_length];
|
15346
|
78 |
|
46174
|
79 |
for (int i = 0; i < local_variable_type_table_length; i++) {
|
|
80 |
local_variable_type_table[i] = new LocalVariable(input, cpool);
|
|
81 |
}
|
|
82 |
}
|
15346
|
83 |
|
46174
|
84 |
@Override
|
|
85 |
public void accept(final Visitor v) {
|
|
86 |
v.visitLocalVariableTypeTable(this);
|
|
87 |
}
|
15346
|
88 |
|
46174
|
89 |
@Override
|
|
90 |
public final void dump(final DataOutputStream file) throws IOException {
|
|
91 |
super.dump(file);
|
|
92 |
file.writeShort(local_variable_type_table.length);
|
|
93 |
for (final LocalVariable variable : local_variable_type_table) {
|
|
94 |
variable.dump(file);
|
|
95 |
}
|
|
96 |
}
|
15346
|
97 |
|
46174
|
98 |
public final LocalVariable[] getLocalVariableTypeTable() {
|
|
99 |
return local_variable_type_table;
|
15346
|
100 |
}
|
|
101 |
|
46174
|
102 |
public final LocalVariable getLocalVariable(final int index) {
|
|
103 |
for (final LocalVariable variable : local_variable_type_table) {
|
|
104 |
if (variable.getIndex() == index) {
|
|
105 |
return variable;
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
return null;
|
|
110 |
}
|
15346
|
111 |
|
46174
|
112 |
public final void setLocalVariableTable(final LocalVariable[] local_variable_table) {
|
|
113 |
this.local_variable_type_table = local_variable_table;
|
|
114 |
}
|
|
115 |
|
|
116 |
/**
|
|
117 |
* @return String representation.
|
|
118 |
*/
|
|
119 |
@Override
|
|
120 |
public final String toString() {
|
|
121 |
final StringBuilder buf = new StringBuilder();
|
|
122 |
|
|
123 |
for (int i = 0; i < local_variable_type_table.length; i++) {
|
|
124 |
buf.append(local_variable_type_table[i].toStringShared(true));
|
15346
|
125 |
|
46174
|
126 |
if (i < local_variable_type_table.length - 1) {
|
|
127 |
buf.append('\n');
|
|
128 |
}
|
|
129 |
}
|
|
130 |
|
|
131 |
return buf.toString();
|
|
132 |
}
|
15346
|
133 |
|
46174
|
134 |
/**
|
|
135 |
* @return deep copy of this attribute
|
|
136 |
*/
|
|
137 |
@Override
|
|
138 |
public Attribute copy(final ConstantPool constant_pool) {
|
|
139 |
final LocalVariableTypeTable c = (LocalVariableTypeTable) clone();
|
15346
|
140 |
|
46174
|
141 |
c.local_variable_type_table = new LocalVariable[local_variable_type_table.length];
|
|
142 |
for (int i = 0; i < local_variable_type_table.length; i++) {
|
|
143 |
c.local_variable_type_table[i] = local_variable_type_table[i].copy();
|
|
144 |
}
|
|
145 |
|
|
146 |
c.setConstantPool(constant_pool);
|
|
147 |
return c;
|
|
148 |
}
|
|
149 |
|
|
150 |
public final int getTableLength() {
|
|
151 |
return local_variable_type_table == null ? 0 : local_variable_type_table.length;
|
|
152 |
}
|
15346
|
153 |
}
|