Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4a8587c514a9041ce3f51c3fae972c4b2d9fb79a (plain) (blame)
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
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
/*******************************************************************************
 * Copyright (c) 2000, 2018 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Stephan Herrmann - contribution for Bug 300576 - NPE Computing type hierarchy when compliance doesn't match libraries
 *     Jesper S Moller - contributions for bug 393192 - Incomplete type hierarchy with > 10 annotations
 *******************************************************************************/
package org.eclipse.jdt.core.tests.model;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;

import junit.framework.Test;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IOrdinaryClassFile;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IRegion;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.tests.model.SearchTests.WaitingJob;
import org.eclipse.jdt.core.tests.model.Semaphore.TimeOutException;
import org.eclipse.jdt.core.tests.util.Util;

@SuppressWarnings("rawtypes")
public class TypeHierarchyTests extends ModifyingResourceTests {
	/**
	 * A placeholder for a type hierarchy used in some test cases.
	 */
	ITypeHierarchy typeHierarchy;

static {
//	TESTS_NAMES= new String[] { "testBug329663a" };
}
public static Test suite() {
	return buildModelTestSuite(TypeHierarchyTests.class, BYTECODE_DECLARATION_ORDER);
}
public TypeHierarchyTests(String name) {
	super(name);
	this.displayName = true;
}

/* (non-Javadoc)
 * @see org.eclipse.jdt.core.tests.model.AbstractJavaModelTests#setUpSuite()
 */
public void setUpSuite() throws Exception {
	super.setUpSuite();

	setUpJavaProject("TypeHierarchy");
	addLibrary("myLib.jar", "myLibsrc.zip", new String[] {
		"my/pkg/X.java",
		"package my.pkg;\n" +
		"public class X {\n" +
		"}",
		"my/pkg/Y.java",
		"package my.pkg;\n" +
		"public class Y {\n" +
		"  void foo() {\n" +
		"    new X() {};" +
		"  }\n" +
		"}",
	}, JavaCore.VERSION_1_4);

	IPackageFragmentRoot root = this.currentProject.getPackageFragmentRoot(this.currentProject.getProject().getFile("lib.jar"));
	IRegion region = JavaCore.newRegion();
	region.add(root);
	this.typeHierarchy = this.currentProject.newTypeHierarchy(region, null);

	IJavaProject project15 = createJavaProject("TypeHierarchy15", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5");
	addLibrary(project15, "lib15.jar", "lib15src.zip", new String[] {
		"util/AbstractList.java",
		"package util;\n" +
		"public class AbstractList<E> {\n" +
		"}",
		"util/ArrayList.java",
		"package util;\n" +
		"public class ArrayList<E> extends AbstractList<E> implements List<E> {\n" +
		"}",
		"util/List.java",
		"package util;\n" +
		"public interface List<E> {\n" +
		"}",
		"util/Map.java",
		"package util;\n" +
		"public class Map<K,V> extends AbstractList<V> {\n" +
		"}",
	}, JavaCore.VERSION_1_5);
	createFile(
		"/TypeHierarchy15/src/X.java",
		"import util.*;\n" +
		"public class X<E> extends ArrayList<E> implements List<E> {\n" +
		"}"
	);
	createFile(
		"/TypeHierarchy15/src/Y.java",
		"import util.*;\n" +
		"public class Y extends ArrayList implements List {\n" +
		"}"
	);
	createFile(
		"/TypeHierarchy15/src/I.java",
		"public interface I<E> {\n" +
		"}"
	);
	createFile(
		"/TypeHierarchy15/src/A.java",
		"public class A<E> implements I<E> {\n" +
		"}"
	);
	createFile(
		"/TypeHierarchy15/src/X99606.java",
		"public class X99606 extends Y99606<X99606.Color> {\n" +
		"	static class Color {}\n" +
		"}"
	);
	createFile(
		"/TypeHierarchy15/src/Y99606.java",
		"public class Y99606<T> {\n" +
		"}"
	);
	createFile(
		"/TypeHierarchy15/src/A108740.java",
		"class A108740<T> {}"
	);
	createFile(
		"/TypeHierarchy15/src/B108740.java",
		"class B108740<T> extends A108740<C108740> {}"
	);
	createFile(
		"/TypeHierarchy15/src/C108740.java",
		"class C108740 extends B108740<C108740> {}"
	);
	createFile(
		"/TypeHierarchy15/src/D108740.java",
		"class D108740 extends B108740<D108740> {}"
	);
	createFile(
		"/TypeHierarchy15/src/CycleParent.java",
		"class CycleParent extends CycleBase<CycleChild> {}"
	);
	createFile(
		"/TypeHierarchy15/src/CycleBase.java",
		"class CycleBase<T extends CycleBase> {}"
	);
	createFile(
		"/TypeHierarchy15/src/CycleChild.java",
		"class CycleChild extends CycleParent implements Comparable<CycleChild> {\n" +
		"	public int compareTo(CycleChild o) { return 0; }\n" +
		"}"
	);
	createFile(
		"/TypeHierarchy15/src/Try.java",
		"public enum Try {\n" +
		"    THIS,\n" +
		"    THAT(),\n" +
		"    ANONYMOUS() {}\n" +
		"}"
	);

}

/* (non-Javadoc)
 * @see org.eclipse.jdt.core.tests.model.SuiteOfTestCases#tearDownSuite()
 */
public void tearDownSuite() throws Exception {
	this.typeHierarchy = null;
	deleteProject("TypeHierarchy");
	deleteProject("TypeHierarchy15");

	super.tearDownSuite();
}
/*
 * Ensures that a hierarchy on an anonymous type in an initializer is correct.
 */
public void testAnonymousType01() throws JavaModelException {
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
	IType type = typeA.getInitializer(1).getType("", 1);
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: <anonymous #1> [in <initializer #1> [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"Super types:\n" +
		"  X [in X.java [in p7 [in src [in TypeHierarchy]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}
/*
 * Ensures that a hierarchy on an anonymous type in a second initializer is correct.
 */
public void testAnonymousType02() throws JavaModelException {
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
	IType type = typeA.getInitializer(2).getType("", 1);
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: <anonymous #1> [in <initializer #2> [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"Super types:\n" +
		"  X [in X.java [in p7 [in src [in TypeHierarchy]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}
/*
 * Ensures that a hierarchy on an anonymous type in a field declaration is correct.
 */
public void testAnonymousType03() throws JavaModelException {
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
	IType type = typeA.getField("field1").getType("", 1);
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: <anonymous #1> [in field1 [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"Super types:\n" +
		"  X [in X.java [in p7 [in src [in TypeHierarchy]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}
/*
 * Ensures that a hierarchy on an anonymous type in a field declaration is correct.
 */
public void testAnonymousType04() throws JavaModelException {
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
	IType type = typeA.getField("field2").getType("", 1);
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: <anonymous #1> [in field2 [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"Super types:\n" +
		"  X [in X.java [in p7 [in src [in TypeHierarchy]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
	type = typeA.getField("field2").getType("", 2);
	hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: <anonymous #2> [in field2 [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"Super types:\n" +
		"  X [in X.java [in p7 [in src [in TypeHierarchy]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}
/*
 * Ensures that a hierarchy on an anonymous type in a method declaration is correct.
 */
public void testAnonymousType05() throws JavaModelException {
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
	IType type = typeA.getMethod("foo", new String[] {}).getType("", 1);
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: <anonymous #1> [in foo() [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"Super types:\n" +
		"  X [in X.java [in p7 [in src [in TypeHierarchy]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}
/*
 * Ensures that a hierarchy on an anonymous type that uses a non-default constructor is correct.
 * (regression test for bug 44506 Type hierarchy is missing anonymous type)
 */
public void testAnonymousType06() throws JavaModelException {
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p8", "X.java").getType("X");
	IType type = typeA.getMethod("foo", new String[] {}).getType("", 1);
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: <anonymous #1> [in foo() [in X [in X.java [in p8 [in src [in TypeHierarchy]]]]]]\n" +
		"Super types:\n" +
		"  X [in X.java [in p8 [in src [in TypeHierarchy]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}
/*
 * Ensure that the key of an anonymous binary type in a hierarchy is correct.
 * (regression test for bug 93826 ArrayIndexOutOfBoundsException when opening type hierarchy)
 */
public void testAnonymousType07() throws CoreException {
	IType type = getClassFile("TypeHierarchy","myLib.jar", "my.pkg", "X.class").getType();
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] subtypes = hierarchy.getSubtypes(type);
	assertEquals("Unexpected key", "Lmy/pkg/Y$1;", subtypes.length < 1 ? null : subtypes[0].getKey());
}
/*
 * Ensure that hierarchy on an enum also include the anonymous of its enum contants
 * (regression test for bug 120667 [hierarchy] Type hierarchy for enum type does not include anonymous subtypes)
 */
public void testAnonymousType08() throws CoreException {
	IType type = getCompilationUnit("TypeHierarchy15/src/Try.java").getType("Try");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: Try [in Try.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"Super types:\n" +
		"  Enum [in Enum.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"    Comparable [in Comparable.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"    Serializable [in Serializable.class [in java.io [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"Sub types:\n" +
		"  <anonymous #1> [in ANONYMOUS [in Try [in Try.java [in <default> [in src [in TypeHierarchy15]]]]]]\n",
		hierarchy);
}
/*
 * Ensure that hierarchy on the anonymous type of an enum constant is correct
 * (regression test for bug 120667 [hierarchy] Type hierarchy for enum type does not include anonymous subtypes)
 */
public void testAnonymousType09() throws CoreException {
	IType type = getCompilationUnit("TypeHierarchy15/src/Try.java").getType("Try").getField("ANONYMOUS").getType("", 1);
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: <anonymous #1> [in ANONYMOUS [in Try [in Try.java [in <default> [in src [in TypeHierarchy15]]]]]]\n" +
		"Super types:\n" +
		"  Try [in Try.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"    Enum [in Enum.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"      Comparable [in Comparable.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"      Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"      Serializable [in Serializable.class [in java.io [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}
/*
 * Ensure that hierarchy on the anonymous type of a member type that is opened is correct
 * (regression test for bug 122444 [hierarchy] Type hierarchy of inner member type misses anonymous subtypes)
 */
public void testAnonymousType10() throws CoreException {
	ICompilationUnit cu =  getCompilationUnit("TypeHierarchy/src/q7/X.java");
	cu.open(null);
	IType type = cu.getType("X").getType("Member");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: Member [in X [in X.java [in q7 [in src [in TypeHierarchy]]]]]\n" +
		"Super types:\n" +
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n" +
		"  <anonymous #1> [in foo(X) [in Y [in X.java [in q7 [in src [in TypeHierarchy]]]]]]\n",
		hierarchy);
}
/*
 * Ensure that hierarchy contains an anonymous type as a subclass of the focus type,
 * if the anonymous type is created with a message send to a third type as an argument to
 * the constructor.
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=210070)
 */
public void testAnonymousType11() throws CoreException {
	IType type = getCompilationUnit("TypeHierarchy/src/q8/Y210070.java").getType("Y210070");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: Y210070 [in Y210070.java [in q8 [in src [in TypeHierarchy]]]]\n" +
		"Super types:\n" +
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n" +
		"  <anonymous #1> [in foo(X210070) [in Z210070 [in Z210070.java [in q8 [in src [in TypeHierarchy]]]]]]\n",
		hierarchy);
}
/*
 * Ensure that hierarchy contains an anonymous type as a subclass of the focus type,
 * if the anonymous type is created with a problem in its constructor call.
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=210070)
 */
public void testAnonymousType12() throws CoreException {
	IType type = getCompilationUnit("TypeHierarchy/src/q8/A210070.java").getType("A210070");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: A210070 [in A210070.java [in q8 [in src [in TypeHierarchy]]]]\n" +
		"Super types:\n" +
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n" +
		"  <anonymous #1> [in foo() [in A210070 [in A210070.java [in q8 [in src [in TypeHierarchy]]]]]]\n",
		hierarchy);
}/**
 * Ensures that the superclass can be retrieved for a binary inner type.
 */
public void testBinaryInnerTypeGetSuperclass() throws JavaModelException {
	IOrdinaryClassFile cf = getClassFile("TypeHierarchy", "lib.jar", "binary", "Y$Inner.class");
	IType type = cf.getType();
	ITypeHierarchy h = type.newSupertypeHierarchy(null);
	IType superclass = h.getSuperclass(type);
	assertTrue("Superclass not found for Y$Inner", superclass != null);
	assertEquals("Unexpected super class", "Z", superclass.getElementName());
}
/**
 * Ensures that the superinterfaces can be retrieved for a binary inner type.
 */
public void testBinaryInnerTypeGetSuperInterfaces() throws JavaModelException {
	IOrdinaryClassFile cf = getClassFile("TypeHierarchy", "lib.jar", "binary", "Y$Inner.class");
	IType type = cf.getType();
	ITypeHierarchy h = type.newSupertypeHierarchy(null);
	assertTypesEqual(
		"Unexpected super interfaces",
		"binary.I\n",
		h.getSuperInterfaces(type));
}
/*
 * Ensures that the hierarchy lookup mechanism get the right binary if it is missplaced.
 * (regression test for bug 139279 Fup of bug 134110, got CCE changing an external jar contents and refreshing the project)
 */
public void testBinaryInWrongPackage() throws CoreException {
	try {
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL_LIB", "lib"}, "bin");
		createFolder("/P/src/p");
		createFile(
			"/P/src/p/X.java",
			"pakage p;\n" +
			"public class X {\n" +
			"}"
		);
		getProject("P").build(IncrementalProjectBuilder.FULL_BUILD, null);
		waitForAutoBuild();
		getFile("/P/bin/p/X.class").copy(new Path("/P/lib/X.class"), false, null);
		ITypeHierarchy hierarchy = getClassFile("P", "/P/lib", "", "X.class").getType().newSupertypeHierarchy(null);
		assertHierarchyEquals(
			"Focus: X [in X.class [in <default> [in lib [in P]]]]\n" +
			"Super types:\n" +
			"Sub types:\n",
			hierarchy);
	} finally {
		deleteProject("P");
	}
}
/*
 * Ensures that a hierarchy with a binary subclass that is also referenced can be computed
 * (regression test for bug 48459 NPE in Type hierarchy)
 */
public  void testBinarySubclass() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy/src/p48459/p1/X48459.java").getType("X48459");
	ITypeHierarchy h = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: X48459 [in X48459.java [in p48459.p1 [in src [in TypeHierarchy]]]]\n" +
		"Super types:\n" +
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n" +
		"  <anonymous #1> [in foo [in Z48459 [in Z48459.java [in p48459.p1 [in src [in TypeHierarchy]]]]]]\n" +
		"  Y48459 [in Y48459.class [in p48459.p2 [in lib48459 [in TypeHierarchy]]]]\n",
		h);
}
/**
 * Ensures that the superclass can be retrieved for a binary type's superclass.
 */
public void testBinaryTypeGetSuperclass() throws JavaModelException {
	IOrdinaryClassFile cf = getClassFile("TypeHierarchy", "lib.jar", "binary", "Y.class");
	IType type = cf.getType();
	ITypeHierarchy h= type.newSupertypeHierarchy(null);
	IType superclass= h.getSuperclass(type);
	assertTrue("Superclass not found forY", superclass != null);
	assertEquals("Unexpected superclass of Y", "X", superclass.getElementName());
}
/**
 * Ensures that the superclass can be retrieved for a binary type's superclass.
 * This is a relatively deep type hierarchy.
 */
public void testBinaryTypeGetSuperclass2() throws JavaModelException {
	IOrdinaryClassFile cf = getClassFile("TypeHierarchy", "lib.jar", "binary", "Deep.class");
	IType type = cf.getType();
	ITypeHierarchy h= type.newSupertypeHierarchy(null);
	IType superclass= h.getSuperclass(type);
	assertTrue("Superclass not found for Deep", superclass != null);
	assertEquals("Unexpected superclass of Deep", "Z", superclass.getElementName());
}
/**
 * Ensures that the superinterfaces can be retrieved for a binary type's superinterfaces.
 */
public void testBinaryTypeGetSuperInterfaces() throws JavaModelException {
	IOrdinaryClassFile cf = getClassFile("TypeHierarchy", "lib.jar", "binary", "X.class");
	IType type = cf.getType();
	ITypeHierarchy h = type.newSupertypeHierarchy(null);
	IType[] superInterfaces = h.getSuperInterfaces(type);
	assertTypesEqual(
		"Unexpected super interfaces of X",
		"binary.I\n",
		superInterfaces);
}
/**
 * Ensures that the superinterfaces can be retrieved for a binary type's superinterfaces.
 * Test with type that has a "rich" super hierarchy
 */
public void testBinaryTypeGetSuperInterfaces2() throws JavaModelException {
	IOrdinaryClassFile cf = getClassFile("TypeHierarchy", "lib.jar", "rich", "C.class");
	IType type = cf.getType();
	ITypeHierarchy h = type.newSupertypeHierarchy(null);
	IType[] superInterfaces = h.getSuperInterfaces(type);
	assertTypesEqual(
		"Unexpected super interfaces of C",
		"rich.I\n" +
		"rich.I3\n",
		superInterfaces);
}
/*
 * Ensures that a hierarchy can be constructed on a binary type in a jar that is hidden by another jar with the same type.
 * (regression test for bug
 */
public void testBinaryTypeHiddenByOtherJar() throws CoreException, IOException {
	String externalJar1 = null;
	String externalJar2 = null;
	try {
		externalJar1 = Util.getOutputDirectory() + File.separator + "test1.jar";
		Util.createJar(
			new String[] {
				"p/X.java",
				"package p;\n" +
				"public class X {\n" +
				"}" ,
				"p/Y.java",
				"package p;\n" +
				"public class Y extends X {\n" +
				"}"
			},
			new HashMap(),
			externalJar1
		);
		externalJar2 = Util.getOutputDirectory() + File.separator + "test2.jar";
		Util.createJar(
			new String[] {
				"p/X.java",
				"package p;\n" +
				"public class X {\n" +
				"}" ,
				"p/Y.java",
				"package p;\n" +
				"public class Y extends X {\n" +
				"}"
			},
			new HashMap(),
			externalJar2
		);
		IJavaProject project = createJavaProject("P", new String[] {}, new String[] {"JCL_LIB", externalJar1, externalJar2}, "");
		IType focus = project.getPackageFragmentRoot(externalJar2).getPackageFragment("p").getOrdinaryClassFile("Y.class").getType();
		assertHierarchyEquals(
			"Focus: Y [in Y.class [in p [in " + externalJar2 + "]]]\n" +
			"Super types:\n" +
			"  X [in X.class [in p [in " + externalJar1 + "]]]\n" +
			"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"Sub types:\n",
			focus.newTypeHierarchy(null)
		);
	} finally {
		if (externalJar1 != null)
			Util.delete(externalJar1);
		if (externalJar2 != null)
			Util.delete(externalJar2);
		deleteProject("P");
	}
}
/*
 * Ensures that a hierarchy can be constructed on a binary type in a jar that has '.class' in its name.
 * (regression test for bug 157035 "Open Type Hierarchy" fails if subtype is anonymous or local class and location for this subtype contains ".class")
 */
public void testBinaryTypeInDotClassJar() throws CoreException, IOException {
	String externalJar = null;
	try {
		externalJar = Util.getOutputDirectory() + File.separator + "test.classic.jar";
		Util.createJar(
			new String[] {
				"p/X.java",
				"package p;\n" +
				"public class X {\n" +
				"}" ,
				"p/Y.java",
				"package p;\n" +
				"public class Y {\n" +
				"  void foo() {\n" +
				"    new X() {\n" +
				"    };\n" +
				" }\n" +
				"}"
			},
			new HashMap(),
			externalJar
		);
		IJavaProject project = createJavaProject("P", new String[] {}, new String[] {"JCL_LIB", externalJar}, "");
		IType focus = project.getPackageFragmentRoot(externalJar).getPackageFragment("p").getOrdinaryClassFile("X.class").getType();
		assertHierarchyEquals(
			"Focus: X [in X.class [in p [in " + externalJar + "]]]\n" +
			"Super types:\n" +
			"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"Sub types:\n" +
			"  <anonymous> [in Y$1.class [in p [in " + externalJar + "]]]\n",
			focus.newTypeHierarchy(null)
		);
	} finally {
		if (externalJar != null)
			Util.delete(externalJar);
		deleteProject("P");
	}
}
/**
 * Ensures that the creation of a type hierarchy can be cancelled.
 */
public void testCancel() throws JavaModelException {
	boolean isCanceled = false;
	IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "X.java").getType("X");
	IRegion region = JavaCore.newRegion();
	region.add(getPackageFragmentRoot("TypeHierarchy", "src"));
	try {
		TestProgressMonitor monitor = TestProgressMonitor.getInstance();
		monitor.setCancelledCounter(1);
		type.getJavaProject().newTypeHierarchy(type, region, monitor);
	} catch (OperationCanceledException e) {
		isCanceled = true;
	}
	assertTrue("Operation should have thrown an operation canceled exception", isCanceled);
}
/**
 * Ensures that contains(...) returns true for a type that is part of the
 * hierarchy and false otherwise.
 */
public void testContains1() throws JavaModelException {
	// regular class
	IType type = getClassFile("TypeHierarchy", "lib.jar", "binary", "X.class").getType();
	assertTrue("X must be included", this.typeHierarchy.contains(type));
}
public void testContains2() throws JavaModelException {
	// root class
	IType type = getClassFile("TypeHierarchy", getExternalJCLPathString(), "java.lang", "Object.class").getType();
	assertTrue("Object must be included", this.typeHierarchy.contains(type));
}
public void testContains3() throws JavaModelException {
	// interface
	IType type = getClassFile("TypeHierarchy", "lib.jar", "binary", "I.class").getType();
	assertTrue("I must be included", this.typeHierarchy.contains(type));
}
public void testCycle() throws JavaModelException {
	IType type = getCompilationUnit("/TypeHierarchy/src/cycle/X.java").getType("X");
	ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: X [in X.java [in cycle [in src [in TypeHierarchy]]]]\n" +
		"Super types:\n" +
		"  Y [in Y.java [in cycle [in src [in TypeHierarchy]]]]\n" +
		"Sub types:\n",
		hierarchy
	);
}
public void testCycle2() throws JavaModelException {
	IType type = getCompilationUnit("/TypeHierarchy15/src/CycleParent.java").getType("CycleParent");
	ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: CycleParent [in CycleParent.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"Super types:\n" +
		"  CycleBase [in CycleBase.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"Sub types:\n",
		hierarchy
	);
}
/*
 * Ensures that creating a type hierarchy accross multiple project checks for cancellation regularly.
 */
public void testEfficiencyMultipleProjects() throws CoreException {
	try {
		createJavaProject("P1", new String[] {""}, new String[] {"JCL_LIB"}, "");
		createJavaProject("P2", new String[] {""}, new String[] {"JCL_LIB"}, new String[] {"/P1"}, "");
		createJavaProject("P3", new String[] {""}, new String[] {"JCL_LIB"}, new String[] {"/P1"}, "");
		createFile("/P1/X.java", "public class X {}");
		createFile("/P3/Y.java", "public class Y extends X {}");
		createFile("/P3/Z.java", "public class Z extends X {}");
		createFile("/P2/W.java", "public class W extends X {}");
		waitUntilIndexesReady();
		IType type = getCompilationUnit("/P1/X.java").getType("X");
		class ProgressCounter extends TestProgressMonitor {
			int count = 0;
			public boolean isCanceled() {
				this.count++;
				return false;
			}
		}
		ProgressCounter counter = new ProgressCounter();
		type.newTypeHierarchy(counter);
		assertTrue("Not enough cancellation checks", counter.count >= 85); 
	} finally {
		deleteProjects(new String[] {"P1", "P2", "P3"});
	}
}
/*
 * Ensures that a hierarchy can be created with a potential subtype in an empty primary working copy
 * (regression test for bug 65677 Creating hierarchy failed. See log for details. 0)
 */
public void testEmptyWorkingCopyPotentialSubtype() throws JavaModelException {
    ICompilationUnit workingCopy = null;
    try {
        workingCopy = getCompilationUnit("/TypeHierarchy/src/q4/Y.java");
        workingCopy.becomeWorkingCopy(null);
        workingCopy.getBuffer().setContents("");
        workingCopy.makeConsistent(null);

        IType type = getCompilationUnit("/TypeHierarchy/src/q4/X.java").getType("X");
		ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
		assertHierarchyEquals(
			"Focus: X [in X.java [in q4 [in src [in TypeHierarchy]]]]\n" +
			"Super types:\n" +
			"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"Sub types:\n",
			hierarchy);
    } finally {
        if (workingCopy != null)
            workingCopy.discardWorkingCopy();
    }
}
/*
 * Ensures that subtypes are found in an external library folder
 */
public void testExternalFolder() throws CoreException, IOException {
	try {
		createExternalFolder("externalLib");
		Util.compile(
			new String[] {
				"p/X.java",
				"package p;\n" +
				"public class X {\n" +
				"}",
				"p/Y.java",
				"package p;\n" +
				"public class Y extends X {\n" +
				"}",
			},
			new HashMap(),
			getExternalResourcePath("externalLib"));
		createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
		IOrdinaryClassFile classFile = getClassFile("P", getExternalResourcePath("externalLib"), "p", "X.class");
		ITypeHierarchy hierarchy = classFile.getType().newTypeHierarchy(null);
		assertHierarchyEquals(
			"Focus: X [in X.class [in p [in "+ getExternalPath() + "externalLib]]]\n" +
			"Super types:\n" +
			"Sub types:\n" +
			"  Y [in Y.class [in p [in "+ getExternalPath() + "externalLib]]]\n",
			hierarchy);
	} finally {
		deleteProject("P");
		deleteExternalResource("externalLib");
	}
}
/*
 * Ensures that subtypes are found in an external ZIP archive
 */
public void testZIPArchive() throws CoreException, IOException {
	try {
		createJar(
			new String[] {
				"p/X.java",
				"package p;\n" +
				"public class X {\n" +
				"}",
				"p/Y.java",
				"package p;\n" +
				"public class Y extends X {\n" +
				"}",
			},
			getExternalResourcePath("externalLib.abc"));
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
		refreshExternalArchives(p);

		IOrdinaryClassFile classFile = getClassFile("P", getExternalResourcePath("externalLib.abc"), "p", "X.class");
		ITypeHierarchy hierarchy = classFile.getType().newTypeHierarchy(null);
		assertHierarchyEquals(
			"Focus: X [in X.class [in p [in "+ getExternalPath() + "externalLib.abc]]]\n" +
			"Super types:\n" +
			"Sub types:\n" +
			"  Y [in Y.class [in p [in "+ getExternalPath() + "externalLib.abc]]]\n",
			hierarchy);
	} finally {
		deleteExternalResource("externalLib.abc");
		deleteProject("P");
	}
}
/*
 * Ensures that a call to IJavaProject.findType("java.lang.Object") doesn't cause the hierarchy
 * computation to throw a StackOverFlow
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=209222)
 */
public void testFindObject() throws CoreException {
	// ensure Object.class is closed
	this.currentProject.getPackageFragmentRoot(getExternalJCLPathString()).getPackageFragment("java.lang").getOrdinaryClassFile("Object.class").close();
	// find Object to fill internal jar type cache
	IType type = this.currentProject.findType("java.lang.Object");
	// create hierarchy
	type.newTypeHierarchy(null); // should not throw a StackOverFlow
}
/*
 * Ensures that a hierarchy on a type with local and anonymous types is correct.
 */
public void testFocusWithLocalAndAnonymousTypes() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p7", "X.java").getType("X");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: X [in X.java [in p7 [in src [in TypeHierarchy]]]]\n" +
		"Super types:\n" +
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n" +
		"  <anonymous #1> [in <initializer #2> [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"  <anonymous #1> [in field1 [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"  <anonymous #1> [in field2 [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"  <anonymous #1> [in foo() [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"  <anonymous #1> [in <initializer #1> [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"  <anonymous #2> [in field2 [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"  Y1 [in foo() [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"    Y2 [in foo() [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"  Y1 [in <initializer #1> [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"    Y2 [in <initializer #1> [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n",
		hierarchy);
}
/*
 * Ensures that a hierarchy on a generic type can be opened
 */
public void testGeneric01() throws JavaModelException {
	IType type = getCompilationUnit("/TypeHierarchy15/src/X.java").getType("X");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: X [in X.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"Super types:\n" +
		"  ArrayList [in ArrayList.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"    AbstractList [in AbstractList.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"      Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"    List [in List.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"  List [in List.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"Sub types:\n",
		hierarchy
	);
}
/*
 * Ensures that a hierarchy on a generic type can be opened
 */
public void testGeneric02() throws JavaModelException {
	IType type = getPackageFragmentRoot("/TypeHierarchy15/lib15.jar").getPackageFragment("util").getOrdinaryClassFile("ArrayList.class").getType();
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: ArrayList [in ArrayList.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"Super types:\n" +
		"  AbstractList [in AbstractList.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"  List [in List.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"Sub types:\n" +
		"  X [in X.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"  Y [in Y.java [in <default> [in src [in TypeHierarchy15]]]]\n",
		hierarchy
	);
}
/*
 * Ensures that a hierarchy on a generic type can be opened
 */
public void testGeneric03() throws JavaModelException {
	IType type = getCompilationUnit("/TypeHierarchy15/src/Y.java").getType("Y");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: Y [in Y.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"Super types:\n" +
		"  ArrayList [in ArrayList.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"    AbstractList [in AbstractList.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"      Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"    List [in List.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"  List [in List.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"Sub types:\n",
		hierarchy
	);
}
/*
 * Ensures that a super type hierarchy on a generic type can be opened
 * (regression test for bug 72348 [1.5][Type Hierarchy] Super type hierarchy of class extending generic type is empty)
 */
public void testGeneric04() throws JavaModelException {
	IType type = getCompilationUnit("/TypeHierarchy15/src/X.java").getType("X");
	ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: X [in X.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"Super types:\n" +
		"  ArrayList [in ArrayList.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"    AbstractList [in AbstractList.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"      Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"    List [in List.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"  List [in List.class [in util [in lib15.jar [in TypeHierarchy15]]]]\n" +
		"Sub types:\n",
		hierarchy
	);
}
/*
 * Ensures that a hierarchy on a generic interface can be opened
 * (regression test for bug 82004 [model][5.0] 3.1M4 type hierarchy for generic interface)
 */
public void testGeneric05() throws JavaModelException {
	IType type = getCompilationUnit("/TypeHierarchy15/src/I.java").getType("I");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: I [in I.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"Super types:\n" +
		"Sub types:\n" +
		"  A [in A.java [in <default> [in src [in TypeHierarchy15]]]]\n",
		hierarchy
	);
}
/*
 * Ensure that the key of a binary type in a hierarchy is correct when this type is not part of the Java model cache.
 * (regression test for bug 93854 IAE in Util.scanTypeSignature when scanning a signature retrieved from a binding key)
 */
public void testGeneric06() throws CoreException {
	getJavaProject("TypeHierarcht15").close();
	IType type = getClassFile("TypeHierarchy15","lib15.jar", "util", "AbstractList.class").getType();
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] subtypes = hierarchy.getSubtypes(type);
	assertEquals("Unexpected key", "Lutil/Map<TK;TV;>;", subtypes.length < 2 ? null : subtypes[1].getKey());
}
/*
 * Ensures that a hierarchy on a generic type that is extended using a member as a type parameter can be opened
 * (regression test for bug 99606 Subtype not found if parameterized on inner class)
 */
public void testGeneric07() throws JavaModelException {
	IType type = getCompilationUnit("/TypeHierarchy15/src/Y99606.java").getType("Y99606");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: Y99606 [in Y99606.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"Super types:\n" +
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"Sub types:\n" +
		"  X99606 [in X99606.java [in <default> [in src [in TypeHierarchy15]]]]\n",
		hierarchy
	);
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=108740
public void testGeneric08() throws JavaModelException {
	IType type = getCompilationUnit("/TypeHierarchy15/src/D108740.java").getType("D108740");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: D108740 [in D108740.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"Super types:\n" +
		"  B108740 [in B108740.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"    A108740 [in A108740.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
		"      Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
		"Sub types:\n",
		hierarchy
	);
}
/*
 * Ensures that a hierarchy is where a type inherits conflicting paratemerized types is still correctly reported
 * (regression test for bug 136095 Type Hierarchy incomplete with illegally parameterized superinterfaces)
 */
public void testGeneric09() throws CoreException {
	try {
		createFile(
			"/TypeHierarchy15/src/I1_136095.java",
			"public interface I1_136095<E> {\n" +
			"}"
		);
		createFile(
			"/TypeHierarchy15/src/I2_136095.java",
			"public interface I2_136095 extends I1_136095<String>{\n" +
			"}"
		);
		createFile(
			"/TypeHierarchy15/src/X_136095.java",
			"public abstract class X_136095 implements I1_136095<Integer>, I2_136095 {\n" +
			"}"
		);
		IType type = getCompilationUnit("/TypeHierarchy15/src/X_136095.java").getType("X_136095");
		ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
		assertHierarchyEquals(
			"Focus: X_136095 [in X_136095.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
			"Super types:\n" +
			"  I1_136095 [in I1_136095.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
			"  I2_136095 [in I2_136095.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
			"    I1_136095 [in I1_136095.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
			"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
			"Sub types:\n",
			hierarchy
		);
	} finally {
		deleteFile("/TypeHierarchy15/src/I1_136095.java");
		deleteFile("/TypeHierarchy15/src/I2_136095.java");
		deleteFile("/TypeHierarchy15/src/X_136095.java");
	}
}
/*
 * Ensures that a super type hierarchy is where the focus type implements a generic type with a qualified type parameter is correct
 * (regression test for bug 140340 [5.0][templates] foreach template does not work when an Iterable over a static inner class exists)
 */
public void testGeneric10() throws CoreException {
	try {
		createFile(
			"/TypeHierarchy15/src/Y_140340.java",
			"public class Y_140340 {\n" +
			"  public static class Z {\n" +
			"  }\n" +
			"}"
		);
		createFile(
			"/TypeHierarchy15/src/X_140340.java",
			"public class X_140340 implements I1_140340<Y_140340.Z> {\n" +
			"}\n" +
			"interface I1_140340<T> {\n" +
			"}"
		);
		IType type = getCompilationUnit("/TypeHierarchy15/src/X_140340.java").getType("X_140340");
		ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
		assertHierarchyEquals(
			"Focus: X_140340 [in X_140340.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
			"Super types:\n" +
			"  I1_140340 [in X_140340.java [in <default> [in src [in TypeHierarchy15]]]]\n" +
			"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
			"Sub types:\n",
			hierarchy
		);
	} finally {
		deleteFile("/TypeHierarchy15/src/Y_140340.java");
		deleteFile("/TypeHierarchy15/src/X_140340.java");
	}
}
/*
 * Ensures that no cycle is created in a hierarchy with 2 types with same simple names and errors
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=215681 )
 */
public void testGeneric11() throws CoreException {
	try {
		createFolder("/TypeHierarchy15/src/p215681");
		createFile(
			"/TypeHierarchy15/src/p215681/A_215681.java",
			"package p215681;\r\n" +
			"public class A_215681<E> {\n" +
			"}"
		);
		createFolder("/TypeHierarchy15/src/q215681");
		createFile(
			"/TypeHierarchy15/src/q215681/A_215681.java",
			"package q215681;\n" +
			"import p215681.A_215681;\n" +
			"public class A_215681 extends A_215681<Object> {\n" +
			"}"
		);
		IType type = getCompilationUnit("/TypeHierarchy15/src/q215681/A_215681.java").getType("A_215681");
		ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
		assertHierarchyEquals(
			"Focus: A_215681 [in A_215681.java [in q215681 [in src [in TypeHierarchy15]]]]\n" +
			"Super types:\n" +
			"Sub types:\n",
			hierarchy
		);
	} finally {
		deleteFolder("/TypeHierarchy15/src/p215681");
		deleteFolder("/TypeHierarchy15/src/q215681");
	}
}
/*
 * Ensures that no cycle is created in a hierarchy with 2 types with same simple names and errors
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=215681 )
 */
public void testGeneric12() throws CoreException {
	try {
		createFolder("/TypeHierarchy15/src/p215681");
		createFile(
			"/TypeHierarchy15/src/p215681/A_215681.java",
			"package p215681;\r\n" +
			"public interface A_215681<E> {\n" +
			"}"
		);
		createFolder("/TypeHierarchy15/src/q215681");
		createFile(
			"/TypeHierarchy15/src/q215681/A_215681.java",
			"package q215681;\n" +
			"import p215681.A_215681;\n" +
			"public interface A_215681 extends A_215681<Object> {\n" +
			"}"
		);
		IType type = getCompilationUnit("/TypeHierarchy15/src/q215681/A_215681.java").getType("A_215681");
		ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
		assertHierarchyEquals(
			"Focus: A_215681 [in A_215681.java [in q215681 [in src [in TypeHierarchy15]]]]\n" +
			"Super types:\n" +
			"Sub types:\n",
			hierarchy
		);
	} finally {
		deleteFolder("/TypeHierarchy15/src/p215681");
		deleteFolder("/TypeHierarchy15/src/q215681");
	}
}
/**
 * Ensures the correctness of all classes in a type hierarchy based on a region.
 */
public void testGetAllClassesInRegion() {
	IType[] types = this.typeHierarchy.getAllClasses();
	assertTypesEqual(
		"Unexpected all classes in hierarchy",
		"binary.Deep\n" +
		"binary.X\n" +
		"binary.Y\n" +
		"binary.Y$Inner\n" +
		"binary.Z\n" +
		"java.lang.Object\n" +
		"rich.A\n" +
		"rich.B\n" +
		"rich.C\n",
		types);
}
/**
 * Ensures the correctness of all interfaces in a type hierarchy based on a region.
 */
public void testGetAllInterfacesInRegion() {
	IType[] types = this.typeHierarchy.getAllInterfaces();
	assertTypesEqual(
		"Unexpected all interfaces in hierarchy",
		"binary.I\n" +
		"rich.I\n" +
		"rich.I2\n" +
		"rich.I3\n",
		types);
}
/**
 * Ensures that the correct subtypes of a type exist in the type
 * hierarchy.
 */
public void testGetAllSubtypes() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "X.java").getType("X");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] types = hierarchy.getAllSubtypes(type);
	this.assertTypesEqual(
		"Unexpected sub types of X",
		"p1.Deep\n" +
		"p1.Y\n" +
		"p1.Z\n",
		types
	);
}
/**
 * Ensures that the correct subtypes of a binary type
 * exit in the type hierarchy created on a region.
 */
public void testGetAllSubtypesFromBinary() throws JavaModelException {
	IType type = getClassFile("TypeHierarchy", "lib.jar", "binary", "X.class").getType();
	IRegion region = JavaCore.newRegion();
	region.add(type.getPackageFragment());
	ITypeHierarchy hierarchy = type.getJavaProject().newTypeHierarchy(type, region, null);
	IType[] types = hierarchy.getAllSubtypes(type);
	assertTypesEqual(
		"Unexpected all subtypes of binary.X",
		"binary.Deep\n" +
		"binary.Y\n" +
		"binary.Y$Inner\n" +
		"binary.Z\n",
		types);
}

/**
 * Ensures that the correct superclasses of a type exist in the type
 * hierarchy.
 */
public void testGetAllSuperclasses() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "Z.java").getType("Z");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] types = hierarchy.getAllSuperclasses(type);
	assertTypesEqual(
		"Unexpected all super classes of Z",
		"java.lang.Object\n" +
		"p1.X\n" +
		"p1.Y\n",
		types);
}

/**
 * Ensures that the correct superclasses of a binary type exist in the type  hierarchy.
 * (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=53095)
 */
public void testGetAllSuperclassesFromBinary() throws JavaModelException {
	String fileName = "TypeHierarchy/lib53095/p53095/X53095.class";	//$NON-NLS-1$
	IJavaElement javaElement = JavaCore.create(getFile(fileName));
	assertNotNull("Problem to get class file \""+fileName+"\"", javaElement);
	assertTrue("Invalid type for class file \""+fileName+"\"", javaElement instanceof IClassFile);
	IType type = ((IOrdinaryClassFile) javaElement).getType();
	ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null); // it works when we use newTypeHierarchy(null)
	IType[] types = hierarchy.getAllSupertypes(type);
	assertTypesEqual(
		"Unexpected all super classes of X53095",
		"java.lang.RuntimeException\n" +
		"java.lang.Exception\n" +
		"java.lang.Throwable\n" +
		"java.lang.Object\n",
		types,
		false);
}

/**
 * Ensures that the correct superclasses of a binary type exist in the type  hierarchy.
 * (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=54043)
 */
public void testGetAllSuperclassesFromBinary2() throws JavaModelException {
	IOrdinaryClassFile cf = getClassFile("TypeHierarchy", "test54043.jar", "p54043", "X54043.class");
	IType type = cf.getType();
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] types = hierarchy.getAllSupertypes(type);
	assertTypesEqual(
		"Unexpected all super classes of X54043",
		"java.lang.RuntimeException\n" +
		"java.lang.Exception\n" +
		"java.lang.Throwable\n" +
		"java.lang.Object\n",
		types,
		false);
}
/**
 * Ensures that the correct superinterfaces of a type exist in the type
 * hierarchy.
 */
public void testGetAllSuperInterfaces() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "Z.java").getType("Z");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] types = hierarchy.getAllSuperInterfaces(type);
	assertTypesEqual(
		"Unexpected super interfaces of Z",
		"p1.I1\n" +
		"p1.I2\n",
		types);
}
/**
 * Ensures that the correct supertypes of a type exist in the type
 * hierarchy.
 */
