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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
|
/*
* Javassist, a Java-bytecode translator toolkit.
* Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. Alternatively, the contents of this file may be used under
* the terms of the GNU Lesser General Public License Version 2.1 or later,
* or the Apache License Version 2.0.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*/
package javassist.bytecode;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javassist.CtClass;
/**
* Constant pool table.
*/
public final class ConstPool
{
LongVector items;
int numOfItems;
int thisClassInfo;
Map<ConstInfo,ConstInfo> itemsCache;
/**
* <code>CONSTANT_Class</code>
*/
public static final int CONST_Class = ClassInfo.tag;
/**
* <code>CONSTANT_Fieldref</code>
*/
public static final int CONST_Fieldref = FieldrefInfo.tag;
/**
* <code>CONSTANT_Methodref</code>
*/
public static final int CONST_Methodref = MethodrefInfo.tag;
/**
* <code>CONSTANT_InterfaceMethodref</code>
*/
public static final int CONST_InterfaceMethodref
= InterfaceMethodrefInfo.tag;
/**
* <code>CONSTANT_String</code>
*/
public static final int CONST_String = StringInfo.tag;
/**
* <code>CONSTANT_Integer</code>
*/
public static final int CONST_Integer = IntegerInfo.tag;
/**
* <code>CONSTANT_Float</code>
*/
public static final int CONST_Float = FloatInfo.tag;
/**
* <code>CONSTANT_Long</code>
*/
public static final int CONST_Long = LongInfo.tag;
/**
* <code>CONSTANT_Double</code>
*/
public static final int CONST_Double = DoubleInfo.tag;
/**
* <code>CONSTANT_NameAndType</code>
*/
public static final int CONST_NameAndType = NameAndTypeInfo.tag;
/**
* <code>CONSTANT_Utf8</code>
*/
public static final int CONST_Utf8 = Utf8Info.tag;
/**
* <code>CONSTANT_MethodHandle</code>
*/
public static final int CONST_MethodHandle = MethodHandleInfo.tag;
/**
* <code>CONSTANT_MethodHandle</code>
*/
public static final int CONST_MethodType = MethodTypeInfo.tag;
/**
* <code>CONSTANT_Dynamic</code>
*/
public static final int CONST_Dynamic = DynamicInfo.tag;
/**
* <code>CONSTANT_DynamicCallSite</code>,
* also known as <code>CONSTANT_InvokeDynamic</code>
*/
public static final int CONST_DynamicCallSite = InvokeDynamicInfo.tag;
public static final int CONST_InvokeDynamic = InvokeDynamicInfo.tag;
/**
* <code>CONSTANT_Module</code>
*/
public static final int CONST_Module = ModuleInfo.tag;
/**
* <code>CONSTANT_Package</code>
*/
public static final int CONST_Package = PackageInfo.tag;
/**
* Represents the class using this constant pool table.
*/
public static final CtClass THIS = null;
/**
* <code>reference_kind</code> of <code>CONSTANT_MethodHandle_info</code>.
*/
public static final int REF_getField = 1;
/**
* <code>reference_kind</code> of <code>CONSTANT_MethodHandle_info</code>.
*/
public static final int REF_getStatic = 2;
/**
* <code>reference_kind</code> of <code>CONSTANT_MethodHandle_info</code>.
*/
public static final int REF_putField = 3;
/**
* <code>reference_kind</code> of <code>CONSTANT_MethodHandle_info</code>.
*/
public static final int REF_putStatic = 4;
/**
* <code>reference_kind</code> of <code>CONSTANT_MethodHandle_info</code>.
*/
public static final int REF_invokeVirtual = 5;
/**
* <code>reference_kind</code> of <code>CONSTANT_MethodHandle_info</code>.
*/
public static final int REF_invokeStatic = 6;
/**
* <code>reference_kind</code> of <code>CONSTANT_MethodHandle_info</code>.
*/
public static final int REF_invokeSpecial = 7;
/**
* <code>reference_kind</code> of <code>CONSTANT_MethodHandle_info</code>.
*/
public static final int REF_newInvokeSpecial = 8;
/**
* <code>reference_kind</code> of <code>CONSTANT_MethodHandle_info</code>.
*/
public static final int REF_invokeInterface = 9;
/**
* Constructs a constant pool table.
*
* @param thisclass the name of the class using this constant
* pool table
*/
public ConstPool(String thisclass)
{
items = new LongVector();
itemsCache = null;
numOfItems = 0;
addItem0(null); // index 0 is reserved by the JVM.
thisClassInfo = addClassInfo(thisclass);
}
/**
* Constructs a constant pool table from the given byte stream.
*
* @param in byte stream.
*/
public ConstPool(DataInputStream in) throws IOException
{
itemsCache = null;
thisClassInfo = 0;
/* read() initializes items and numOfItems, and do addItem(null).
*/
read(in);
}
void prune()
{
itemsCache = null;
}
/**
* Returns the number of entries in this table.
*/
public int getSize()
{
return numOfItems;
}
/**
* Returns the name of the class using this constant pool table.
*/
public String getClassName()
{
return getClassInfo(thisClassInfo);
}
/**
* Returns the index of <code>CONSTANT_Class_info</code> structure
* specifying the class using this constant pool table.
*/
public int getThisClassInfo()
{
return thisClassInfo;
}
void setThisClassInfo(int i)
{
thisClassInfo = i;
}
ConstInfo getItem(int n)
{
return items.elementAt(n);
}
/**
* Returns the <code>tag</code> field of the constant pool table
* entry at the given index.
*
* @return either <code>CONST_Class</code>, <code>CONST_Fieldref</code>,
* <code>CONST_Methodref</code>, or ...
*/
public int getTag(int index)
{
return getItem(index).getTag();
}
/**
* Reads <code>CONSTANT_Class_info</code> structure
* at the given index.
*
* @return a fully-qualified class or interface name specified
* by <code>name_index</code>. If the type is an array
* type, this method returns an encoded name like
* <code>[Ljava.lang.Object;</code> (note that the separators
* are not slashes but dots).
* @see javassist.ClassPool#getCtClass(String)
*/
public String getClassInfo(int index)
{
ClassInfo c = (ClassInfo)getItem(index);
if (c == null)
return null;
return Descriptor.toJavaName(getUtf8Info(c.name));
}
/**
* Reads <code>CONSTANT_Class_info</code> structure
* at the given index.
*
* @return the descriptor of the type specified
* by <code>name_index</code>.
* @see javassist.ClassPool#getCtClass(String)
* @since 3.15
*/
public String getClassInfoByDescriptor(int index)
{
ClassInfo c = (ClassInfo)getItem(index);
if (c == null)
return null;
String className = getUtf8Info(c.name);
if (className.charAt(0) == '[')
return className;
return Descriptor.of(className);
}
/**
* Reads the <code>name_index</code> field of the
* <code>CONSTANT_NameAndType_info</code> structure
* at the given index.
*/
public int getNameAndTypeName(int index)
{
NameAndTypeInfo ntinfo = (NameAndTypeInfo)getItem(index);
return ntinfo.memberName;
}
/**
* Reads the <code>descriptor_index</code> field of the
* <code>CONSTANT_NameAndType_info</code> structure
* at the given index.
*/
public int getNameAndTypeDescriptor(int index)
{
NameAndTypeInfo ntinfo = (NameAndTypeInfo)getItem(index);
return ntinfo.typeDescriptor;
}
/**
* Reads the <code>class_index</code> field of the
* <code>CONSTANT_Fieldref_info</code>,
* <code>CONSTANT_Methodref_info</code>,
* or <code>CONSTANT_Interfaceref_info</code>,
* structure at the given index.
*
* @since 3.6
*/
public int getMemberClass(int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return minfo.classIndex;
}
/**
* Reads the <code>name_and_type_index</code> field of the
* <code>CONSTANT_Fieldref_info</code>,
* <code>CONSTANT_Methodref_info</code>,
* or <code>CONSTANT_Interfaceref_info</code>,
* structure at the given index.
*
* @since 3.6
*/
public int getMemberNameAndType(int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return minfo.nameAndTypeIndex;
}
/**
* Reads the <code>class_index</code> field of the
* <code>CONSTANT_Fieldref_info</code> structure
* at the given index.
*/
public int getFieldrefClass(int index)
{
FieldrefInfo finfo = (FieldrefInfo)getItem(index);
return finfo.classIndex;
}
/**
* Reads the <code>class_index</code> field of the
* <code>CONSTANT_Fieldref_info</code> structure
* at the given index.
*
* @return the name of the class at that <code>class_index</code>.
*/
public String getFieldrefClassName(int index)
{
FieldrefInfo f = (FieldrefInfo)getItem(index);
if (f == null)
return null;
return getClassInfo(f.classIndex);
}
/**
* Reads the <code>name_and_type_index</code> field of the
* <code>CONSTANT_Fieldref_info</code> structure
* at the given index.
*/
public int getFieldrefNameAndType(int index)
{
FieldrefInfo finfo = (FieldrefInfo)getItem(index);
return finfo.nameAndTypeIndex;
}
/**
* Reads the <code>name_index</code> field of the
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
* @param index an index to a <code>CONSTANT_Fieldref_info</code>.
* @return the name of the field.
*/
public String getFieldrefName(int index)
{
FieldrefInfo f = (FieldrefInfo)getItem(index);
if (f == null)
return null;
NameAndTypeInfo n = (NameAndTypeInfo)getItem(f.nameAndTypeIndex);
if(n == null)
return null;
return getUtf8Info(n.memberName);
}
/**
* Reads the <code>descriptor_index</code> field of the
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
* @param index an index to a <code>CONSTANT_Fieldref_info</code>.
* @return the type descriptor of the field.
*/
public String getFieldrefType(int index)
{
FieldrefInfo f = (FieldrefInfo)getItem(index);
if (f == null)
return null;
NameAndTypeInfo n = (NameAndTypeInfo)getItem(f.nameAndTypeIndex);
if(n == null)
return null;
return getUtf8Info(n.typeDescriptor);
}
/**
* Reads the <code>class_index</code> field of the
* <code>CONSTANT_Methodref_info</code> structure
* at the given index.
*/
public int getMethodrefClass(int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return minfo.classIndex;
}
/**
* Reads the <code>class_index</code> field of the
* <code>CONSTANT_Methodref_info</code> structure
* at the given index.
*
* @return the name of the class at that <code>class_index</code>.
*/
public String getMethodrefClassName(int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
if (minfo == null)
return null;
return getClassInfo(minfo.classIndex);
}
/**
* Reads the <code>name_and_type_index</code> field of the
* <code>CONSTANT_Methodref_info</code> structure
* at the given index.
*/
public int getMethodrefNameAndType(int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return minfo.nameAndTypeIndex;
}
/**
* Reads the <code>name_index</code> field of the
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
* @param index an index to a <code>CONSTANT_Methodref_info</code>.
* @return the name of the method.
*/
public String getMethodrefName(int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
if (minfo == null)
return null;
NameAndTypeInfo n
= (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
if(n == null)
return null;
return getUtf8Info(n.memberName);
}
/**
* Reads the <code>descriptor_index</code> field of the
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
* @param index an index to a <code>CONSTANT_Methodref_info</code>.
* @return the descriptor of the method.
*/
public String getMethodrefType(int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
if (minfo == null)
return null;
NameAndTypeInfo n
= (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
if(n == null)
return null;
return getUtf8Info(n.typeDescriptor);
}
/**
* Reads the <code>class_index</code> field of the
* <code>CONSTANT_InterfaceMethodref_info</code> structure
* at the given index.
*/
public int getInterfaceMethodrefClass(int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return minfo.classIndex;
}
/**
* Reads the <code>class_index</code> field of the
* <code>CONSTANT_InterfaceMethodref_info</code> structure
* at the given index.
*
* @return the name of the class at that <code>class_index</code>.
*/
public String getInterfaceMethodrefClassName(int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return getClassInfo(minfo.classIndex);
}
/**
* Reads the <code>name_and_type_index</code> field of the
* <code>CONSTANT_InterfaceMethodref_info</code> structure
* at the given index.
*/
public int getInterfaceMethodrefNameAndType(int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return minfo.nameAndTypeIndex;
}
/**
* Reads the <code>name_index</code> field of the
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
* @param index an index to
* a <code>CONSTANT_InterfaceMethodref_info</code>.
* @return the name of the method.
*/
public String getInterfaceMethodrefName(int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
if (minfo == null)
return null;
NameAndTypeInfo n
= (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
if(n == null)
return null;
return getUtf8Info(n.memberName);
}
/**
* Reads the <code>descriptor_index</code> field of the
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
* @param index an index to
* a <code>CONSTANT_InterfaceMethodref_info</code>.
* @return the descriptor of the method.
*/
public String getInterfaceMethodrefType(int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
if (minfo == null)
return null;
NameAndTypeInfo n
= (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
if(n == null)
return null;
return getUtf8Info(n.typeDescriptor);
}
/**
* Reads <code>CONSTANT_Integer_info</code>, <code>_Float_info</code>,
* <code>_Long_info</code>, <code>_Double_info</code>, or
* <code>_String_info</code> structure.
* These are used with the LDC instruction.
*
* @return a <code>String</code> value or a wrapped primitive-type
* value.
*/
public Object getLdcValue(int index)
{
ConstInfo constInfo = this.getItem(index);
Object value = null;
if (constInfo instanceof StringInfo)
value = this.getStringInfo(index);
else if (constInfo instanceof FloatInfo)
value = Float.valueOf(getFloatInfo(index));
else if (constInfo instanceof IntegerInfo)
value = Integer.valueOf(getIntegerInfo(index));
else if (constInfo instanceof LongInfo)
value = Long.valueOf(getLongInfo(index));
else if (constInfo instanceof DoubleInfo)
value = Double.valueOf(getDoubleInfo(index));
return value;
}
/**
* Reads <code>CONSTANT_Integer_info</code> structure
* at the given index.
*
* @return the value specified by this entry.
*/
public int getIntegerInfo(int index)
{
IntegerInfo i = (IntegerInfo)getItem(index);
return i.value;
}
/**
* Reads <code>CONSTANT_Float_info</code> structure
* at the given index.
*
* @return the value specified by this entry.
*/
public float getFloatInfo(int index)
{
FloatInfo i = (FloatInfo)getItem(index);
return i.value;
}
/**
* Reads <code>CONSTANT_Long_info</code> structure
* at the given index.
*
* @return the value specified by this entry.
*/
public long getLongInfo(int index)
{
LongInfo i = (LongInfo)getItem(index);
return i.value;
}
/**
* Reads <code>CONSTANT_Double_info</code> structure
* at the given index.
*
* @return the value specified by this entry.
*/
public double getDoubleInfo(int index)
{
DoubleInfo i = (DoubleInfo)getItem(index);
return i.value;
}
/**
* Reads <code>CONSTANT_String_info</code> structure
* at the given index.
*
* @return the string specified by <code>string_index</code>.
*/
public String getStringInfo(int index)
{
StringInfo si = (StringInfo)getItem(index);
return getUtf8Info(si.string);
}
/**
* Reads <code>CONSTANT_utf8_info</code> structure
* at the given index.
*
* @return the string specified by this entry.
*/
public String getUtf8Info(int index)
{
Utf8Info utf = (Utf8Info)getItem(index);
return utf.string;
}
/**
* Reads the <code>reference_kind</code> field of the
* <code>CONSTANT_MethodHandle_info</code> structure
* at the given index.
*
* @see #REF_getField
* @see #REF_getStatic
* @see #REF_invokeInterface
* @see #REF_invokeSpecial
* @see #REF_invokeStatic
* @see #REF_invokeVirtual
* @see #REF_newInvokeSpecial
* @see #REF_putField
* @see #REF_putStatic
* @since 3.17
*/
public int getMethodHandleKind(int index)
{
MethodHandleInfo mhinfo = (MethodHandleInfo)getItem(index);
return mhinfo.refKind;
}
/**
* Reads the <code>reference_index</code> field of the
* <code>CONSTANT_MethodHandle_info</code> structure
* at the given index.
*
* @since 3.17
*/
public int getMethodHandleIndex(int index)
{
MethodHandleInfo mhinfo = (MethodHandleInfo)getItem(index);
return mhinfo.refIndex;
}
/**
* Reads the <code>descriptor_index</code> field of the
* <code>CONSTANT_MethodType_info</code> structure
* at the given index.
*
* @since 3.17
*/
public int getMethodTypeInfo(int index)
{
MethodTypeInfo mtinfo = (MethodTypeInfo)getItem(index);
return mtinfo.descriptor;
}
/**
* Reads the <code>bootstrap_method_attr_index</code> field of the
* <code>CONSTANT_InvokeDynamic_info</code> structure
* at the given index.
*
* @since 3.17
*/
public int getInvokeDynamicBootstrap(int index)
{
InvokeDynamicInfo iv = (InvokeDynamicInfo)getItem(index);
return iv.bootstrap;
}
/**
* Reads the <code>name_and_type_index</code> field of the
* <code>CONSTANT_InvokeDynamic_info</code> structure
* at the given index.
*
* @since 3.17
*/
public int getInvokeDynamicNameAndType(int index)
{
InvokeDynamicInfo iv = (InvokeDynamicInfo)getItem(index);
return iv.nameAndType;
}
/**
* Reads the <code>descriptor_index</code> field of the
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
* @param index an index to a <code>CONSTANT_InvokeDynamic_info</code>.
* @return the descriptor of the bootstrap method.
* @since 3.17
*/
public String getInvokeDynamicType(int index)
{
InvokeDynamicInfo iv = (InvokeDynamicInfo)getItem(index);
if (iv == null)
return null;
NameAndTypeInfo n = (NameAndTypeInfo)getItem(iv.nameAndType);
if(n == null)
return null;
return getUtf8Info(n.typeDescriptor);
}
/**
* Reads the <code>bootstrap_method_attr_index</code> field of the
* <code>CONSTANT_Dynamic_info</code> structure
* at the given index.
*
* @since 3.26
*/
public int getDynamicBootstrap(int index)
{
DynamicInfo iv = (DynamicInfo)getItem(index);
return iv.bootstrap;
}
/**
* Reads the <code>name_and_type_index</code> field of the
* <code>CONSTANT_Dynamic_info</code> structure
* at the given index.
*
* @since 3.26
*/
public int getDynamicNameAndType(int index)
{
DynamicInfo iv = (DynamicInfo)getItem(index);
return iv.nameAndType;
}
/**
* Reads the <code>descriptor_index</code> field of the
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
* @param index an index to a <code>CONSTANT_Dynamic_info</code>.
* @return the descriptor of the bootstrap method.
* @since 3.26
*/
public String getDynamicType(int index)
{
DynamicInfo iv = (DynamicInfo)getItem(index);
if (iv == null)
return null;
NameAndTypeInfo n = (NameAndTypeInfo)getItem(iv.nameAndType);
if(n == null)
return null;
return getUtf8Info(n.typeDescriptor);
}
/**
* Reads the <code>name_index</code> field of the
* <code>CONSTANT_Module_info</code> structure at the given index.
*
* @return the module name at <code>name_index</code>.
* @since 3.22
*/
public String getModuleInfo(int index)
{
ModuleInfo mi = (ModuleInfo)getItem(index);
return getUtf8Info(mi.name);
}
/**
* Reads the <code>name_index</code> field of the
* <code>CONSTANT_Package_info</code> structure at the given index.
*
* @return the package name at <code>name_index</code>. It is a slash-
* separated name such as com/oracle/net.
* @since 3.22
*/
public String getPackageInfo(int index)
{
PackageInfo mi = (PackageInfo)getItem(index);
return getUtf8Info(mi.name);
}
/**
* Determines whether <code>CONSTANT_Methodref_info</code>
* structure at the given index represents the constructor
* of the given class.
*
* @return the <code>descriptor_index</code> specifying
* the type descriptor of the that constructor.
* If it is not that constructor,
* <code>isConstructor()</code> returns 0.
*/
public int isConstructor(String classname, int index)
{
return isMember(classname, MethodInfo.nameInit, index);
}
/**
* Determines whether <code>CONSTANT_Methodref_info</code>,
* <code>CONSTANT_Fieldref_info</code>, or
* <code>CONSTANT_InterfaceMethodref_info</code> structure
* at the given index represents the member with the specified
* name and declaring class.
*
* @param classname the class declaring the member
* @param membername the member name
* @param index the index into the constant pool table
*
* @return the <code>descriptor_index</code> specifying
* the type descriptor of that member.
* If it is not that member,
* <code>isMember()</code> returns 0.
*/
public int isMember(String classname, String membername, int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
if (getClassInfo(minfo.classIndex).equals(classname)) {
NameAndTypeInfo ntinfo
= (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
if (getUtf8Info(ntinfo.memberName).equals(membername))
return ntinfo.typeDescriptor;
}
return 0; // false
}
/**
* Determines whether <code>CONSTANT_Methodref_info</code>,
* <code>CONSTANT_Fieldref_info</code>, or
* <code>CONSTANT_InterfaceMethodref_info</code> structure
* at the given index has the name and the descriptor
* given as the arguments.
*
* @param membername the member name
* @param desc the descriptor of the member.
* @param index the index into the constant pool table
*
* @return the name of the target class specified by
* the <code>..._info</code> structure
* at <code>index</code>.
* Otherwise, null if that structure does not
* match the given member name and descriptor.
*/
public String eqMember(String membername, String desc, int index)
{
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
NameAndTypeInfo ntinfo
= (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
if (getUtf8Info(ntinfo.memberName).equals(membername)
&& getUtf8Info(ntinfo.typeDescriptor).equals(desc))
return getClassInfo(minfo.classIndex);
return null; // false
}
private int addItem0(ConstInfo info)
{
items.addElement(info);
return numOfItems++;
}
private int addItem(ConstInfo info)
{
if (itemsCache == null)
itemsCache = makeItemsCache(items);
ConstInfo found = itemsCache.get(info);
if (found != null)
return found.index;
items.addElement(info);
itemsCache.put(info, info);
return numOfItems++;
}
/**
* Copies the n-th item in this ConstPool object into the destination
* ConstPool object.
* The class names that the item refers to are renamed according
* to the given map.
*
* @param n the <i>n</i>-th item
* @param dest destination constant pool table
* @param classnames the map or null.
* @return the index of the copied item into the destination ClassPool.
*/
public int copy(int n, ConstPool dest, Map<String,String> classnames)
{
if (n == 0)
return 0;
ConstInfo info = getItem(n);
return info.copy(this, dest, classnames);
}
int addConstInfoPadding() {
return addItem0(new ConstInfoPadding(numOfItems));
}
/**
* Adds a new <code>CONSTANT_Class_info</code> structure.
*
* <p>This also adds a <code>CONSTANT_Utf8_info</code> structure
* for storing the class name.
*
* @return the index of the added entry.
*/
public int addClassInfo(CtClass c)
{
if (c == THIS)
return thisClassInfo;
else if (!c.isArray())
return addClassInfo(c.getName());
else {
// an array type is recorded in the hashtable with
// the key "[L<classname>;" instead of "<classname>".
//
// note: toJvmName(toJvmName(c)) is equal to toJvmName(c).
return addClassInfo(Descriptor.toJvmName(c));
}
}
/**
* Adds a new <code>CONSTANT_Class_info</code> structure.
*
* <p>This also adds a <code>CONSTANT_Utf8_info</code> structure
* for storing the class name.
*
* @param qname a fully-qualified class name
* (or the JVM-internal representation of that name).
* @return the index of the added entry.
*/
public int addClassInfo(String qname)
{
int utf8 = addUtf8Info(Descriptor.toJvmName(qname));
return addItem(new ClassInfo(utf8, numOfItems));
}
/**
* Adds a new <code>CONSTANT_NameAndType_info</code> structure.
*
* <p>This also adds <code>CONSTANT_Utf8_info</code> structures.
*
* @param name <code>name_index</code>
* @param type <code>descriptor_index</code>
* @return the index of the added entry.
*/
public int addNameAndTypeInfo(String name, String type)
{
return addNameAndTypeInfo(addUtf8Info(name), addUtf8Info(type));
}
/**
* Adds a new <code>CONSTANT_NameAndType_info</code> structure.
*
* @param name <code>name_index</code>
* @param type <code>descriptor_index</code>
* @return the index of the added entry.
*/
public int addNameAndTypeInfo(int name, int type)
{
return addItem(new NameAndTypeInfo(name, type, numOfItems));
}
/**
* Adds a new <code>CONSTANT_Fieldref_info</code> structure.
*
* <p>This also adds a new <code>CONSTANT_NameAndType_info</code>
* structure.
*
* @param classInfo <code>class_index</code>
* @param name <code>name_index</code>
* of <code>CONSTANT_NameAndType_info</code>.
* @param type <code>descriptor_index</code>
* of <code>CONSTANT_NameAndType_info</code>.
* @return the index of the added entry.
*/
public int addFieldrefInfo(int classInfo, String name, String type)
{
int nt = addNameAndTypeInfo(name, type);
return addFieldrefInfo(classInfo, nt);
}
/**
* Adds a new <code>CONSTANT_Fieldref_info</code> structure.
*
* @param classInfo <code>class_index</code>
* @param nameAndTypeInfo <code>name_and_type_index</code>.
* @return the index of the added entry.
*/
public int addFieldrefInfo(int classInfo, int nameAndTypeInfo)
{
return addItem(new FieldrefInfo(classInfo, nameAndTypeInfo,
numOfItems));
}
/**
* Adds a new <code>CONSTANT_Methodref_info</code> structure.
*
* <p>This also adds a new <code>CONSTANT_NameAndType_info</code>
* structure.
*
* @param classInfo <code>class_index</code>
* @param name <code>name_index</code>
* of <code>CONSTANT_NameAndType_info</code>.
* @param type <code>descriptor_index</code>
* of <code>CONSTANT_NameAndType_info</code>.
* @return the index of the added entry.
*/
public int addMethodrefInfo(int classInfo, String name, String type)
{
int nt = addNameAndTypeInfo(name, type);
return addMethodrefInfo(classInfo, nt);
}
/**
* Adds a new <code>CONSTANT_Methodref_info</code> structure.
*
* @param classInfo <code>class_index</code>
* @param nameAndTypeInfo <code>name_and_type_index</code>.
* @return the index of the added entry.
*/
public int addMethodrefInfo(int classInfo, int nameAndTypeInfo)
{
return addItem(new MethodrefInfo(classInfo,
nameAndTypeInfo, numOfItems));
}
/**
* Adds a new <code>CONSTANT_InterfaceMethodref_info</code>
* structure.
*
* <p>This also adds a new <code>CONSTANT_NameAndType_info</code>
* structure.
*
* @param classInfo <code>class_index</code>
* @param name <code>name_index</code>
* of <code>CONSTANT_NameAndType_info</code>.
* @param type <code>descriptor_index</code>
* of <code>CONSTANT_NameAndType_info</code>.
* @return the index of the added entry.
*/
public int addInterfaceMethodrefInfo(int classInfo,
String name,
String type)
{
int nt = addNameAndTypeInfo(name, type);
return addInterfaceMethodrefInfo(classInfo, nt);
}
/**
* Adds a new <code>CONSTANT_InterfaceMethodref_info</code>
* structure.
*
* @param classInfo <code>class_index</code>
* @param nameAndTypeInfo <code>name_and_type_index</code>.
* @return the index of the added entry.
*/
public int addInterfaceMethodrefInfo(int classInfo,
int nameAndTypeInfo)
{
return addItem(new InterfaceMethodrefInfo(classInfo,
nameAndTypeInfo,
numOfItems));
}
/**
* Adds a new <code>CONSTANT_String_info</code>
* structure.
*
* <p>This also adds a new <code>CONSTANT_Utf8_info</code>
* structure.
*
* @return the index of the added entry.
*/
public int addStringInfo(String str)
{
int utf = addUtf8Info(str);
return addItem(new StringInfo(utf, numOfItems));
}
/**
* Adds a new <code>CONSTANT_Integer_info</code>
* structure.
*
* @return the index of the added entry.
*/
public int addIntegerInfo(int i)
{
return addItem(new IntegerInfo(i, numOfItems));
}
/**
* Adds a new <code>CONSTANT_Float_info</code>
* structure.
*
* @return the index of the added entry.
*/
public int addFloatInfo(float f)
{
return addItem(new FloatInfo(f, numOfItems));
}
/**
* Adds a new <code>CONSTANT_Long_info</code>
* structure.
*
* @return the index of the added entry.
*/
public int addLongInfo(long l)
{
int i = addItem(new LongInfo(l, numOfItems));
if (i == numOfItems - 1) // if not existing
addConstInfoPadding();
return i;
}
/**
* Adds a new <code>CONSTANT_Double_info</code>
* structure.
*
* @return the index of the added entry.
*/
public int addDoubleInfo(double d)
{
int i = addItem(new DoubleInfo(d, numOfItems));
if (i == numOfItems - 1) // if not existing
addConstInfoPadding();
return i;
}
/**
* Adds a new <code>CONSTANT_Utf8_info</code>
* structure.
*
* @return the index of the added entry.
*/
public int addUtf8Info(String utf8)
{
return addItem(new Utf8Info(utf8, numOfItems));
}
/**
* Adds a new <code>CONSTANT_MethodHandle_info</code>
* structure.
*
* @param kind <code>reference_kind</code>
* such as {@link #REF_invokeStatic <code>REF_invokeStatic</code>}.
* @param index <code>reference_index</code>.
* @return the index of the added entry.
*
* @since 3.17
*/
public int addMethodHandleInfo(int kind, int index)
{
return addItem(new MethodHandleInfo(kind, index, numOfItems));
}
/**
* Adds a new <code>CONSTANT_MethodType_info</code>
* structure.
*
* @param desc <code>descriptor_index</code>.
* @return the index of the added entry.
*
* @since 3.17
*/
public int addMethodTypeInfo(int desc)
{
return addItem(new MethodTypeInfo(desc, numOfItems));
}
/**
* Adds a new <code>CONSTANT_InvokeDynamic_info</code>
* structure.
*
* @param bootstrap <code>bootstrap_method_attr_index</code>.
* @param nameAndType <code>name_and_type_index</code>.
* @return the index of the added entry.
*
* @since 3.17
*/
public int addInvokeDynamicInfo(int bootstrap, int nameAndType)
{
return addItem(new InvokeDynamicInfo(bootstrap, nameAndType, numOfItems));
}
/**
* Adds a new <code>CONSTANT_Dynamic_info</code> structure.
*
* @param bootstrap <code>bootstrap_method_attr_index</code>.
* @param nameAndType <code>name_and_type_index</code>.
* @return the index of the added entry.
* @since 3.26
*/
public int addDynamicInfo(int bootstrap, int nameAndType) {
return addItem(new DynamicInfo(bootstrap, nameAndType, numOfItems));
}
/**
* Adds a new <code>CONSTANT_Module_info</code>
* @param nameIndex the index of the Utf8 entry.
* @return the index of the added entry.
* @since 3.22
*/
public int addModuleInfo(int nameIndex)
{
return addItem(new ModuleInfo(nameIndex, numOfItems));
}
/**
* Adds a new <code>CONSTANT_Package_info</code>
* @param nameIndex the index of the Utf8 entry.
* @return the index of the added entry.
* @since 3.22
*/
public int addPackageInfo(int nameIndex)
{
return addItem(new PackageInfo(nameIndex, numOfItems));
}
/**
* Get all the class names.
*
* @return a set of class names (<code>String</code> objects).
*/
public Set<String> getClassNames()
{
Set<String> result = new HashSet<String>();
LongVector v = items;
int size = numOfItems;
for (int i = 1; i < size; ++i) {
String className = v.elementAt(i).getClassName(this);
if (className != null)
result.add(className);
}
return result;
}
/**
* Replaces all occurrences of a class name.
*
* @param oldName the replaced name (JVM-internal representation).
* @param newName the substituted name (JVM-internal representation).
*/
public void renameClass(String oldName, String newName)
{
LongVector v = items;
int size = numOfItems;
for (int i = 1; i < size; ++i) {
ConstInfo ci = v.elementAt(i);
ci.renameClass(this, oldName, newName, itemsCache);
}
}
/**
* Replaces all occurrences of class names.
*
* @param classnames specifies pairs of replaced and substituted
* name.
*/
public void renameClass(Map<String,String> classnames)
{
LongVector v = items;
int size = numOfItems;
for (int i = 1; i < size; ++i) {
ConstInfo ci = v.elementAt(i);
ci.renameClass(this, classnames, itemsCache);
}
}
private void read(DataInputStream in) throws IOException
{
int n = in.readUnsignedShort();
items = new LongVector(n);
numOfItems = 0;
addItem0(null); // index 0 is reserved by the JVM.
while (--n > 0) { // index 0 is reserved by JVM
int tag = readOne(in);
if ((tag == LongInfo.tag) || (tag == DoubleInfo.tag)) {
addConstInfoPadding();
--n;
}
}
}
private static Map<ConstInfo,ConstInfo> makeItemsCache(LongVector items)
{
Map<ConstInfo,ConstInfo> cache = new HashMap<ConstInfo,ConstInfo>();
int i = 1;
while (true) {
ConstInfo info = items.elementAt(i++);
if (info == null)
break;
cache.put(info, info);
}
return cache;
}
private int readOne(DataInputStream in) throws IOException
{
ConstInfo info;
int tag = in.readUnsignedByte();
switch (tag) {
case Utf8Info.tag : // 1
info = new Utf8Info(in, numOfItems);
break;
case IntegerInfo.tag : // 3
info = new IntegerInfo(in, numOfItems);
break;
case FloatInfo.tag : // 4
info = new FloatInfo(in, numOfItems);
break;
case LongInfo.tag : // 5
info = new LongInfo(in, numOfItems);
break;
case DoubleInfo.tag : // 6
info = new DoubleInfo(in, numOfItems);
break;
case ClassInfo.tag : // 7
info = new ClassInfo(in, numOfItems);
break;
case StringInfo.tag : // 8
info = new StringInfo(in, numOfItems);
break;
case FieldrefInfo.tag : // 9
info = new FieldrefInfo(in, numOfItems);
break;
case MethodrefInfo.tag : // 10
info = new MethodrefInfo(in, numOfItems);
break;
case InterfaceMethodrefInfo.tag : // 11
info = new InterfaceMethodrefInfo(in, numOfItems);
break;
case NameAndTypeInfo.tag : // 12
info = new NameAndTypeInfo(in, numOfItems);
break;
case MethodHandleInfo.tag : // 15
info = new MethodHandleInfo(in, numOfItems);
break;
case MethodTypeInfo.tag : // 16
info = new MethodTypeInfo(in, numOfItems);
break;
case DynamicInfo.tag : // 17
info = new DynamicInfo(in, numOfItems);
break;
case InvokeDynamicInfo.tag : // 18
info = new InvokeDynamicInfo(in, numOfItems);
break;
case ModuleInfo.tag : // 19
info = new ModuleInfo(in, numOfItems);
break;
case PackageInfo.tag : // 20
info = new PackageInfo(in, numOfItems);
break;
default :
throw new IOException("invalid constant type: "
+ tag + " at " + numOfItems);
}
addItem0(info);
return tag;
}
/**
* Writes the contents of the constant pool table.
*/
public void write(DataOutputStream out) throws IOException
{
out.writeShort(numOfItems);
LongVector v = items;
int size = numOfItems;
for (int i = 1; i < size; ++i)
v.elementAt(i).write(out);
}
/**
* Prints the contents of the constant pool table.
*/
public void print()
{
print(new PrintWriter(System.out, true));
}
/**
* Prints the contents of the constant pool table.
*/
public void print(PrintWriter out)
{
int size = numOfItems;
for (int i = 1; i < size; ++i) {
out.print(i);
out.print(" ");
items.elementAt(i).print(out);
}
}
}
abstract class ConstInfo
{
int index;
public ConstInfo(int i) { index = i; }
public abstract int getTag();
public String getClassName(ConstPool cp) { return null; }
public void renameClass(ConstPool cp, String oldName, String newName,
Map<ConstInfo,ConstInfo> cache) {}
public void renameClass(ConstPool cp, Map<String,String> classnames,
Map<ConstInfo,ConstInfo> cache) {}
public abstract int copy(ConstPool src, ConstPool dest,
Map<String, String> classnames);
// ** classnames is a mapping between JVM names.
public abstract void write(DataOutputStream out) throws IOException;
public abstract void print(PrintWriter out);
@Override
public String toString() {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PrintWriter out = new PrintWriter(bout);
print(out);
return bout.toString();
}
}
/* padding following DoubleInfo or LongInfo.
*/
class ConstInfoPadding extends ConstInfo
{
public ConstInfoPadding(int i) { super(i); }
@Override
public int getTag() { return 0; }
@Override
public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
{
return dest.addConstInfoPadding();
}
@Override
public void write(DataOutputStream out) throws IOException {}
@Override
public void print(PrintWriter out)
{
out.println("padding");
}
}
class ClassInfo extends ConstInfo
{
static final int tag = 7;
int name;
public ClassInfo(int className, int index)
{
super(index);
name = className;
}
public ClassInfo(DataInputStream in, int index) throws IOException
{
super(index);
name = in.readUnsignedShort();
}
@Override
public int hashCode() { return name; }
@Override
public boolean equals(Object obj)
{
return obj instanceof ClassInfo && ((ClassInfo)obj).name == name;
}
@Override
public int getTag() { return tag; }
@Override
public String getClassName(ConstPool cp)
{
return cp.getUtf8Info(name);
}
@Override
public void renameClass(ConstPool cp, String oldName, String newName,
Map<ConstInfo,ConstInfo> cache)
{
String nameStr = cp.getUtf8Info(name);
String newNameStr = null;
if (nameStr.equals(oldName))
newNameStr = newName;
else if (nameStr.charAt(0) == '[') {
String s = Descriptor.rename(nameStr, oldName, newName);
if (nameStr != s)
newNameStr = s;
}
if (newNameStr != null)
if (cache == null)
name = cp.addUtf8Info(newNameStr);
else {
cache.remove(this);
name = cp.addUtf8Info(newNameStr);
cache.put(this, this);
}
}
@Override
public void renameClass(ConstPool cp, Map<String,String> map,
Map<ConstInfo,ConstInfo> cache)
{
String oldName = cp.getUtf8Info(name);
String newName = null;
if (oldName.charAt(0) == '[') {
String s = Descriptor.rename(oldName, map);
if (oldName != s)
newName = s;
}
else {
String s = map.get(oldName);
if (s != null && !s.equals(oldName))
newName = s;
}
if (newName != null) {
if (cache == null)
name = cp.addUtf8Info(newName);
else {
cache.remove(this);
name = cp.addUtf8Info(newName);
cache.put(this, this);
}
}
}
@Override
public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
{
String classname = src.getUtf8Info(name);
if (map != null) {
String newname = map.get(classname);
if (newname != null)
classname = newname;
}
return dest.addClassInfo(classname);
}
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(tag);
out.writeShort(name);
}
@Override
public void print(PrintWriter out)
{
out.print("Class #");
out.println(name);
}
}
class NameAndTypeInfo extends ConstInfo
{
static final int tag = 12;
int memberName;
int typeDescriptor;
public NameAndTypeInfo(int name, int type, int index)
{
super(index);
memberName = name;
typeDescriptor = type;
}
public NameAndTypeInfo(DataInputStream in, int index) throws IOException
{
super(index);
memberName = in.readUnsignedShort();
typeDescriptor = in.readUnsignedShort();
}
@Override
public int hashCode() { return (memberName << 16) ^ typeDescriptor; }
@Override
public boolean equals(Object obj)
{
if (obj instanceof NameAndTypeInfo) {
NameAndTypeInfo nti = (NameAndTypeInfo)obj;
return nti.memberName == memberName
&& nti.typeDescriptor == typeDescriptor;
}
return false;
}
@Override
public int getTag() { return tag; }
@Override
public void renameClass(ConstPool cp, String oldName, String newName,
Map<ConstInfo,ConstInfo> cache)
{
String type = cp.getUtf8Info(typeDescriptor);
String type2 = Descriptor.rename(type, oldName, newName);
if (type != type2)
if (cache == null)
typeDescriptor = cp.addUtf8Info(type2);
else {
cache.remove(this);
typeDescriptor = cp.addUtf8Info(type2);
cache.put(this, this);
}
}
@Override
public void renameClass(ConstPool cp, Map<String,String> map,
Map<ConstInfo,ConstInfo> cache)
{
String type = cp.getUtf8Info(typeDescriptor);
String type2 = Descriptor.rename(type, map);
if (type != type2)
if (cache == null)
typeDescriptor = cp.addUtf8Info(type2);
else {
cache.remove(this);
typeDescriptor = cp.addUtf8Info(type2);
cache.put(this, this);
}
}
@Override
public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
{
String mname = src.getUtf8Info(memberName);
String tdesc = src.getUtf8Info(typeDescriptor);
tdesc = Descriptor.rename(tdesc, map);
return dest.addNameAndTypeInfo(dest.addUtf8Info(mname),
dest.addUtf8Info(tdesc));
}
@Override
public void write(DataOutputStream out) throws IOException {
out.writeByte(tag);
out.writeShort(memberName);
out.writeShort(typeDescriptor);
}
@Override
public void print(PrintWriter out) {
out.print("NameAndType #");
out.print(memberName);
out.print(", type #");
out.println(typeDescriptor);
}
}
abstract class MemberrefInfo extends ConstInfo
{
int classIndex;
int nameAndTypeIndex;
public MemberrefInfo(int cindex, int ntindex, int thisIndex)
{
super(thisIndex);
classIndex = cindex;
nameAndTypeIndex = ntindex;
}
public MemberrefInfo(DataInputStream in, int thisIndex)
throws IOException
{
super(thisIndex);
classIndex = in.readUnsignedShort();
nameAndTypeIndex = in.readUnsignedShort();
}
@Override
public int hashCode() { return (classIndex << 16) ^ nameAndTypeIndex; }
@Override
public boolean equals(Object obj) {
if (obj instanceof MemberrefInfo) {
MemberrefInfo mri = (MemberrefInfo)obj;
return mri.classIndex == classIndex
&& mri.nameAndTypeIndex == nameAndTypeIndex
&& mri.getClass() == this.getClass();
}
return false;
}
@Override
public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
{
int classIndex2 = src.getItem(classIndex).copy(src, dest, map);
int ntIndex2 = src.getItem(nameAndTypeIndex).copy(src, dest, map);
return copy2(dest, classIndex2, ntIndex2);
}
abstract protected int copy2(ConstPool dest, int cindex, int ntindex);
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(getTag());
out.writeShort(classIndex);
out.writeShort(nameAndTypeIndex);
}
@Override
public void print(PrintWriter out)
{
out.print(getTagName() + " #");
out.print(classIndex);
out.print(", name&type #");
out.println(nameAndTypeIndex);
}
public abstract String getTagName();
}
class FieldrefInfo extends MemberrefInfo
{
static final int tag = 9;
public FieldrefInfo(int cindex, int ntindex, int thisIndex)
{
super(cindex, ntindex, thisIndex);
}
public FieldrefInfo(DataInputStream in, int thisIndex)
throws IOException
{
super(in, thisIndex);
}
@Override
public int getTag() { return tag; }
@Override
public String getTagName() { return "Field"; }
@Override
protected int copy2(ConstPool dest, int cindex, int ntindex)
{
return dest.addFieldrefInfo(cindex, ntindex);
}
}
class MethodrefInfo extends MemberrefInfo
{
static final int tag = 10;
public MethodrefInfo(int cindex, int ntindex, int thisIndex)
{
super(cindex, ntindex, thisIndex);
}
public MethodrefInfo(DataInputStream in, int thisIndex)
throws IOException
{
super(in, thisIndex);
}
@Override
public int getTag() { return tag; }
@Override
public String getTagName() { return "Method"; }
@Override
protected int copy2(ConstPool dest, int cindex, int ntindex)
{
return dest.addMethodrefInfo(cindex, ntindex);
}
}
class InterfaceMethodrefInfo extends MemberrefInfo
{
static final int tag = 11;
public InterfaceMethodrefInfo(int cindex, int ntindex, int thisIndex)
{
super(cindex, ntindex, thisIndex);
}
public InterfaceMethodrefInfo(DataInputStream in, int thisIndex)
throws IOException
{
super(in, thisIndex);
}
@Override
public int getTag() { return tag; }
@Override
public String getTagName() { return "Interface"; }
@Override
protected int copy2(ConstPool dest, int cindex, int ntindex)
{
return dest.addInterfaceMethodrefInfo(cindex, ntindex);
}
}
class StringInfo extends ConstInfo
{
static final int tag = 8;
int string;
public StringInfo(int str, int index)
{
super(index);
string = str;
}
public StringInfo(DataInputStream in, int index) throws IOException
{
super(index);
string = in.readUnsignedShort();
}
@Override
public int hashCode() { return string; }
@Override
public boolean equals(Object obj)
{
return obj instanceof StringInfo && ((StringInfo)obj).string == string;
}
@Override
public int getTag() { return tag; }
@Override
public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
{
return dest.addStringInfo(src.getUtf8Info(string));
}
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(tag);
out.writeShort(string);
}
@Override
public void print(PrintWriter out)
{
out.print("String #");
out.println(string);
}
}
class IntegerInfo extends ConstInfo
{
static final int tag = 3;
int value;
public IntegerInfo(int v, int index)
{
super(index);
value = v;
}
public IntegerInfo(DataInputStream in, int index) throws IOException
{
super(index);
value = in.readInt();
}
@Override
public int hashCode() { return value; }
@Override
public boolean equals(Object obj)
{
return obj instanceof IntegerInfo && ((IntegerInfo)obj).value == value;
}
@Override
public int getTag() { return tag; }
@Override
public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
{
return dest.addIntegerInfo(value);
}
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(tag);
out.writeInt(value);
}
@Override
public void print(PrintWriter out)
{
out.print("Integer ");
out.println(value);
}
}
class FloatInfo extends ConstInfo
{
static final int tag = 4;
float value;
public FloatInfo(float f, int index)
{
super(index);
value = f;
}
public FloatInfo(DataInputStream in, int index) throws IOException
{
super(index);
value = in.readFloat();
}
@Override
public int hashCode() { return Float.floatToIntBits(value); }
@Override
public boolean equals(Object obj)
{
return obj instanceof FloatInfo && ((FloatInfo)obj).value == value;
}
@Override
public int getTag() { return tag; }
@Override
public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
{
return dest.addFloatInfo(value);
}
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(tag);
out.writeFloat(value);
}
@Override
public void print(PrintWriter out)
{
out.print("Float ");
out.println(value);
}
}
class LongInfo extends ConstInfo
{
static final int tag = 5;
long value;
public LongInfo(long l, int index)
{
super(index);
value = l;
}
public LongInfo(DataInputStream in, int index) throws IOException
{
super(index);
value = in.readLong();
}
@Override
public int hashCode() { return (int)(value ^ (value >>> 32)); }
@Override
public boolean equals(Object obj) {
return obj instanceof LongInfo && ((LongInfo)obj).value == value;
}
@Override
public int getTag() { return tag; }
@Override
public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
{
return dest.addLongInfo(value);
}
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(tag);
out.writeLong(value);
}
@Override
public void print(PrintWriter out)
{
out.print("Long ");
out.println(value);
}
}
class DoubleInfo extends ConstInfo
{
static final int tag = 6;
double value;
public DoubleInfo(double d, int index)
{
super(index);
value = d;
}
public DoubleInfo(DataInputStream in, int index) throws IOException
{
super(index);
value = in.readDouble();
}
@Override
public int hashCode() {
long v = Double.doubleToLongBits(value);
return (int)(v ^ (v >>> 32));
}
@Override
public boolean equals(Object obj)
{
return obj instanceof DoubleInfo
&& ((DoubleInfo)obj).value == value;
}
@Override
public int getTag() { return tag; }
@Override
public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
{
return dest.addDoubleInfo(value);
}
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(tag);
out.writeDouble(value);
}
@Override
public void print(PrintWriter out)
{
out.print("Double ");
out.println(value);
}
}
class Utf8Info extends ConstInfo
{
static final int tag = 1;
String string;
public Utf8Info(String utf8, int index)
{
super(index);
string = utf8;
}
public Utf8Info(DataInputStream in, int index)
throws IOException
{
super(index);
string = in.readUTF();
}
@Override
public int hashCode() {
return string.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof Utf8Info
&& ((Utf8Info)obj).string.equals(string);
}
@Override
public int getTag() { return tag; }
@Override
public int copy(ConstPool src, ConstPool dest,
Map<String,String> map)
{
return dest.addUtf8Info(string);
}
@Override
public void write(DataOutputStream out)
throws IOException
{
out.writeByte(tag);
out.writeUTF(string);
}
@Override
public void print(PrintWriter out) {
out.print("UTF8 \"");
out.print(string);
out.println("\"");
}
}
class MethodHandleInfo extends ConstInfo {
static final int tag = 15;
int refKind, refIndex;
public MethodHandleInfo(int kind, int referenceIndex, int index) {
super(index);
refKind = kind;
refIndex = referenceIndex;
}
public MethodHandleInfo(DataInputStream in, int index)
throws IOException
{
super(index);
refKind = in.readUnsignedByte();
refIndex = in.readUnsignedShort();
}
@Override
public int hashCode() { return (refKind << 16) ^ refIndex; }
@Override
public boolean equals(Object obj)
{
if (obj instanceof MethodHandleInfo) {
MethodHandleInfo mh = (MethodHandleInfo)obj;
return mh.refKind == refKind && mh.refIndex == refIndex;
}
return false;
}
@Override
public int getTag() { return tag; }
@Override
public int copy(ConstPool src, ConstPool dest,
Map<String,String> map)
{
return dest.addMethodHandleInfo(refKind,
src.getItem(refIndex).copy(src, dest, map));
}
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(tag);
out.writeByte(refKind);
out.writeShort(refIndex);
}
@Override
public void print(PrintWriter out) {
out.print("MethodHandle #");
out.print(refKind);
out.print(", index #");
out.println(refIndex);
}
}
class MethodTypeInfo extends ConstInfo
{
static final int tag = 16;
int descriptor;
public MethodTypeInfo(int desc, int index)
{
super(index);
descriptor = desc;
}
public MethodTypeInfo(DataInputStream in, int index)
throws IOException
{
super(index);
descriptor = in.readUnsignedShort();
}
@Override
public int hashCode() { return descriptor; }
@Override
public boolean equals(Object obj)
{
if (obj instanceof MethodTypeInfo)
return ((MethodTypeInfo)obj).descriptor == descriptor;
return false;
}
@Override
public int getTag() { return tag; }
@Override
public void renameClass(ConstPool cp, String oldName, String newName,
Map<ConstInfo,ConstInfo> cache)
{
String desc = cp.getUtf8Info(descriptor);
String desc2 = Descriptor.rename(desc, oldName, newName);
if (desc != desc2)
if (cache == null)
descriptor = cp.addUtf8Info(desc2);
else {
cache.remove(this);
descriptor = cp.addUtf8Info(desc2);
cache.put(this, this);
}
}
@Override
public void renameClass(ConstPool cp, Map<String,String> map,
Map<ConstInfo,ConstInfo> cache)
{
String desc = cp.getUtf8Info(descriptor);
String desc2 = Descriptor.rename(desc, map);
if (desc != desc2)
if (cache == null)
descriptor = cp.addUtf8Info(desc2);
else {
cache.remove(this);
descriptor = cp.addUtf8Info(desc2);
cache.put(this, this);
}
}
@Override
public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
{
String desc = src.getUtf8Info(descriptor);
desc = Descriptor.rename(desc, map);
return dest.addMethodTypeInfo(dest.addUtf8Info(desc));
}
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(tag);
out.writeShort(descriptor);
}
@Override
public void print(PrintWriter out) {
out.print("MethodType #");
out.println(descriptor);
}
}
class InvokeDynamicInfo extends ConstInfo
{
static final int tag = 18;
int bootstrap, nameAndType;
public InvokeDynamicInfo(int bootstrapMethod,
int ntIndex, int index)
{
super(index);
bootstrap = bootstrapMethod;
nameAndType = ntIndex;
}
public InvokeDynamicInfo(DataInputStream in, int index)
throws IOException
{
super(index);
bootstrap = in.readUnsignedShort();
nameAndType = in.readUnsignedShort();
}
@Override
public int hashCode() { return (bootstrap << 16) ^ nameAndType; }
@Override
public boolean equals(Object obj)
{
if (obj instanceof InvokeDynamicInfo) {
InvokeDynamicInfo iv = (InvokeDynamicInfo)obj;
return iv.bootstrap == bootstrap
&& iv.nameAndType == nameAndType;
}
return false;
}
@Override
public int getTag() { return tag; }
@Override
public int copy(ConstPool src, ConstPool dest,
Map<String,String> map)
{
return dest.addInvokeDynamicInfo(bootstrap,
src.getItem(nameAndType).copy(src, dest, map));
}
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(tag);
out.writeShort(bootstrap);
out.writeShort(nameAndType);
}
@Override
public void print(PrintWriter out) {
out.print("InvokeDynamic #");
out.print(bootstrap);
out.print(", name&type #");
out.println(nameAndType);
}
}
class DynamicInfo extends ConstInfo {
static final int tag = 17;
int bootstrap, nameAndType;
public DynamicInfo(int bootstrapMethod, int ntIndex, int index) {
super(index);
bootstrap = bootstrapMethod;
nameAndType = ntIndex;
}
public DynamicInfo(DataInputStream in, int index) throws IOException {
super(index);
bootstrap = in.readUnsignedShort();
nameAndType = in.readUnsignedShort();
}
@Override
public int hashCode() {
return (bootstrap << 16) ^ nameAndType;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof DynamicInfo) {
DynamicInfo iv = (DynamicInfo)obj;
return iv.bootstrap == bootstrap && iv.nameAndType == nameAndType;
}
return false;
}
@Override
public int getTag() {
return tag;
}
@Override
public int copy(ConstPool src, ConstPool dest, Map<String, String> map) {
return dest.addDynamicInfo(bootstrap, src.getItem(nameAndType).copy(src, dest, map));
}
@Override
public void write(DataOutputStream out) throws IOException {
out.writeByte(tag);
out.writeShort(bootstrap);
out.writeShort(nameAndType);
}
@Override
public void print(PrintWriter out) {
out.print("Dynamic #");
out.print(bootstrap);
out.print(", name&type #");
out.println(nameAndType);
}
}
class ModuleInfo extends ConstInfo
{
static final int tag = 19;
int name;
public ModuleInfo(int moduleName, int index)
{
super(index);
name = moduleName;
}
public ModuleInfo(DataInputStream in, int index)
throws IOException
{
super(index);
name = in.readUnsignedShort();
}
@Override
public int hashCode() { return name; }
@Override
public boolean equals(Object obj)
{
return obj instanceof ModuleInfo
&& ((ModuleInfo)obj).name == name;
}
@Override
public int getTag() { return tag; }
public String getModuleName(ConstPool cp)
{
return cp.getUtf8Info(name);
}
@Override
public int copy(ConstPool src, ConstPool dest,
Map<String,String> map)
{
String moduleName = src.getUtf8Info(name);
int newName = dest.addUtf8Info(moduleName);
return dest.addModuleInfo(newName);
}
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(tag);
out.writeShort(name);
}
@Override
public void print(PrintWriter out) {
out.print("Module #");
out.println(name);
}
}
class PackageInfo extends ConstInfo
{
static final int tag = 20;
int name;
public PackageInfo(int moduleName, int index)
{
super(index);
name = moduleName;
}
public PackageInfo(DataInputStream in, int index)
throws IOException
{
super(index);
name = in.readUnsignedShort();
}
@Override
public int hashCode() { return name; }
@Override
public boolean equals(Object obj) {
return obj instanceof PackageInfo
&& ((PackageInfo)obj).name == name;
}
@Override
public int getTag() { return tag; }
public String getPackageName(ConstPool cp)
{
return cp.getUtf8Info(name);
}
@Override
public int copy(ConstPool src, ConstPool dest,
Map<String,String> map)
{
String packageName = src.getUtf8Info(name);
int newName = dest.addUtf8Info(packageName);
return dest.addModuleInfo(newName);
}
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(tag);
out.writeShort(name);
}
@Override
public void print(PrintWriter out)
{
out.print("Package #");
out.println(name);
}
}
|