public void testGetAllSupertypes() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "Z.java").getType("Z");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] types = hierarchy.getAllSupertypes(type);
	assertTypesEqual(
		"Unexpected all super types of Z",
		"java.lang.Object\n" +
		"p1.I1\n" +
		"p1.I2\n" +
		"p1.X\n" +
		"p1.Y\n",
		types);
}
/**
 * Ensures that the correct supertypes of a type exist in the type
 * hierarchy.
 * (regression test for bug 23644 hierarchy: getAllSuperTypes does not include all superinterfaces?)
 */
public void testGetAllSupertypes2() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p3", "B.java").getType("B");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] types = hierarchy.getAllSupertypes(type);
	assertTypesEqual(
		"Unexpected all super types of B",
		"java.lang.Object\n" +
		"p3.A\n" +
		"p3.I\n" +
		"p3.I1\n",
		types);
}
/**
 * Ensures that the correct supertypes of a type exist in the type
 * hierarchy.
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=239096 )
 */
public void testGetAllSupertypes3() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "A.java").getType("B");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] types = hierarchy.getAllSupertypes(type);
	assertTypesEqual(
		"Unexpected all super types of B",
		"java.lang.Object\n",
		types);
}
/**
 * Ensures that the correct supertypes of a type exist in the type
 * hierarchy.
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=239096 )
 */
public void testGetAllSupertypes4() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "A.java").getType("B");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] types = hierarchy.getAllSuperInterfaces(type);
	assertTypesEqual(
		"Unexpected all super interfaces of B",
		"",
		types);
}
/**
 * Ensures that the correct types exist in the type
 * hierarchy.
 */
public void testGetAllTypes() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "Y.java").getType("Y");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	this.assertTypesEqual(
		"Unexpected types in hierarchy of Y",
		"java.lang.Object\n" +
		"p1.Deep\n" +
		"p1.I1\n" +
		"p1.I2\n" +
		"p1.X\n" +
		"p1.Y\n" +
		"p1.Z\n",
		hierarchy.getAllTypes()
	);
}
/**
 * Ensures that the flags for an interface hierarchy are correctly cached
 * (regression test for bug 60365 hierarchy view shows some interfaces as classes [type hierarchy])
 */
public void testGetCachedFlags() throws JavaModelException {
	IType type1 = getClassFile("TypeHierarchy", "test60365.jar", "q4", "I1.class").getType();
	ITypeHierarchy hierarchy = type1.newTypeHierarchy(null);
	IType type2 = getClassFile("TypeHierarchy", "test60365.jar", "q4", "I2.class").getType();
	int flags = hierarchy.getCachedFlags(type2);
	assertTrue("Cached flags for I2 should indicate interface", Flags.isInterface(flags));
}
/**
 * Ensures that the correct extending interfaces exist in the type
 * hierarchy.
 */
public void testGetExtendingInterfaces() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p2", "I.java").getType("I");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] types = hierarchy.getExtendingInterfaces(type);
	this.assertTypesEqual(
		"Unexpected extending interfaces of I",
		"p2.I1\n" +
		"p2.I2\n",
		types
	);

	type = getCompilationUnit("TypeHierarchy", "src", "p2", "X.java").getType("X");
	hierarchy = type.newTypeHierarchy(null);
	types = hierarchy.getExtendingInterfaces(type);
	this.assertTypesEqual(
		"Unexpected extending interfaces of X",
		"", // interfaces cannot extend a class
		types
	);
}
/**
 * Ensures that the correct implementing interfaces exist in the type
 * hierarchy.
 */
public void testGetImplementingClasses() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p2", "I.java").getType("I");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] types = hierarchy.getImplementingClasses(type);
	this.assertTypesEqual(
		"Unexpected implementing classes of I",
		"p2.X\n",
		types
	);

	type = getCompilationUnit("TypeHierarchy", "src", "p2", "X.java").getType("X");
	hierarchy = type.newTypeHierarchy(null);
	types = hierarchy.getImplementingClasses(type);
	this.assertTypesEqual(
		"Unexpected implementing classes of X",
		"", // classes cannot implement a class
		types
	);
}
/**
 * Ensures that the correct root classes exist in the type
 * hierarchy.
 */
public void testGetRootClasses() {
	IType[] types = this.typeHierarchy.getRootClasses();
	assertTypesEqual(
		"Unexpected root classes",
		"java.lang.Object\n",
		types);
}
/**
 * Ensures that the correct root interfaces exist in the type
 * hierarchy.
 */
public void testGetRootInterfaces() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p2", "Y.java").getType("Y");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	IType[] types = hierarchy.getRootInterfaces();
	assertTypesEqual(
		"Unexpected root classes",
		"p2.I\n",
		types);
}
/**
 * Ensures that getRootInterfaces() works on a IRegion.
 */
public void testGetRootInterfacesFromRegion() {
	IType[] types = this.typeHierarchy.getRootInterfaces();
	assertTypesEqual(
		"Unexpected root classes",
		"binary.I\n" +
		"rich.I\n" +
		"rich.I3\n",
		types);
}
/**
 * Ensures that the correct number of subclasses exist in the type
 * hierarchy created on a region.
 */
public void testGetSubclasses() throws JavaModelException {
	IType type = getClassFile("TypeHierarchy", "lib.jar", "binary", "X.class").getType();
	IType[] types = this.typeHierarchy.getSubclasses(type);
	this.assertTypesEqual(
		"Unexpected subclasses of binary.X",
		"binary.Y\n",
		types
	);

	type = getClassFile("TypeHierarchy", "lib.jar", "binary", "I.class").getType();
	types = this.typeHierarchy.getSubclasses(type);
	this.assertTypesEqual(
		"Unexpected subclasses of binary.I",
		"", // interfaces cannot have a subclass
		types
	);
}
/**
 * Ensures that the correct number of subtypes exist in the type
 * hierarchy created on a region.
 */
public void testGetSubtypes() throws JavaModelException {
	IType type = getClassFile("TypeHierarchy", "lib.jar", "binary", "X.class").getType();
	IType[] types = this.typeHierarchy.getSubtypes(type);
	this.assertTypesEqual(
		"Unexpected subtypes of binary.X",
		"binary.Y\n",
		types
	);

	type = getClassFile("TypeHierarchy", "lib.jar", "binary", "I.class").getType();
	types = this.typeHierarchy.getSubtypes(type);
	this.assertTypesEqual(
		"Unexpected subtypes of binary.I",
		"binary.X\n" +
		"binary.Y$Inner\n",
		types
	);
}

/**
 * Ensures that the superclass is correct in the type
 * hierarchy a type created on a region containing a package.
 */
public void testGetSuperclassInRegion() throws JavaModelException {
	IRegion r = JavaCore.newRegion();
	IPackageFragment p = getPackageFragment("TypeHierarchy", "src", "p1");
	r.add(p);
	ITypeHierarchy hierarchy = p.getJavaProject().newTypeHierarchy(r, null);

	IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "Y.java").getType("Y");
	IType superclass= hierarchy.getSuperclass(type);
	assertEquals("Unexpected super class of Y", "X", superclass.getElementName());
}
/**
 * Ensures that the correct supertypes exist in the type
 * hierarchy created on a region.
 */
public void testGetSupertypesInRegion() throws JavaModelException {
	IType type = getClassFile("TypeHierarchy", "lib.jar", "binary", "Y.class").getType();
	IType[] superTypes = this.typeHierarchy.getSupertypes(type);
	assertTypesEqual(
		"Unexpected super types of Y",
		"binary.X\n",
		superTypes);
}
/**
 * Ensures that the correct supertypes exist in the type
 * hierarchy created on a region containing a project.
 */
public void testGetSupertypesWithProjectRegion() throws JavaModelException {
	IJavaProject project = getJavaProject("TypeHierarchy");
	IRegion region= JavaCore.newRegion();
	region.add(project);
	IType type = getClassFile("TypeHierarchy", "lib.jar", "binary", "Y.class").getType();
	ITypeHierarchy hierarchy = project.newTypeHierarchy(type, region, null);
	IType[] superTypes = hierarchy.getSupertypes(type);
	assertTypesEqual(
		"Unexpected super types of Y",
		"binary.X\n",
		superTypes);
}
/**
 * Ensures that getType() returns the type the hierarchy was created for.
 */
public void testGetType() throws JavaModelException {
	// hierarchy created on a type
	IOrdinaryClassFile cf = getClassFile("TypeHierarchy", "lib.jar", "binary", "Y.class");
	IType type = cf.getType();
	ITypeHierarchy hierarchy = null;
	try {
		hierarchy = type.newSupertypeHierarchy(null);
	} catch (IllegalArgumentException iae) {
		assertTrue("IllegalArgumentException", false);
	}
	assertEquals("Unexpected focus type", type, hierarchy.getType());

	// hierarchy created on a region
	assertTrue("Unexpected focus type for hierarchy on region", this.typeHierarchy.getType() == null);
}
/*
 * Ensures that a hierarchy on an type that implements a binary inner interface is correct.
 * (regression test for bug 58440 type hierarchy incomplete when implementing fully qualified interface)
 */
public void testImplementBinaryInnerInterface() throws JavaModelException {
	IOrdinaryClassFile cf = getClassFile("TypeHierarchy", "test58440.jar", "p58440", "Y.class");
	IType type = cf.getType();
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: Y [in Y.class [in p58440 [in test58440.jar [in TypeHierarchy]]]]\n" +
		"Super types:\n" +
		"  Inner [in X$Inner.class [in p58440 [in test58440.jar [in TypeHierarchy]]]]\n" +
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}
/**
 * Ensures that a hierarchy on an inner type is correctly rooted.
 */
public void testInnerType1() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p5", "X.java").getType("X").getType("Inner");
	ITypeHierarchy hierarchy = null;
	try {
		hierarchy = type.newTypeHierarchy(null);
	} catch (IllegalArgumentException iae) {
		assertTrue("IllegalArgumentException", false);
	}
	assertHierarchyEquals(
		"Focus: Inner [in X [in X.java [in p5 [in src [in TypeHierarchy]]]]]\n" +
		"Super types:\n" +
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}


/**
 * Ensures that a hierarchy on an inner type has the correct subtype.
 * (regression test for bug 43274 Type hierarchy broken)
 */
public void testInnerType2() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p6", "A.java").getType("A").getType("Inner");
	ITypeHierarchy hierarchy = null;
	try {
		hierarchy = type.newTypeHierarchy(null);
	} catch (IllegalArgumentException iae) {
		assertTrue("IllegalArgumentException", false);
	}
	assertHierarchyEquals(
		"Focus: Inner [in A [in A.java [in p6 [in src [in TypeHierarchy]]]]]\n" +
		"Super types:\n" +
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n" +
		"  B [in A.java [in p6 [in src [in TypeHierarchy]]]]\n",
		hierarchy);
}
/*
 * Ensures that a hierarchy on a local type in an initializer is correct.
 */
public void testLocalType1() throws JavaModelException {
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
	IType type = typeA.getInitializer(1).getType("Y1", 1);
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: Y1 [in <initializer #1> [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"Super types:\n" +
		"  X [in X.java [in p7 [in src [in TypeHierarchy]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n" +
		"  Y2 [in <initializer #1> [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n",
		hierarchy);
}
/*
 * Ensures that a hierarchy on a local type in a second initializer is correct.
 */
public void testLocalType2() throws JavaModelException {
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
	IType type = typeA.getInitializer(2).getType("Y3", 1);
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: Y3 [in <initializer #2> [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"Super types:\n" +
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}
/*
 * Ensures that a hierarchy on a local type in a method declaration is correct.
 */
public void testLocalType3() throws JavaModelException {
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
	IType type = typeA.getMethod("foo", new String[] {}).getType("Y2", 1);
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: Y2 [in foo() [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"Super types:\n" +
		"  Y1 [in foo() [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"    X [in X.java [in p7 [in src [in TypeHierarchy]]]]\n" +
		"      Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}
/*
 * Ensures that a super type hierarchy on a local type in a method declaration is correct.
 * (regression test for bug 44073 Override methods action does not work for local types [code manipulation])
 */
public void testLocalType4() throws JavaModelException {
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
	IType type = typeA.getMethod("foo", new String[] {}).getType("Y1", 1);
	ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: Y1 [in foo() [in A [in A.java [in p7 [in src [in TypeHierarchy]]]]]]\n" +
		"Super types:\n" +
		"  X [in X.java [in p7 [in src [in TypeHierarchy]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}
/*
 * Ensures that a super type hierarchy on a local type in a method declaration with an error is correct.
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=210498 )
 */
public void testLocalType5() throws JavaModelException {
	IType typeX = getCompilationUnit("TypeHierarchy", "src", "q9", "X.java").getType("X");
	IType type = typeX.getMethod("foo", new String[] {}).getType("Local", 1);
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertTypesEqual(
		"Unexpected types in hierarchy",
		"java.lang.Object\n" +
		"q9.X\n" +
		"q9.X$Local\n",
		hierarchy.getAllTypes());
}
/*
 * Ensures that a type hierarchy on a member type with subtypes in another project is correct
 * (regression test for bug 101019 RC3: Type Hierarchy does not find implementers/extenders of inner class/interface in other project)
 */
public void testMemberTypeSubtypeDifferentProject() throws CoreException {
	try {
		createJavaProject("P1");
		createFile(
			"/P1/X.java",
			"public class X {\n" +
			"  public class Member {\n" +
			"  }\n" +
			"}"
			);
		createJavaProject("P2", new String[] {""}, new String[] {"JCL_LIB"}, new String[] {"/P1"}, "");
		createFile(
			"/P2/Y.java",
			"public class Y extends X.Member {\n" +
			"}"
		);
		IType focus = getCompilationUnit("/P1/X.java").getType("X").getType("Member");
		ITypeHierarchy hierarchy = focus.newTypeHierarchy(null/*no progress*/);
		assertHierarchyEquals(
			"Focus: Member [in X [in X.java [in <default> [in <project root> [in P1]]]]]\n" +
			"Super types:\n" +
			"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"Sub types:\n" +
			"  Y [in Y.java [in <default> [in <project root> [in P2]]]]\n",
			hierarchy);
	} finally {
		deleteProjects(new String[] {"P1", "P2"});
	}
}
/**
 * Ensures that a hierarchy on a type that implements a missing interface is correctly rooted.
 * (regression test for bug 24691 Missing interface makes hierarchy incomplete)
 */
public void testMissingInterface() throws JavaModelException {
	IType type = getCompilationUnit("TypeHierarchy", "src", "p4", "X.java").getType("X");
	ITypeHierarchy hierarchy = null;
	try {
		hierarchy = type.newTypeHierarchy(null);
	} catch (IllegalArgumentException iae) {
		assertTrue("IllegalArgumentException", false);
	}
	assertHierarchyEquals(
		"Focus: X [in X.java [in p4 [in src [in TypeHierarchy]]]]\n" +
		"Super types:\n" +
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}
/*
 * Ensures that a hierarchy on a binary type that extends a missing class with only binary types in the project
 * is correct.
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=213249 )
 */
public void testMissingBinarySuperclass1() throws Exception {
	try {
		IJavaProject project = createJavaProject("P", new String[0], "bin");
		addClassFolder(project, "lib", new String[] {
			"p/X213249.java",
			"package p;\n" +
			"public class X213249 {\n" +
			"}",
			"p/Y213249.java",
			"package p;\n" +
			"public class Y213249 extends X213249 {\n" +
			"}",
			"p/Z213249.java",
			"package p;\n" +
			"public class Z213249 extends Y213249 {\n" +
			"}",
		}, "1.4");
		deleteFile("/P/lib/p/X213249.class");
		IType type = getClassFile("/P/lib/p/Z213249.class").getType();
		ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
		assertHierarchyEquals(
			"Focus: Z213249 [in Z213249.class [in p [in lib [in P]]]]\n" +
			"Super types:\n" +
			"  Y213249 [in Y213249.class [in p [in lib [in P]]]]\n" +
			"Sub types:\n",
			hierarchy);
	} finally {
		deleteProject("P");
	}
}
/*
 * Ensures that a hierarchy on a binary type that extends a missing class with only binary types in the project
 * is correct.
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=213249 )
 */
public void testMissingBinarySuperclass2() throws Exception {
	try {
		IJavaProject project = createJavaProject("P", new String[0], "bin");
		addClassFolder(project, "lib", new String[] {
			"p/X213249.java",
			"package p;\n" +
			"public class X213249 {\n" +
			"}",
			"p/Y213249.java",
			"package p;\n" +
			"public class Y213249 extends X213249 {\n" +
			"}",
			"p/Z213249.java",
			"package p;\n" +
			"public class Z213249 extends Y213249 {\n" +
			"}",
		}, "1.4");
		deleteFile("/P/lib/p/X213249.class");
		IType type = getClassFile("/P/lib/p/Z213249.class").getType();
		ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
		assertHierarchyEquals(
			"Focus: Z213249 [in Z213249.class [in p [in lib [in P]]]]\n" +
			"Super types:\n" +
			"  Y213249 [in Y213249.class [in p [in lib [in P]]]]\n" +
			"Sub types:\n",
			hierarchy);
	} finally {
		deleteProject("P");
	}
}
/*
 * Ensures that a potential subtype in a dependent project doesn't appear in the hierarchy
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=169678 )
 */
public void testPotentialSubtypeInDependentProject() throws Exception {
	try {
		createJavaProject("P1", new String[] {""}, new String[] {"JCL_LIB"}, "");
		createFolder("/P1/p1");
		createFile(
			"/P1/p1/X169678.java",
			"package p1;\n" +
			"public class X169678 {\n" +
			"  public static class Y169678 {\n" +
			"  }\n" +
			"}"
		);
		createFile(
			"/P1/p1/Z169678.java",
			"package p1;\n" +
			"public class Z169678 extends X169678.Y169678 {\n" +
			"}"
		);
		createJavaProject("P2", new String[] {""}, new String[] {"JCL_LIB"}, new String[] {"/P1"}, "");
		createFolder("/P2/p2");
		createFile(
			"/P2/p2/Y169678.java",
			"package p2;\n" +
			"public class Y169678 {\n" +
			"}\n" +
			"class Z169678 extends Y169678 {\n" +
			"}"
		);
		IType type = getCompilationUnit("/P1/p1/X169678.java").getType("X169678").getType("Y169678");
		ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
		IType[] allTypes = hierarchy.getAllTypes();
		assertSortedElementsEqual(
			"Unexpected types in hierarchy",
			"Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"Y169678 [in X169678 [in X169678.java [in p1 [in <project root> [in P1]]]]]\n" +
			"Z169678 [in Z169678.java [in p1 [in <project root> [in P1]]]]",
			allTypes);
	} finally {
		deleteProjects(new String[] {"P1", "P2"});
	}
}
/**
 * Ensures that a potential subtype that is not in the classpth is handle correctly.
 * (Regression test for PR #1G4GL9R)
 */
public void testPotentialSubtypeNotInClasspath() throws JavaModelException {
	IJavaProject project = getJavaProject("TypeHierarchy");
	ICompilationUnit cu = getCompilationUnit("TypeHierarchy", "src", "p1", "X.java");
	IType type = cu.getType("X");
	ITypeHierarchy h = type.newTypeHierarchy(project, null);
	IType[] types = h.getSubtypes(type);
	this.assertTypesEqual(
		"Unexpected sub types of X",
		"p1.Y\n",
		types
	);
}
/*
 * Ensures that progress is reported while waiting for indexing to finish
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=210094 )
 */
public void testProgressWhileIndexing() throws CoreException, TimeOutException {
	final WaitingJob job = new WaitingJob();
	try {
		createJavaProject("P");
		createFile("/P/X210094.java", "public class X210094 {}");
		job.suspend();
		createFile("/P/Y210094.java", "public class Y210094 {}");
		IType type = getCompilationUnit("/P/X210094.java").getType("X210094");
		class ProgressCounter extends TestProgressMonitor {
			int count = 0;
			public void subTask(String name) {
				if (this.count++ == 0)
					job.resume();
			}
			public boolean isCanceled() {
				return false;
			}
		}
		ProgressCounter counter = new ProgressCounter();
		type.newTypeHierarchy(counter);
		assertTrue("subTask() should be notified", counter.count > 0);
	} finally {
		job.resume();
		deleteProject("P");
	}
}
/*
 * Ensures that a type hierarchy on a region contains all subtypes
 * (regression test for bug 47743 Open type hiearchy problems [type hierarchy])
 */
public void testRegion1() throws JavaModelException {
	IPackageFragment pkg = getPackageFragment("TypeHierarchy", "src", "q1");
	IRegion region = JavaCore.newRegion();
	region.add(pkg);
	ITypeHierarchy h = pkg.getJavaProject().newTypeHierarchy(region, null);
	assertTypesEqual(
		"Unexpected types in hierarchy",
		"java.lang.Object\n" +
		"q1.X\n" +
		"q1.Z\n" +
		"q2.Y\n",
		h.getAllTypes()
	);
}
/*
 * Ensures that a type hierarchy on a region contains all subtypes
 * (regression test for bug 47743 Open type hiearchy problems [type hierarchy])
 */
public void testRegion2() throws JavaModelException {
	IPackageFragment pkg = getPackageFragment("TypeHierarchy", "src", "q2");
	IRegion region = JavaCore.newRegion();
	region.add(pkg);
	ITypeHierarchy h = pkg.getJavaProject().newTypeHierarchy(region, null);
	assertTypesEqual(
		"Unexpected types in hierarchy",
		"java.lang.Object\n" +
		"q1.X\n" +
		"q2.Y\n",
		h.getAllTypes()
	);
}
/*
 * Ensures that a type hierarchy on a region contains anonymous/local types in this region
 * (regression test for bug 48395 Hierarchy on region misses local classes)
 */
public void testRegion3() throws JavaModelException {
	IPackageFragment pkg = getPackageFragment("TypeHierarchy", "src", "p9");
	IRegion region = JavaCore.newRegion();
	region.add(pkg);
	ITypeHierarchy h = pkg.getJavaProject().newTypeHierarchy(region, null);
	assertTypesEqual(
		"Unexpected types in hierarchy",
		"java.lang.Object\n" +
		"p9.X\n" +
		"p9.X$1\n" +
		"p9.X$Y\n",
		h.getAllTypes()
	);
}
public void _testRegion4() throws CoreException {
	try {
		IJavaProject p1 = createJavaProject("P1");
		IJavaProject p2 = createJavaProject("P2", new String[] {""}, new String[] {"JCL_LIB"}, new String[] {"/P1"}, "");
		IJavaProject p3 = createJavaProject("P3", new String[] {""}, new String[] {"JCL_LIB"}, new String[] {"/P1"}, "");
		createFile(
			"/P1/X.java",
			"public class X {\n" +
			"}"
		);
		createFile(
			"/P2/Y.java",
			"public class Y extends X {\n" +
			"}"
		);
		createFile(
			"/P3/Z.java",
			"public class Z extends X {\n" +
			"}"
		);
		IRegion region = JavaCore.newRegion();
		region.add(p1);
		region.add(p2);
		region.add(p3);
		ITypeHierarchy hierarchy = JavaCore.newTypeHierarchy(region, null, null);
		assertHierarchyEquals(
			"Focus: <NONE>\n" +
			"Super types of root classes:\n" +
			"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"Sub types of root classes:\n" +
			"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"    Class [in Class.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"    String [in String.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"    Throwable [in Throwable.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"      Error [in Error.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"      Exception [in Exception.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"        CloneNotSupportedException [in CloneNotSupportedException.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"        InterruptedException [in InterruptedException.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"        RuntimeException [in RuntimeException.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"          IllegalMonitorStateException [in IllegalMonitorStateException.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"    X [in X.java [in <default> [in <project root> [in P1]]]]\n" +
			"      Y [in Y.java [in <default> [in <project root> [in P2]]]]\n" +
			"      Z [in Z.java [in <default> [in <project root> [in P3]]]]\n",
			hierarchy);
	} finally {
		deleteProjects(new String[] {"P1", "P2", "P3"});
	}
}
/*
 * Ensures that a type hierarchy on a region that contains a type with a missing super class is correct
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=154865 )
 */
public void testRegion5() throws Exception {
	try {
		createJavaProject("P", new String[] {""}, new String[] {"JCL_LIB"}, "");
		createFolder("/P/p");
		createFile(
			"/P/p/X.java",
			"package p;\n" +
			"public class X {\n" +
			"}\n" +
			"class Y extends X {\n" +
			"}"
		);
		createFile(
			"/P/p/Z.java",
			"package p;\n" +
			"public class Z extends Unknown {\n" +
			"}"
		);
		IPackageFragment pkg = getPackage("/P/p");
		IRegion region = JavaCore.newRegion();
		region.add(pkg);
		ITypeHierarchy h = pkg.getJavaProject().newTypeHierarchy(region, null);
		assertHierarchyEquals(
			"Focus: <NONE>\n" +
			"Super types of root classes:\n" +
			"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"  Z [in Z.java [in p [in <project root> [in P]]]]\n" +
			"Sub types of root classes:\n" +
			"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"    X [in X.java [in p [in <project root> [in P]]]]\n" +
			"      Y [in X.java [in p [in <project root> [in P]]]]\n" +
			"  Z [in Z.java [in p [in <project root> [in P]]]]\n",
			h);
	} finally {
		deleteProject("P");
	}
}
/**
 * @bug 150289: [hierarchy] NPE in hierarchy builder when region is empy
 * @test Ensure that no NPE is thrown when IRegion has no associated project
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=150289"
 */
public void testRegion_Bug150289() throws JavaModelException {
	ITypeHierarchy h = this.currentProject.newTypeHierarchy(JavaCore.newRegion(), null);
	assertEquals("Unexpected number of types in hierarchy", 0, h.getAllTypes().length);
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=144976
public void testResilienceToMissingBinaries() throws CoreException {
	try {
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL_LIB", "/TypeHierarchy/test144976.jar"}, "bin");
		createFolder("/P/src/tools/");
		createFile(
			"/P/src/tools/DisplayTestResult2.java",
			"pakage tools;\n" +
			"import servlet.*;\n" +
			"public class DisplayTestResult2 extends TmrServlet2 {\n" +
			"}"
		);
		createFolder("/P/src/servlet/");
		createFile(
				"/P/src/servlet/TmrServlet2.java",
				"pakage servlet;\n" +
				"public class TmrServlet2 extends TmrServlet {\n" +
				"}"
			);
		createFile(
				"/P/src/servlet/TmrServlet.java",
				"pakage servlet;\n" +
				"import gk.*;\n" +
				"public class TmrServlet extends GKServlet {\n" +
				"}"
			);
		IType type = getCompilationUnit("P", "src", "tools", "DisplayTestResult2.java").getType("DisplayTestResult2");
		ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
		assertNotNull(hierarchy.getSupertypes(type));
		assertHierarchyEquals(
				"Focus: DisplayTestResult2 [in DisplayTestResult2.java [in tools [in src [in P]]]]\n" +
				"Super types:\n" +
				"  TmrServlet2 [in TmrServlet2.java [in servlet [in src [in P]]]]\n" +
				"    TmrServlet [in TmrServlet.java [in servlet [in src [in P]]]]\n" +
				"      GKServlet [in GKServlet.class [in gk [in /TypeHierarchy/test144976.jar [in P]]]]\n" +
				"Sub types:\n",
			hierarchy);
	} finally {
		deleteProject("P");
	}
}
/*
 * Ensures that the focus type is put as a non-resolved type
 * (regression test for bug 92357 ITypeHierarchy#getType() should return an unresolved handle)
 */
public void testResolvedTypeAsFocus() throws CoreException {
	try {
		createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5");
		String source =
			"public class X {\n" +
			"  Y<String> field;\n" +
			"}\n" +
			"class Y<E> {\n" +
			"}";
		createFile("/P/X.java", source);
		int start = source.indexOf("Y");
		int end = source.indexOf("<String>");
		IJavaElement[] elements = getCompilationUnit("/P/X.java").codeSelect(start, end-start);
		IType focus = (IType) elements[0];
		ITypeHierarchy hierarchy = focus.newTypeHierarchy(null);
		assertElementsEqual(
			"Unexpected focus type in hierarchy",
			"Y [in X.java [in <default> [in <project root> [in P]]]]",
			new IJavaElement[] {hierarchy.getType()},
			true/*show resolved info*/);
	} finally {
		deleteProject("P");
	}
}
/*
 * Ensure that the order of roots is taken into account when a type is present in multiple roots.
 * (regression test for bug 139555 [hierarchy] Opening a class from Type hierarchy will give the wrong one if source and compiled are in defined in project)
 */
public void testRootOrder() throws CoreException, IOException {
	try {
		IJavaProject project = createJavaProject("P", new String[] {"abc"}, new String[] {"JCL_LIB"}, "bin");
		createFolder("/P/abc/p");
		createFile(
			"/P/abc/p/X.java",
			"package p;\n"+
			"public class X {}"
		);
		createFile(
			"/P/abc/p/Y.java",
			"package p;\n"+
			"public class Y extends X {}"
		);
		addLibrary(project, "lib.jar", "libsrc.zip", new String[] {
			"p/X.java",
			"package p;\n"+
			"public class X {}",
			"p/Y.java",
			"package p;\n"+
			"public class Y extends X {}"
		}, "1.4");
		IType type = getCompilationUnit("/P/abc/p/X.java").getType("X");
		ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
		assertHierarchyEquals(
			"Focus: X [in X.java [in p [in abc [in P]]]]\n" +
			"Super types:\n" +
			"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
			"Sub types:\n" +
			"  Y [in Y.java [in p [in abc [in P]]]]\n",
			hierarchy);
	} finally {
		deleteProject("P");
	}
}
/**
 * Ensures that the superclass can be retrieved for a source type's unqualified superclass.
 */
public void testSourceTypeGetSuperclass() throws JavaModelException {
	//unqualified superclass in a source type
	ICompilationUnit cu = getCompilationUnit("TypeHierarchy", "src", "p1", "Y.java");
	IType type = cu.getType("Y");
	ITypeHierarchy h = type.newSupertypeHierarchy(null);
	IType superclass = h.getSuperclass(type);
	assertTrue("Superclass not found for Y", superclass != null);
	assertEquals("Unexpected super class for Y", "X", superclass.getElementName());
}
/**
 * Ensures that the superclass can be retrieved for a source type's superclass when no superclass is specified
 * in the source type.
 */
public void testSourceTypeGetSuperclass2() throws JavaModelException {
	//no superclass specified for a source type
	ICompilationUnit cu = getCompilationUnit("TypeHierarchy", "src", "p1", "X.java");
	IType type = cu.getType("X");
	ITypeHierarchy h = type.newSupertypeHierarchy(null);
	IType superclass = h.getSuperclass(type);
	assertTrue("Superclass not found for X", superclass != null);
	assertEquals("Unexpected super class for X", "Object", superclass.getElementName());
}
/**
 * Ensures that the superclass can be retrieved for a source type's superclass.
 * This type hierarchy is relatively deep.
 */
public void testSourceTypeGetSuperclass3() throws JavaModelException {
	//no superclass specified for a source type
	ICompilationUnit cu = getCompilationUnit("TypeHierarchy", "src", "p1", "Deep.java");
	IType type = cu.getType("Deep");
	ITypeHierarchy h = type.newSupertypeHierarchy(null);
	IType superclass = h.getSuperclass(type);
	assertTrue("Superclass not found for Deep", superclass != null);
	assertEquals("Unexpected super class for Deep", "Z", superclass.getElementName());
}
/**
 * Ensures that the superclass can be retrieved when it is defined
 * in the same compilation unit.
 */
public void testSourceTypeGetSuperclass4() throws JavaModelException {
	ICompilationUnit cu = getCompilationUnit("TypeHierarchy", "src", "p1", "A.java");
	IType type = cu.getType("A");
	ITypeHierarchy h = type.newSupertypeHierarchy(null);
	IType superclass = h.getSuperclass(type);
	assertTrue("Superclass not found for A", superclass != null);
	assertEquals("Unexpected super class for A", "B", superclass.getElementName());
}

/**
 * Ensures that the superinterfaces can be retrieved for a source type's superinterfaces.
 */
public void testSourceTypeGetSuperInterfaces() throws JavaModelException {
	ICompilationUnit cu = getCompilationUnit("TypeHierarchy", "src", "p1", "Y.java");
	IType type = cu.getType("Y");
	ITypeHierarchy h = type.newSupertypeHierarchy(null);
	IType[] superInterfaces = h.getSuperInterfaces(type);
	assertTypesEqual("Unexpected super interfaces for Y",
		"p1.I1\n" +
		"p1.I2\n",
		superInterfaces);
}

/**
 * Ensures that no subclasses exist in a super type hierarchy for the focus type.
 */
public void testSupertypeHierarchyGetSubclasses() throws JavaModelException {
	IType type = getClassFile("TypeHierarchy", getExternalJCLPathString(), "java.lang", "Object.class").getType();
	ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
	IType[] types = hierarchy.getSubclasses(type);
	assertTypesEqual(
		"Unexpected subclasses of Object",
		"",
		types);

	ICompilationUnit cu = getCompilationUnit("TypeHierarchy", "src", "p1", "Y.java");
	type = cu.getType("Y");
	hierarchy = type.newSupertypeHierarchy(null);
	types = hierarchy.getSubclasses(type);
	assertTypesEqual(
		"Unexpected subclasses of Y",
		"",
		types);
}
/**
 * Ensures that no subtypes exist in a super type hierarchy for the focus type.
 */
public void testSupertypeHierarchyGetSubtypes() throws JavaModelException {
	IType type = getClassFile("TypeHierarchy", getExternalJCLPathString(), "java.lang", "Object.class").getType();
	ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
	IType[] types = hierarchy.getSubtypes(type);
	assertTypesEqual(
		"Unexpected subtypes of Object",
		"",
		types);

	ICompilationUnit cu = getCompilationUnit("TypeHierarchy", "src", "p1", "Y.java");
	type = cu.getType("Y");
	hierarchy = type.newSupertypeHierarchy(null);
	types = hierarchy.getSubtypes(type);
	assertTypesEqual(
		"Unexpected subtypes of Y",
		"",
		types);
}
/**
 * Ensures that a super type hierarchy can be created on a working copy.
 * (regression test for bug 3446 type hierarchy: incorrect behavior wrt working copies (1GLDHOA))
 */
public void testSupertypeHierarchyOnWorkingCopy() throws JavaModelException {
	ICompilationUnit cu = this.getCompilationUnit("TypeHierarchy", "src", "wc", "X.java");
	ICompilationUnit workingCopy = null;
	try {
		workingCopy = cu.getWorkingCopy(null);
		workingCopy.createType(
			"class B{\n" +
			"	void m(){\n" +
			"	}\n" +
			"	void f(){\n" +
			"		m();\n" +
			"	}\n" +
			"}\n",
			null,
			true,
			null);
		workingCopy.createType(
			"class A extends B{\n" +
			"	void m(){\n" +
			"	}\n" +
			"}",
			null,
			true,
			null);
		IType typeA = workingCopy.getType("A");
		ITypeHierarchy hierarchy = typeA.newSupertypeHierarchy(null);
		IType typeB = workingCopy.getType("B");
		assertTrue("hierarchy should contain B", hierarchy.contains(typeB));
	} finally {
		if (workingCopy != null) {
			workingCopy.discardWorkingCopy();
		}
	}
}
/*
 * Ensures that creating a hierarchy on a project with classpath problem doesn't throw a NPE
 * (regression test for bug 49809  NPE from MethodVerifier)
 */
public void testSuperTypeHierarchyWithMissingBinary() throws JavaModelException {
	IJavaProject project = getJavaProject("TypeHierarchy");
	IClasspathEntry[] originalClasspath = project.getRawClasspath();
	try {
		int length = originalClasspath.length;
		IClasspathEntry[] newClasspath = new IClasspathEntry[length+1];
		System.arraycopy(originalClasspath, 0, newClasspath, 0, length);
		newClasspath[length] = JavaCore.newLibraryEntry(new Path("/TypeHierarchy/test49809.jar"), null, null);
		project.setRawClasspath(newClasspath, null);
		ICompilationUnit cu = getCompilationUnit("/TypeHierarchy/src/q3/Z.java");
		IType type = cu.getType("Z");
		ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
		assertHierarchyEquals(
				"Focus: Z [in Z.java [in q3 [in src [in TypeHierarchy]]]]\n" +
				"Super types:\n" +
				"  Y49809 [in Y49809.class [in p49809 [in test49809.jar [in TypeHierarchy]]]]\n" +
				"Sub types:\n",
			hierarchy
		);
	} finally {
		project.setRawClasspath(originalClasspath, null);
	}
}
/*
 * Ensures that a hierarchy where the super type is not visible can still be constructed.
 */
public void testVisibility1() throws JavaModelException {
	IType type = getCompilationUnit("/TypeHierarchy/src/q6/Y.java").getType("Y");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: Y [in Y.java [in q6 [in src [in TypeHierarchy]]]]\n" +
		"Super types:\n" +
		"  NonVisibleClass [in X.java [in q5 [in src [in TypeHierarchy]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy
	);
}
/*
 * Ensures that a hierarchy where the super interface is not visible can still be constructed.
 */
public void testVisibility2() throws JavaModelException {
	IType type = getCompilationUnit("/TypeHierarchy/src/q6/Z.java").getType("Z");
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
	assertHierarchyEquals(
		"Focus: Z [in Z.java [in q6 [in src [in TypeHierarchy]]]]\n" +
		"Super types:\n" +
		"  NonVisibleInterface [in X.java [in q5 [in src [in TypeHierarchy]]]]\n" +
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy
	);
}

/**
 * @bug 186781: StackOverflowError while computing launch button tooltip
 * @test Verify that StackOverflowException does no longer occur with the given test case
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=186781"
 */
public void testBug186781() throws JavaModelException {
	IType type = getCompilationUnit("/TypeHierarchy/src/q186871/X.java").getType("X");
	assertTrue("Type should exist!", type.exists());
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null); // when bug occurred a stack overflow happened here...
	assertHierarchyEquals(
		"Focus: X [in X.java [in q186871 [in src [in TypeHierarchy]]]]\n" +
		"Super types:\n" +
		"  Super [in X.java [in q186871 [in src [in TypeHierarchy]]]]\n" +
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
		"Sub types:\n",
		hierarchy);
}

/**
 * @bug 215841: [search] Opening Type Hierarchy extremely slow
 * @test Ensure that the non-existing library referenced through a linked resource
 * 	is not indexed on each search request while building the hierarchy
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=215841"
 */
public void testBug215841() throws JavaModelException, CoreException, InterruptedException {
	final String linkedPath = "/TypeHierarchy/linked.jar";
	class LocalProgressMonitor extends TestProgressMonitor {
		int count = 0;
		public boolean isCanceled() {
	        return false;
        }
		public void subTask(String name) {
			if (name.indexOf("files to index") > 0 && name.indexOf(linkedPath) > 0) {
	        	this.count++;
			}
        }
	}
	IJavaProject project = getJavaProject("TypeHierarchy");
	IClasspathEntry[] originalClasspath = project.getRawClasspath();
	try {
		// Add linked resource to an unknown jar file on the project classpath
		int length = originalClasspath.length;
		IClasspathEntry[] newClasspath = new IClasspathEntry[length+1];
		System.arraycopy(originalClasspath, 0, newClasspath, 0, length);
		IFile file = getFile(linkedPath);
		file.createLink(new Path(getExternalPath()).append("unknown.jar"), IResource.ALLOW_MISSING_LOCAL, null);
		newClasspath[length] = JavaCore.newLibraryEntry(new Path(linkedPath), null, null);
		project.setRawClasspath(newClasspath, null);
		waitUntilIndexesReady();

		// Build hierarchy of Throwable
		IType type = getClassFile("TypeHierarchy", getExternalJCLPathString(), "java.lang", "Throwable.class").getType();
		LocalProgressMonitor monitor = new LocalProgressMonitor();
		type.newTypeHierarchy(monitor);
		assertEquals("Unexpected indexing of non-existent external jar file while building hierarchy!", 1, monitor.count);
	} finally {
		project.setRawClasspath(originalClasspath, null);
	}
}
/**
 * @bug 254738: NPE in HierarchyResolver.setFocusType
 * @test that a nested method/anonymous sub type is included in the hierarchy when the number of annotations > 10
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=254738"
 */
public void testBug254738() throws CoreException {
	try {
		createJavaProject("P", new String[] {"src"}, new String[] {}, "bin", "1.5");
		createFolder("/P/src/abc");
		createFile(
			"/P/src/abc/Parent.java",
			"package abc;\n" +
			"public class Parent {\n" +
			"	public void parentmethod() {\n" +
			"   	new Object() {\n" +
			"			void nestedonemethod() {\n" +
			"           	new Object(){\n" +
			"               	public int hashCode() {\n" +
			"                   	return 0; \n" +
			"                   } \n" +
			"				}; \n" +
			"         	}\n" +
			"   	};\n" +
			"	}\n" +
			"}\n" +
			"@Deprecated\n" +
			"class Dep {\n" +
			"        @Deprecated void a() {}\n" +
			"        @Deprecated void b() {}\n" +
			"        @Deprecated void c() {}\n" +
			"        @Deprecated void d() {}\n" +
			"        @Deprecated void e() {}\n" +
			"        @Deprecated void f() {}\n" +
			"        @Deprecated void g() {}\n" +
			"        @Deprecated void h() {}\n" +
			"        @Deprecated void i() {}\n" +
			"        @Deprecated void j() {}\n" +
			"        @Deprecated void k() {}\n" +
			"}"
			);
		IType focus  = getCompilationUnit("/P/src/abc/Parent.java").getType("Parent");
		focus =	focus.getMethod("parentmethod", new String[]{}).getType("", 1).getMethod("nestedonemethod", new String[]{}).
												getType("", 1);
		ITypeHierarchy hierarchy = focus.newTypeHierarchy(null);
		assertHierarchyEquals(
				"Focus: <anonymous #1> [in nestedonemethod() [in <anonymous #1> [in parentmethod() [in Parent [in Parent.java [in abc [in src [in P]]]]]]]]\n" + 
				"Super types:\n" + 
				"Sub types:\n",
			hierarchy);
	} finally {
		deleteProjects(new String[] {"P"});
	}
}
/**
 * @bug 288698: Can't create type hierarchy for abstract types when they have inline descendants and *.class* in project name 
 * @test Ensure that ".class" as a substring of a path name is not interpreted as the ".class" suffix.
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=288698"
 */
public void testBug288698() throws JavaModelException {
	IType type = getCompilationUnit("/TypeHierarchy/src288698.classbug/p288698/AbstractBugTest.java").getType("AbstractBugTest");
	assertTrue("Type should exist!", type.exists());
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null); // when bug occurred a StringIndexOutOfBoundsException was thrown here
	assertHierarchyEquals(
		"Focus: AbstractBugTest [in AbstractBugTest.java [in p288698 [in src288698.classbug [in TypeHierarchy]]]]\n" + 
		"Super types:\n" + 
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" + 
		"Sub types:\n" + 
		"  <anonymous #1> [in testIt() [in BugTest2Buggy [in BugTest2Buggy.java [in p288698 [in src288698.classbug [in TypeHierarchy]]]]]]\n",
		hierarchy);
}
/**
 * @bug  329663:[type hierarchy] Interfaces duplicated in type hierarchy on two packages from multiple projects
 * @test that when two selected regions contains the same interface, it's not reported twice in the hierarchy.
 * 
 * @throws JavaModelException
 * @throws CoreException
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=329663"
 */
public void _testBug329663() throws JavaModelException, CoreException {
	try {
		IJavaProject p1 = createJavaProject("P1", new String[] {""}, new String[] {"JCL_LIB"}, new String[0], "");
		IJavaProject p2 = createJavaProject("P2", new String[] {""}, new String[] {"JCL_LIB"}, new String[] {"/P1"}, "");
		createFolder("/P1/p");
		createFile(
				"/P1/p/I.java",
				"package p;\n" +
				"public interface I{}");
		createFile(
				"/P1/p/X.java",
				"package p;\n" +
				"public class X implements I{\n" +
				"}"
		);
		createFolder("/P2/q");
		createFile(
				"/P2/q/Y.java",
				"package q;\n" +
				"import p.*;\n" +
				"public class Y implements I {\n" +
					"}"
		);
		IRegion region = JavaCore.newRegion();
		region.add(p1);
		region.add(p2);
		ITypeHierarchy hierarchy = JavaCore.newTypeHierarchy(region, null, null);
		IType[] types = hierarchy.getRootInterfaces();
		assertTypesEqual("Unexpected super interfaces", 
				"java.io.Serializable\n" + 
				"p.I\n", 
				types);
	}
	finally{
		deleteProject("P1");
		deleteProject("P2");
	}
}
/**
 * @bug  329663:[type hierarchy] Interfaces duplicated in type hierarchy on two packages from multiple projects
 * @test that when two selected regions contains interfaces with same name but different, they are reported individually
 * in the hierarchy.
 * 
 * @throws JavaModelException
 * @throws CoreException
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=329663"
 */
public void _testBug329663a() throws JavaModelException, CoreException {
try {
	IJavaProject p1 = createJavaProject("P1", new String[] {""}, new String[] {"JCL_LIB"}, new String[0], "");
	IJavaProject p2 = createJavaProject("P2", new String[] {""}, new String[] {"JCL_LIB"}, new String[] {"/P1"}, "");
	createFolder("/P1/p");
	createFile(
			"/P1/p/I.java",
			"package p;\n" +
			"public interface I{}");
	createFile(
			"/P1/p/X.java",
			"package p;\n" +
			"public class X implements I{\n" +
				"}"
	);
	createFolder("/P2/q");
	createFile(
			"/P2/q/I.java",
			"package q;\n" +
			"public interface I{}");
	createFile(
			"/P2/q/Y.java",
			"package q;\n" +
			"public class Y implements I {\n" +
				"}"
	);
	IRegion region = JavaCore.newRegion();
	region.add(p1);
	region.add(p2);
	ITypeHierarchy hierarchy = JavaCore.newTypeHierarchy(region, null, null);
	IType[] types = hierarchy.getRootInterfaces();
	assertTypesEqual("Unexpected super interfaces", 
			"java.io.Serializable\n" + 
			"p.I\n" + 
			"q.I\n", 
			types);
}
finally{
	deleteProject("P1");
	deleteProject("P2");
}
}
// Bug 300576 - NPE Computing type hierarchy when compliance doesn't match libraries
// test that a missing java.lang.Enum doesn't cause NPE
public void testBug300576() throws CoreException {
	IJavaProject prj = null;
	try {
		prj = createJavaProject("Bug300576", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin", "1.5");
		createFolder("/Bug300576/src/p");
		createFile("/Bug300576/src/p/Outer.java",
				"package p;\n" + 
				"class Outer {\n" + 
				"    enum A {\n" + 
				"        GREEN, DARK_GREEN, BLACK;\n" +
				"        /** Javadoc of getNext() */\n" + 
				"        A getNext() {\n" + 
				"            switch (this) {\n" + 
				"                case GREEN : return DARK_GREEN;\n" + 
				"                case DARK_GREEN : return BLACK;\n" + 
				"                case BLACK : return GREEN;\n" + 
				"                default : return null;\n" + 
				"            }\n" + 
				"        }\n" + 
				"    }\n" + 
				"    {\n" + 
				"        A a= A.GREEN.getNext();\n" + 
				"    }\n" + 
				"}\n");
		IType a = getCompilationUnit("Bug300576", "src", "p", "Outer.java").getType("Outer").getType("A");
		IRegion region = JavaCore.newRegion();
		region.add(getPackageFragmentRoot("Bug300576", "src"));
		ITypeHierarchy hierarchy = prj.newTypeHierarchy(a, region, new NullProgressMonitor());
		assertHierarchyEquals(
				"Focus: A [in Outer [in Outer.java [in p [in src [in Bug300576]]]]]\n" + 
				"Super types:\n" + 
				"Sub types:\n",
				hierarchy);
	} finally {
		if (prj != null)
			deleteProject(prj);
	}
}
// Bug 300576 - NPE Computing type hierarchy when compliance doesn't match libraries
// test that a bogus java.lang.Enum (non-generic) doesn't cause NPE
public void testBug300576b() throws CoreException {
	IJavaProject prj = null;
	try {
		prj = createJavaProject("Bug300576", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin", "1.5");
		createFolder("/Bug300576/src/p");
		createFolder("/Bug300576/src/java/lang");
		createFile("/Bug300576/src/java/lang/Enum.java",
				"package java.lang;\n" +
				"public class Enum {}\n");
		createFile("/Bug300576/src/p/Outer.java",
				"package p;\n" + 
				"class Outer {\n" + 
				"    enum A {\n" + 
				"        GREEN, DARK_GREEN, BLACK;\n" +
				"        /** Javadoc of getNext() */\n" + 
				"        A getNext() {\n" + 
				"            switch (this) {\n" + 
				"                case GREEN : return DARK_GREEN;\n" + 
				"                case DARK_GREEN : return BLACK;\n" + 
				"                case BLACK : return GREEN;\n" + 
				"                default : return null;\n" + 
				"            }\n" + 
				"        }\n" + 
				"    }\n" + 
				"    {\n" + 
				"        A a= A.GREEN.getNext();\n" + 
				"    }\n" + 
				"}\n");
		IType a = getCompilationUnit("Bug300576", "src", "p", "Outer.java").getType("Outer").getType("A");
		IRegion region = JavaCore.newRegion();
		region.add(getPackageFragmentRoot("Bug300576", "src"));
		ITypeHierarchy hierarchy = prj.newTypeHierarchy(a, region, new NullProgressMonitor());
		assertHierarchyEquals(
				"Focus: A [in Outer [in Outer.java [in p [in src [in Bug300576]]]]]\n" + 
				"Super types:\n" + 
				"Sub types:\n",
				hierarchy);
	} finally {
		if (prj != null)
			deleteProject(prj);
	}	
}
//Bug 393192 -- Incomplete type hierarchy with > 10 annotations
public void testBug393192() throws CoreException {
	IJavaProject prj = null;
	try {
		prj = createJavaProject("Bug393192", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin", "1.5");
		createFolder("/Bug393192/src/pullup");
		createFile("/Bug393192/src/pullup/A.java",
				"package pullup;\n" + 
				"\n" + 
				"class A {\n" + 
				"    @Deprecated\n" + 
				"    void m0() {\n" + 
				"    }\n" + 
				"\n" + 
				"    @Deprecated\n" + 
				"    void m1() {\n" + 
				"    }\n" + 
				"\n" + 
				"    @Deprecated\n" + 
				"    void m2() {\n" + 
				"    }\n" + 
				"\n" + 
				"    @Deprecated\n" + 
				"    void m3() {\n" + 
				"    }\n" + 
				"\n" + 
				"    @Deprecated\n" + 
				"    void m4() {\n" + 
				"    }\n" + 
				"\n" + 
				"    @Deprecated\n" + 
				"    void m5() {\n" + 
				"    }\n" + 
				"\n" + 
				"    @Deprecated\n" + 
				"    void m6() {\n" + 
				"    }\n" + 
				"\n" + 
				"    @Deprecated\n" + 
				"    void m7() {\n" + 
				"    }\n" + 
				"\n" + 
				"    @Deprecated\n" + 
				"    void m8() {\n" + 
				"    }\n" + 
				"\n" + 
				"    @Deprecated\n" + 
				"    void m9() {\n" + 
				"    }\n" + 
				"\n" + 
				"    /**\n" + 
				"     * @param\n" + 
				"     */\n" + 
				"    @Deprecated\n" + 
				"    void m10() {\n" + 
				"    }\n" + 
				"}\n" + 
				"\n");
		createFile("/Bug393192/src/pullup/package-info.java",
				"package pullup;\n" + 
				"\n");
		createFile("/Bug393192/src/pullup/PullUpBug.java",
				"package pullup;\n" + 
				"\n" + 
				"class PullUpBug extends A {\n" + 
				"\n" + 
				"    void mb() {\n" + 
				"        pullUp();\n" + 
				"    }\n" + 
				"\n" + 
				"    // INVOKE Pull Up REFACTORING ON \"pullUp\", or type Hierarchy on A\n" + 
				"    private void pullUp() {\n" + 
				"    }\n" + 
				"}\n");
		IType a = getCompilationUnit("Bug393192", "src", "pullup", "A.java").getType("A");
		ITypeHierarchy hierarchy = a.newTypeHierarchy(new NullProgressMonitor());
		assertHierarchyEquals(
				"Focus: A [in A.java [in pullup [in src [in Bug393192]]]]\n" + 
				"Super types:\n" + 
				"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
				"Sub types:\n" +
				"  PullUpBug [in PullUpBug.java [in pullup [in src [in Bug393192]]]]\n",
				hierarchy);
	} finally {
		if (prj != null)
			deleteProject(prj);
	}	
}
public void testBug436155() throws CoreException, IOException {
	try {
		IJavaProject project = createJavaProject("P", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin");
		createFolder("/P/abc/p");
		addLibrary(project, "lib.jar", "libsrc.zip", new String[] {
			"p/I.java",
			"package p;\n" +
			"public abstract class I {}",
			"p/I2.java",
			"package p;\n" +
			"public abstract class I2 extends I {}",
			"p/Text.java",
			"package p;\n"+
			"public class Text extends I2 {}",
		}, "1.4");
		
		createFolder("/P/src/q");
		String source = "package q;\n" +
				"import p.Text;\n" +
				"class A {\n" +
				"	Text text = null;\n" +
				"}\n";
		createFile("/P/src/q/A.java", source);
		
		int start = source.lastIndexOf("Text");
		this.workingCopies = new ICompilationUnit[1];
		this.workingCopies[0] = getWorkingCopy("P/src/q/A.java", source);

		IJavaElement[] elements = this.workingCopies[0].codeSelect(start, "Text".length());
		IType focus = (IType) elements[0];
		ITypeHierarchy hierarchy = focus.newTypeHierarchy(null);
		assertHierarchyEquals(
				"Focus: Text [in Text.class [in p [in lib.jar [in P]]]]\n" + 
				"Super types:\n" + 
				"  I2 [in I2.class [in p [in lib.jar [in P]]]]\n" + 
				"    I [in I.class [in p [in lib.jar [in P]]]]\n" + 
				"      Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" + 
				"Sub types:\n",
			hierarchy);
	} finally {
		deleteProject("P");
	}
}
public void testBug436139() throws CoreException, IOException {
	IJavaProject prj = null;
	try {
		prj = createJavaProject("Bug436139", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin", "1.8");
		createFolder("/Bug436139/src/p1");
		String iSource = "package p1;\n" +
				"public interface I {\n" +
				"    void foo(A<B> x);\n" +
				"}";
		createFile("/Bug436139/src/p1/I.java", iSource);
		createFile("/Bug436139/src/p1/A.java", "package p1;\n" +"public class A<T> {}");
		createFile("/Bug436139/src/p1/B.java", "package p1;\n" +"public class B {}");

		
		createFolder("/Bug436139/src/p2");
		String source = "package p2;\n" +
				"import p1.*;\n" +
				"\n" +
				"@SuppressWarnings(\"unused\")\n" +
				"public class X {\n" +
				"\n" +
				"	private Object patternChanged(A<B> x1) {\n" +
				"\n" +
				"		I f1 = new I() {\n" +
				"			public void foo(A<B> x) {}\n" +
				"		};\n" +
				"		return null;\n" +
				"	}\n" +
				"\n" +
				"	private void someOtherMethod() {\n" +
				"		I f2 = (x) -> {	patternChanged(x);};\n" +
				"\n" +
				"		I f3 = new I() {\n" +
				"			public void foo(A<B> x) {}\n" +
				"		};\n" +
				"	}\n" +
				"}\n";
		createFile("/Bug436139/src/p2/X.java", source);

		int start = iSource.lastIndexOf("I");
		this.workingCopies = new ICompilationUnit[1];
		this.workingCopies[0] = getWorkingCopy("/Bug436139/src/p1/I.java", iSource);

		IJavaElement[] elements = this.workingCopies[0].codeSelect(start, "I".length());
		IType focus = (IType) elements[0];
		ITypeHierarchy hierarchy = focus.newTypeHierarchy(null);
		assertHierarchyEquals(
				"Focus: I [in [Working copy] I.java [in p1 [in src [in Bug436139]]]]\n" + 
				"Super types:\n" + 
				"Sub types:\n" + 
				"  <anonymous #1> [in patternChanged(A<B>) [in X [in X.java [in p2 [in src [in Bug436139]]]]]]\n" + 
				"  <anonymous #1> [in someOtherMethod() [in X [in X.java [in p2 [in src [in Bug436139]]]]]]\n" +
				"  <lambda #1> [in someOtherMethod() [in X [in X.java [in p2 [in src [in Bug436139]]]]]]\n",
				hierarchy);
	} finally {
		if (prj != null)
			deleteProject(prj);
	}
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=469668
public void testBug469668() throws CoreException, IOException {
	IJavaProject project = null;
	try {
		project = createJavaProject("Bug469668", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin", "1.8");
		createFolder("/Bug469668/src/hierarchy");
		StringBuffer buffer = new StringBuffer();
		for (int i = 1; i < 21; i++) {
			String unitName = "I" + i;
			String content = "package hierarchy;\n" +
			"public interface " + unitName + " " + buffer.toString() + " {}";
			createFile("/Bug469668/src/hierarchy/" + unitName + ".java", content);
			if (i == 1) {
				buffer.append(" extends ");
			}
			if (i > 1 && i < 20) buffer.append(", ");
			buffer.append(unitName);
		}

		IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
		IRegion region = JavaCore.newRegion();
		for (IPackageFragmentRoot root: roots) {
			if(root.getRawClasspathEntry().getEntryKind() == IClasspathEntry.CPE_SOURCE) {
				region.add(root);
			}
		}

		ITypeHierarchy hierarchy = JavaCore.newTypeHierarchy(region, null, new NullProgressMonitor());
		IType type = project.findType("hierarchy.I15");
		IType[] supertypes = hierarchy.getAllSupertypes(type);
		assertEquals(14, supertypes.length);

		type = project.findType("hierarchy.I5");
		IType[]	subtypes = hierarchy.getAllSubtypes(type);
		assertEquals("Incorrect number of entries for subtype", 15, subtypes.length);

		int i20Count = 0;
		for (IType t: subtypes) {
			if("hierarchy.I20".equals(t.getFullyQualifiedName())) {
				i20Count++;
			}
		}
		assertEquals("Multiple entries of the same type in the hierarchy", 1, i20Count);
		assertEquals(15, subtypes.length);

	} finally {
		if (project != null)
			deleteProject(project);
	}
}
public void testBug462158() throws CoreException, IOException {
	IJavaProject prj = null;
	try {
		prj = createJavaProject("Bug462158", new String[] {"src"}, new String[] {"JCL18_FULL"}, "bin", "1.8", true);
		createFolder("/Bug462158/src/p1");
		String iSource = "package p1;\n" +
				"import java.util.ArrayList;\n" +
				"public class TestEclipseForEachBug {\n" +
				"    static abstract class MyList extends ArrayList<Object> {\n" +
				"        private static final long serialVersionUID = 784633858339367208L;\n" +
				"    }\n" +
				"    @Deprecated\n" +
				"    public void foo1(){}\n" +
				"    @Deprecated\n" +
				"    public void foo2(){}\n" +
				"    @Deprecated\n" +
				"    public void foo3(){}\n" +
				"    @Deprecated\n" +
				"    public void foo4(){}\n" +
				"    @Deprecated\n" +
				"    public void foo5(){}\n" +
				"    @Deprecated\n" +
				"    public void foo6(){}\n" +
				"    @Deprecated\n" +
				"    public void foo7(){}\n" +
				"    @Deprecated\n" +
				"    public void foo8(){}\n" +
				"    @Deprecated\n" +
				"    public void foo9(){}\n" +
				"    @Deprecated\n" +
				"    public void foo10(){}\n" +
				"    @Deprecated\n" +
				"    public void foo11(){}\n" +
				"    @Deprecated\n" +
				"    public void foo12(){}\n" +
				"    void foo(MyList list) {\n" +
				"        forea\n" +
				"    }\n" +
				"}";
		createFile("/Bug462158/src/p1/TestEclipseForEachBug.java", iSource);

		int start = iSource.indexOf("MyList list");
		this.workingCopies = new ICompilationUnit[1];
		this.workingCopies[0] = getWorkingCopy("/Bug462158/src/p1/TestEclipseForEachBug.java", iSource);

		IJavaElement[] elements = this.workingCopies[0].codeSelect(start, "MyList".length());
		assertEquals("Incorrect elements", 1, elements.length);
		IType focus = (IType) elements[0];
		ITypeHierarchy hierarchy = focus.newTypeHierarchy(this.workingCopies, null);
		IType[] allSupertypes = hierarchy.getAllSuperclasses(focus);
		assertTypesEqual("Incorrect hierarchy",
				"java.util.ArrayList\n" +
				"java.util.AbstractList\n" +
				"java.util.AbstractCollection\n" +
				"java.lang.Object\n",
				allSupertypes,
				false);
	} finally {
		if (prj != null)
			deleteProject(prj);
	}
}
public void testBug507954_0001() throws JavaModelException, CoreException {
	IJavaProject javaProject = null; 
	try {
		String projectName = "507954";
		javaProject = createJavaProject(projectName, new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5");
		String packA = "/" + projectName + "/src/a/";
		createFolder(packA);
		String fileA = 				"package a;\n" +
				"public abstract class A {\n"+
				"  protected abstract void foo2();\n" +
				"  public void baz2() {\n" +
				"    foo2();\n" +
			"}";
		createFile(packA + "A.java", fileA);
		createFile(
				packA + "B.java",
				"package a;\n" +
				"public class B {\n" +
				"  public void a() {\n" +
				"    new A() {\n" +
				"      @Override\n" +
				"      protected void foo2() {}\n" +
				"    }.baz2();\n" +
				"  }\n" +
				"}"
				);
		createFile(
				packA + "C.java",
				"package a;\n" +
				"public abstract class C {\n" +
				"  protected abstract void foo1();\n" +
				"  public void baz1() {\n" +
				"    foo1();\n" +
				"  }\n" +
				"}"
				);
		String packD = "/" + projectName + "/src/b/";
		createFolder(packD);

		String fileD = "package d;\n" +
				"import a.A;\n" +
				"import a.C;\n" +
				"public final class D {\n" +
				"\n" +
				"	protected void c() {\n" +
				"		new C() {\n" +
				"			@Override\n" +
				"			protected void foo1() {\n" +
				"				a();\n" +
				"				b();\n" +
				"			}\n" +
				"			private void a() {\n" +
				"				new A() {\n" +
				"					@Override\n" +
				"					protected void foo2() {\n" +
				"					}\n" +
				"				}.baz2();\n" +
				"			}\n" +
				"			private void b() {\n" +
				"				new A() {\n" +
				"					@Override\n" +
				"					protected void foo2() {\n" +
				"					}\n" +
				"				}.baz2();\n" +
				"			}\n" +
				"		}.baz1();\n" +
				"	}\n" +
				"\n" +
				"}\n";

		createFile(packA + "D.java", fileD);
		
		String classA = "A";
		int start = fileA.indexOf(classA);
		this.workingCopies = new ICompilationUnit[1];
		this.workingCopies[0] = getWorkingCopy(packA + "A.java", fileA);

		IJavaElement[] elements = this.workingCopies[0].codeSelect(start, classA.length());
		assertEquals("Incorrect elements", 1, elements.length);
		IType focus = (IType) elements[0];
		ITypeHierarchy hierarchy = focus.newTypeHierarchy(this.workingCopies, null);
		IType[] allSubTypes = hierarchy.getAllSubtypes(focus);
		assertTypesEqual("Incorrect hierarchy",
				"a.B$1\n" + 
				"a.D$1$1\n" + 
				"a.D$1$2\n",
				allSubTypes,
				true);
	}
	finally{
		if (javaProject != null) deleteProject(javaProject);
	}
}

public void testBug533949() throws CoreException {
	if (!isJRE9) return;
	IJavaProject javaProject1 = null; 
	IJavaProject javaProject2 = null; 
	try {
		javaProject1 = createJava9Project("mod1");
		String packA = "/mod1/src/a/";
		createFolder(packA);
		createFile(packA + "A.java",
				"package a;\n" +
				"public abstract class A {\n"+
				"}\n");
		createFile("/mod1/src/module-info.java",
				"module mod1 {\n" +
				"	exports a;\n"+
				"}\n");
		
		javaProject2 = createJava9Project("mod2");
		addClasspathEntry(javaProject2, JavaCore.newProjectEntry(javaProject1.getPath()));
		String packB = "/mod2/src/b/";
		createFolder(packB);
		createFile(packB + "B.java",
				"package b;\n" +
				"public class B extends a.A {\n"+
				"}\n");
		createFile("/mod2/src/module-info.java",
				"module mod2 {\n" +
				"	requires mod1;\n"+
				"}\n");
		
		waitUntilIndexesReady();

		this.workingCopies = new ICompilationUnit[1];
		this.workingCopies[0] = getWorkingCopy(packB + "B.java", true);

		IType focus = javaProject2.findType("b.B");
		ITypeHierarchy hierarchy = focus.newTypeHierarchy(this.workingCopies, null);
		IType[] allSuperTypes = hierarchy.getAllSupertypes(focus);
		assertTypesEqual("Incorrect super hierarchy",
				"a.A\n" +
				"java.lang.Object\n",
				allSuperTypes,
				true);
		
		this.workingCopies = new ICompilationUnit[1];
		this.workingCopies[0] = getWorkingCopy(packA + "A.java", true);

		focus = javaProject1.findType("a.A");
		hierarchy = focus.newTypeHierarchy(this.workingCopies, null);
		IType[] allSubTypes = hierarchy.getAllSubtypes(focus);
		assertTypesEqual("Incorrect sub hierarchy",
				"b.B\n",
				allSubTypes,
				true);
	} finally{
		if (javaProject1 != null) deleteProject(javaProject1);
		if (javaProject2 != null) deleteProject(javaProject2);
	}
}

public void testBug541217() throws CoreException {
    if (!isJRE9) return;
    IJavaProject javaProject1 = null;
    try {
        javaProject1 = createJava9Project("mod1");
        String packA = "/mod1/src/a/";
        createFolder(packA);
        createFile(packA + "A.java",
                        "package a;\n" +
                        "public interface A extends java.sql.Driver{\n"+
                        "}\n");
        createFile("/mod1/src/module-info.java",
                        "module mod1 {\n" +
                        "       requires java.sql;\n"+
                        "       exports a;\n"+
                        "}\n");

        waitUntilIndexesReady();

        IType focus = javaProject1.findType("java.sql.Driver");
        ITypeHierarchy hierarchy = focus.newTypeHierarchy(null);
        IType[] allSubTypes = hierarchy.getAllSubtypes(focus);
        assertTypesEqual("Incorrect sub hierarchy",
                        "a.A\n",
                        allSubTypes,
                        true);
    } finally{
        if (javaProject1 != null) deleteProject(javaProject1);
    }
}
public void testBug425111() throws Exception {
	IJavaProject javaProject1 = null;
	try {
		javaProject1 = createJavaProject("P1", new String[] {"src"}, new String[] {"JCL18_FULL", "/P1/lib.jar"},"bin", "1.8");

		createLibrary(javaProject1, "lib.jar", "lib-src.zip", 
				new String[] {
						"javax/tools/JavaFileManager.java",
						"package javax.tools;\n" +
						"public interface JavaFileManager extends AutoCloseable {}\n",
						"javax/tools/ForwardingJavaFileManager.java",
						"package javax.tools;\n" +
						"public class ForwardingJavaFileManager<M extends JavaFileManager> implements JavaFileManager {\n" +
						"	public void close() {}\n" +
						"}\n"
				},
				null,
				"1.8");
		createFolder("/P1/src/p1");
		createFile("/P1/src/p1/T.java",
				"package p1;\n" +
				"import javax.tools.*;\n" +
				"public class T {\n" +
				"	Object test() {\n" +
				"		return new ForwardingJavaFileManager<JavaFileManager>(null) {\n" +
				"		}\n" +
				"	}\n" +
				"}\n");
		waitUntilIndexesReady();
        IType focus = javaProject1.findType("java.lang.AutoCloseable");
        ITypeHierarchy hierarchy = focus.newTypeHierarchy(null);
        IType[] allSubTypes = hierarchy.getAllSubtypes(focus);
        assertTypesEqual("Incorrect sub hierarchy",
        		"java.io.BufferedInputStream\n" + 
        				"java.io.BufferedOutputStream\n" + 
        				"java.io.BufferedReader\n" + 
        				"java.io.BufferedWriter\n" + 
        				"java.io.ByteArrayInputStream\n" + 
        				"java.io.ByteArrayOutputStream\n" + 
        				"java.io.CharArrayReader\n" + 
        				"java.io.CharArrayWriter\n" + 
        				"java.io.Closeable\n" + 
        				"java.io.DataInputStream\n" + 
        				"java.io.DataOutputStream\n" + 
        				"java.io.FileInputStream\n" + 
        				"java.io.FileOutputStream\n" + 
        				"java.io.FileReader\n" + 
        				"java.io.FileWriter\n" + 
        				"java.io.FilterInputStream\n" + 
        				"java.io.FilterOutputStream\n" + 
        				"java.io.FilterReader\n" + 
        				"java.io.FilterWriter\n" + 
        				"java.io.InputStream\n" + 
        				"java.io.InputStreamReader\n" + 
        				"java.io.LineNumberInputStream\n" + 
        				"java.io.LineNumberReader\n" + 
        				"java.io.ObjectInput\n" + 
        				"java.io.ObjectInputStream\n" + 
        				"java.io.ObjectOutput\n" + 
        				"java.io.ObjectOutputStream\n" + 
        				"java.io.OutputStream\n" + 
        				"java.io.OutputStreamWriter\n" + 
        				"java.io.PipedInputStream\n" + 
        				"java.io.PipedOutputStream\n" + 
        				"java.io.PipedReader\n" + 
        				"java.io.PipedWriter\n" + 
        				"java.io.PrintStream\n" + 
        				"java.io.PrintWriter\n" + 
        				"java.io.PushbackInputStream\n" + 
        				"java.io.PushbackReader\n" + 
        				"java.io.RandomAccessFile\n" + 
        				"java.io.Reader\n" + 
        				"java.io.SequenceInputStream\n" + 
        				"java.io.StringBufferInputStream\n" + 
        				"java.io.StringReader\n" + 
        				"java.io.StringWriter\n" + 
        				"java.io.Writer\n" + 
        				"java.net.DatagramSocket\n" + 
        				"java.net.FactoryURLClassLoader\n" + 
        				"java.net.MulticastSocket\n" + 
        				"java.net.ServerSocket\n" + 
        				"java.net.Socket\n" + 
        				"java.net.SocketInputStream\n" + 
        				"java.net.SocketOutputStream\n" + 
        				"java.net.URLClassLoader\n" + 
        				"java.nio.channels.AsynchronousByteChannel\n" + 
        				"java.nio.channels.AsynchronousChannel\n" + 
        				"java.nio.channels.AsynchronousFileChannel\n" + 
        				"java.nio.channels.AsynchronousServerSocketChannel\n" + 
        				"java.nio.channels.AsynchronousSocketChannel\n" + 
        				"java.nio.channels.ByteChannel\n" + 
        				"java.nio.channels.Channel\n" + 
        				"java.nio.channels.DatagramChannel\n" + 
        				"java.nio.channels.FileChannel\n" + 
        				"java.nio.channels.FileLock\n" + 
        				"java.nio.channels.GatheringByteChannel\n" + 
        				"java.nio.channels.InterruptibleChannel\n" + 
        				"java.nio.channels.MulticastChannel\n" + 
        				"java.nio.channels.NetworkChannel\n" + 
        				"java.nio.channels.Pipe$SinkChannel\n" + 
        				"java.nio.channels.Pipe$SourceChannel\n" + 
        				"java.nio.channels.ReadableByteChannel\n" + 
        				"java.nio.channels.ScatteringByteChannel\n" + 
        				"java.nio.channels.SeekableByteChannel\n" + 
        				"java.nio.channels.SelectableChannel\n" + 
        				"java.nio.channels.Selector\n" + 
        				"java.nio.channels.ServerSocketChannel\n" + 
        				"java.nio.channels.SocketChannel\n" + 
        				"java.nio.channels.WritableByteChannel\n" + 
        				"java.nio.channels.spi.AbstractInterruptibleChannel\n" + 
        				"java.nio.channels.spi.AbstractSelectableChannel\n" + 
        				"java.nio.channels.spi.AbstractSelector\n" + 
        				"java.nio.file.WatchService\n" + 
        				"java.security.DigestInputStream\n" + 
        				"java.security.DigestOutputStream\n" + 
        				"java.sql.CallableStatement\n" + 
        				"java.sql.Connection\n" + 
        				"java.sql.PreparedStatement\n" + 
        				"java.sql.ResultSet\n" + 
        				"java.sql.Statement\n" + 
        				"java.util.Formatter\n" + 
        				"java.util.Scanner\n" + 
        				"java.util.jar.JarFile\n" + 
        				"java.util.jar.JarInputStream\n" + 
        				"java.util.jar.JarOutputStream\n" + 
        				"java.util.stream.AbstractPipeline\n" + 
        				"java.util.stream.BaseStream\n" + 
        				"java.util.stream.DoublePipeline\n" + 
        				"java.util.stream.DoubleStream\n" + 
        				"java.util.stream.IntPipeline\n" + 
        				"java.util.stream.IntStream\n" + 
        				"java.util.stream.LongPipeline\n" + 
        				"java.util.stream.LongStream\n" + 
        				"java.util.stream.ReferencePipeline\n" + 
        				"java.util.stream.Stream\n" + 
        				"java.util.zip.CheckedInputStream\n" + 
        				"java.util.zip.CheckedOutputStream\n" + 
        				"java.util.zip.DeflaterInputStream\n" + 
        				"java.util.zip.DeflaterOutputStream\n" + 
        				"java.util.zip.GZIPInputStream\n" + 
        				"java.util.zip.GZIPOutputStream\n" + 
        				"java.util.zip.InflaterInputStream\n" + 
        				"java.util.zip.InflaterOutputStream\n" + 
        				"java.util.zip.ZipFile\n" + 
        				"java.util.zip.ZipInputStream\n" + 
        				"java.util.zip.ZipOutputStream\n" + 
        				"javax.tools.ForwardingJavaFileManager\n" + 
        				"javax.tools.JavaFileManager\n" + 
        				"p1.T$1\n",
                        allSubTypes,
                        true);
	} finally {
		if (javaProject1 != null) deleteProject(javaProject1);
	}
}
}

Back to the top