Skip to main content
summaryrefslogtreecommitdiffstats
blob: 796ed6d569beb463e5c80c0c81a3531794dd672f (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
/*******************************************************************************
 * Copyright (c) 2000, 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.core.tests.model;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import junit.framework.Test;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.*;
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
import org.eclipse.jdt.internal.core.Buffer;
import org.eclipse.jdt.internal.core.CompilationUnit;
import org.eclipse.jdt.internal.core.util.Util;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.text.edits.UndoEdit;

public class CompilationUnitTests extends ModifyingResourceTests {
	ICompilationUnit cu;
	ICompilationUnit workingCopy;
	IJavaProject testProject;

public CompilationUnitTests(String name) {
	super(name);
}
public void setUpSuite() throws Exception {
	super.setUpSuite();

	this.testProject = createJavaProject("P", new String[] {"src"}, new String[] {getExternalJCLPathString()}, "bin", "1.5");
	createFolder("/P/src/p");
	createFile(
		"/P/src/p/X.java",
		"\n\n" + 	// package now includes comment (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=93880)
						// => need some empty line at beginning to be able to have cu without any other element (see testGetElementAt())
		"/* some comment */" +
		"package p;\n" +
		"import p2.*;\n" +
		"import p3.Z;\n" +
		"public class X implements Runnable {\n" +
		"  public int f1;\n" +
		"  /** @deprecated\n */" +
		"  protected Object f2;\n" +
		"  private X f3;\n" +
		"  java.lang.String f4;\n" +
		"  int f5, f6, f7;\n" +
		"  @Deprecated\n" +
		"  int f8;\n" +
		"  public class Inner {\n" +
		"    class InnerInner {\n" +
		"    }\n" +
		"  }\n" +
		"  public void foo(Y y) throws IOException {\n" +
		"  }\n" +
		"  protected static Object bar() {\n" +
		"  }\n" +
		"  /** @deprecated\n */" +
		"  private int fred() {\n" +
		"  }\n" +
		"  @Deprecated\n" +
		"  private void fred2() {\n" +
		"  }\n" +
		"  void testIsVarArgs(String s, Object ... args) {\n" +
		"  }\n" +
		"  X(String... s) {\n" +
		"  }\n" +
		"  native void foo2();\n" +
		"  volatile void foo3() {}\n" +
		"  strictfp void foo4() {}\n" +
		"}\n" +
		"/** @deprecated\n */" +
		"interface I {\n" +
		"  int run();\n" +
		"}\n" +
		"interface I2<E> {\n" +
		"}\n" +
		"@Deprecated\n" +
		"interface I3 {\n" +
		"}\n" +
		"class Y<E> implements I2<E> {\n" +
		"}\n" +
		"enum Colors {\n" +
		"  BLUE, WHITE, RED;\n" +
		"}\n" +
		"@interface /*c*/ Annot {\n" +
		"  String field();\n" +
		"}"
	);
	this.cu = getCompilationUnit("/P/src/p/X.java");
}

// Use this static initializer to specify subset for tests
// All specified tests which do not belong to the class are skipped...
static {
//	TESTS_PREFIX = "testGetChildren";
//	TESTS_NAMES = new String[] { "testDefaultFlag1" };
//	TESTS_NUMBERS = new int[] { 13 };
//	TESTS_RANGE = new int[] { 16, -1 };
}
public static Test suite() {
	return buildModelTestSuite(CompilationUnitTests.class);
}
protected void tearDown() throws Exception {
	if (this.workingCopy != null)
		this.workingCopy.discardWorkingCopy();
	super.tearDown();
}
public void tearDownSuite() throws Exception {
	this.deleteProject("P");
	super.tearDownSuite();
}

private ICompilationUnit createWorkingCopy(String source) throws JavaModelException {
	this.workingCopy = getCompilationUnit("/P/src/p/Y.java").getWorkingCopy(new WorkingCopyOwner(){}, null);
	this.workingCopy.getBuffer().setContents(source);
	this.workingCopy.makeConsistent(null);
	return this.workingCopy;
}
/**
 * Create working copy and compute problems.
 *
 * Note that in this case, a complete parse of javadoc comment is performed
 * (ie. done with checkDocComment = true) instead of a "light" parse when
 * problems are not computed.
 *
 * See CompilationUnit#buildStructure() line with comment: // disable javadoc parsing if not computing problems, not resolving and not creating ast
 * and org.eclipse.jdt.internal.compiler.parser.JavadocParser#checkDeprecation(int)
 */
private ICompilationUnit createWorkingCopyComputingProblems(String source) throws JavaModelException {
	this.workingCopy = getWorkingCopy("/P/src/p/Y.java", source, true);
	return this.workingCopy;
}
/**
 * Calls methods that do nothing to ensure code coverage
 */
public void testCodeCoverage() throws JavaModelException {
	this.cu.discardWorkingCopy();
	this.cu.restore();
}
/**
 * Ensures <code>commitWorkingCopy(boolean, IProgressMonitor)</code> throws the correct
 * <code>JavaModelException</code> for a <code>CompilationUnit</code>.
 */
public void testCommitWorkingCopy() {
	try {
		this.cu.commitWorkingCopy(false, null);
	} catch (JavaModelException jme) {
		assertTrue("Incorrect status for committing a CompilationUnit", jme.getStatus().getCode() == IJavaModelStatusConstants.INVALID_ELEMENT_TYPES);
		return;
	}
	assertTrue("A compilation unit should throw an exception is a commit is attempted", false);
}

/*
 * Ensures that the default value for an annotation method is correct.
 */
public void testDefaultValue1() throws CoreException {
	try {
		String cuSource =
			"package p;\n" +
			"public @interface Y {\n" +
			"  public String member() default \"abc\";\n" +
			"}";
		createFile("/P/src/p/Y.java", cuSource);
		IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
		assertMemberValuePairEquals(
			"member=\"abc\"",
			method.getDefaultValue());
	} finally {
		deleteFile("/P/src/p/Y.java");
	}
}

/*
 * Ensures that the default value for an annotation method is correct.
 */
public void testDefaultValue2() throws CoreException {
	try {
		String cuSource =
			"package p;\n" +
			"public @interface Y {\n" +
			"  public int member() default 1;\n" +
			"}";
		createFile("/P/src/p/Y.java", cuSource);
		IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
		assertMemberValuePairEquals(
			"member=(int)1",
			method.getDefaultValue());
	} finally {
		deleteFile("/P/src/p/Y.java");
	}
}

/*
 * Ensures that the default value for an annotation method is correct.
 */
public void testDefaultValue3() throws CoreException {
	try {
		String cuSource =
			"package p;\n" +
			"public @interface Y {\n" +
			"  public int member();\n" +
			"}";
		createFile("/P/src/p/Y.java", cuSource);
		IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
		assertMemberValuePairEquals(
			"<null>",
			method.getDefaultValue());
	} finally {
		deleteFile("/P/src/p/Y.java");
	}
}

/*
 * Ensures that the default value for a non annotation method is correct.
 */
public void testDefaultValue4() throws CoreException {
	try {
		String cuSource =
			"package p;\n" +
			"public class Y {\n" +
			"  public int member() {}\n" +
			"}";
		createFile("/P/src/p/Y.java", cuSource);
		IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
		assertMemberValuePairEquals(
			"<null>",
			method.getDefaultValue());
	} finally {
		deleteFile("/P/src/p/Y.java");
	}
}

/*
 * Ensures that the default value for an annotation method is correct.
 */
public void testDefaultValue5() throws CoreException {
	try {
		String cuSource =
			"package p;\n" +
			"public @interface Y {\n" +
			"  public String member() default \"abc\" + 1;\n" +
			"}";
		createFile("/P/src/p/Y.java", cuSource);
		IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
		assertMemberValuePairEquals(
			"member=<null>",
			method.getDefaultValue());
	} finally {
		deleteFile("/P/src/p/Y.java");
	}
}

/*
 * Ensures that the default value for a constructor doesn't throw a ClassCastException
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=226134 )
 */
public void testDefaultValue6() throws CoreException {
	try {
		String cuSource =
			"package p;\n" +
			"public class Y {\n" +
			"  public Y() {}\n" +
			"}";
		createFile("/P/src/p/Y.java", cuSource);
		IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("Y", new String[0]);
		assertMemberValuePairEquals(
			"<null>",
			method.getDefaultValue());
	} finally {
		deleteFile("/P/src/p/Y.java");
	}
}

/*
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
 * Ensures that the default value (a negative int) for an annotation method is correct.
 */
public void testDefaultValue7() throws CoreException {
	try {
		String cuSource =
			"package p;\n" +
			"public @interface Y {\n" +
			"  public int member() default -1;\n" +
			"}";
		createFile("/P/src/p/Y.java", cuSource);
		IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
		assertMemberValuePairEquals(
			"member=(int)-1",
			method.getDefaultValue());
	} finally {
		deleteFile("/P/src/p/Y.java");
	}
}

/*
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
 * Ensures that the default value (a negative float) for an annotation method is correct.
 */
public void testDefaultValue8() throws CoreException {
	try {
		String cuSource =
			"package p;\n" +
			"public @interface Y {\n" +
			"  public float member() default -1.0f;\n" +
			"}";
		createFile("/P/src/p/Y.java", cuSource);
		IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
		assertMemberValuePairEquals(
			"member=-1.0f",
			method.getDefaultValue());
	} finally {
		deleteFile("/P/src/p/Y.java");
	}
}

/*
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
 * Ensures that the default value (a negative double) for an annotation method is correct.
 */
public void testDefaultValue9() throws CoreException {
	try {
		String cuSource =
			"package p;\n" +
			"public @interface Y {\n" +
			"  public double member() default -1.0;\n" +
			"}";
		createFile("/P/src/p/Y.java", cuSource);
		IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
		assertMemberValuePairEquals(
			"member=(double)-1.0",
			method.getDefaultValue());
	} finally {
		deleteFile("/P/src/p/Y.java");
	}
}

/*
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
 * Ensures that the default value (a negative long) for an annotation method is correct.
 */
public void testDefaultValue10() throws CoreException {
	try {
		String cuSource =
			"package p;\n" +
			"public @interface Y {\n" +
			"  public long member() default -1L;\n" +
			"}";
		createFile("/P/src/p/Y.java", cuSource);
		IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
		assertMemberValuePairEquals(
			"member=-1L",
			method.getDefaultValue());
	} finally {
		deleteFile("/P/src/p/Y.java");
	}
}

/*
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
 * Ensures that the default value (a sign appended Qualified Name Reference) for an annotation method
 * doesn't throw an exception
 */
public void testDefaultValue11() throws CoreException {
	try {
		String cuSource =
			"package p;\n" +
			"interface A {\n" +
			"	static int VAL = 1;\n" +
			"}\n" +
			"public @interface Y {\n" +
			"  public int member() default -A.VAL;\n" +
			"}";
		createFile("/P/src/p/Y.java", cuSource);
		IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
		assertMemberValuePairEquals(
			"member=<null>",
			method.getDefaultValue());
	} finally {
		deleteFile("/P/src/p/Y.java");
	}
}

/*
 * Ensure that the deprecated flag is correctly reported
 * (regression test fo bug 23207 Flags.isDeprecated(IMethod.getFlags()) doesn't work)
 */
public void testDeprecatedFlag01() throws JavaModelException {
	IType type = this.cu.getType("X");
	assertTrue("Type X should not be deprecated", !Flags.isDeprecated(type.getFlags()));
}

/*
 * Ensure that the deprecated flag is correctly reported
 * (regression test fo bug 23207 Flags.isDeprecated(IMethod.getFlags()) doesn't work)
 */
public void testDeprecatedFlag02() throws JavaModelException {
	IType type = this.cu.getType("I");
	assertTrue("Type I should be deprecated", Flags.isDeprecated(type.getFlags()));
}

/*
 * Ensure that the deprecated flag is correctly reported
 * (regression test fo bug 23207 Flags.isDeprecated(IMethod.getFlags()) doesn't work)
 */
public void testDeprecatedFlag03() throws JavaModelException {
	IField field = this.cu.getType("X").getField("f1");
	assertTrue("Field f1 should not be deprecated", !Flags.isDeprecated(field.getFlags()));
}

/*
 * Ensure that the deprecated flag is correctly reported
 * (regression test fo bug 23207 Flags.isDeprecated(IMethod.getFlags()) doesn't work)
 */
public void testDeprecatedFlag04() throws JavaModelException {
	IField field = this.cu.getType("X").getField("f2");
	assertTrue("Field f2 should be deprecated", Flags.isDeprecated(field.getFlags()));
}

/*
 * Ensure that the deprecated flag is correctly reported
 * (regression test fo bug 23207 Flags.isDeprecated(IMethod.getFlags()) doesn't work)
 */
public void testDeprecatedFlag05() throws JavaModelException {
	IMethod method = this.cu.getType("X").getMethod("bar", new String[]{});
	assertTrue("Method bar should not be deprecated", !Flags.isDeprecated(method.getFlags()));
}

/*
 * Ensure that the deprecated flag is correctly reported
 * (regression test fo bug 23207 Flags.isDeprecated(IMethod.getFlags()) doesn't work)
 */
public void testDeprecatedFlag06() throws JavaModelException {
	IMethod method = this.cu.getType("X").getMethod("fred", new String[]{});
	assertTrue("Method fred should be deprecated", Flags.isDeprecated(method.getFlags()));
}

/*
 * Ensure that the deprecated flag is correctly reported
 * (regression test fo bug 89807 Outliner should recognize @Deprecated annotation)
 */
public void testDeprecatedFlag07() throws JavaModelException {
	IType type = this.cu.getType("I3");
	assertTrue("Type I3 should be deprecated", Flags.isDeprecated(type.getFlags()));
}

/*
 * Ensure that the deprecated flag is correctly reported
 * (regression test fo bug 89807 Outliner should recognize @Deprecated annotation)
 */
public void testDeprecatedFlag08() throws JavaModelException {
	IField field = this.cu.getType("X").getField("f8");
	assertTrue("Field f8 should be deprecated", Flags.isDeprecated(field.getFlags()));
}

/*
 * Ensure that the deprecated flag is correctly reported
 * (regression test fo bug 89807 Outliner should recognize @Deprecated annotation)
 */
public void testDeprecatedFlag09() throws JavaModelException {
	IMethod method = this.cu.getType("X").getMethod("fred2", new String[0]);
	assertTrue("Method fred2 should be deprecated", Flags.isDeprecated(method.getFlags()));
}

/*
 * Ensures that the primary type of a cu can be found.
 */
public void testFindPrimaryType1() throws JavaModelException {
	ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java");
	assertElementEquals(
		"Unexpected primary type",
		"X [in X.java [in p [in src [in P]]]]",
		unit.findPrimaryType());
}

/*
 * Ensures that retrieving the content of a compilation whose file has been deleted logs the problem
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=138882 )
 */
public void testFileDeleted() throws CoreException {
	try {
		startLogListening();
		((org.eclipse.jdt.internal.compiler.env.ICompilationUnit) getCompilationUnit("/P/src/p/Deleted.java")).getContents();
		assertLogEquals(
			"Status ERROR: org.eclipse.jdt.core code=4 File not found: \'/P/src/p/Deleted.java\' org.eclipse.core.internal.resources.ResourceException: Resource \'/P/src/p/Deleted.java\' does not exist.\n"
		);
	} finally {
		stopLogListening();
	}
}

/*
 * Ensures that findPrimaryType() doesn't throw an exception if the cu name is invalid.
 * (regression test for bug 120865 ICompilationUnit.findPrimaryType(..) should not throw internal AFE)
 */
public void testFindPrimaryType2() throws JavaModelException {
	ICompilationUnit unit = getPackage("/P/src/p").getCompilationUnit("A.B.java");
	assertNull("Unexpected primary type", unit.findPrimaryType());
}

/*
 * Ensure that the annotations for a type are correct.
 */
public void testAnnotations01() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot\n",
		annotations);
}

/*
 * Ensure that the annotations for a method are correct.
 */
public void testAnnotations02() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"public class Y {\n" +
		"  @MyAnnot\n" +
		"  public void foo() {\n" +
		"  }\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getMethod("foo", new String[0]).getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot\n",
		annotations);
}

/*
 * Ensure that the annotations for a field are correct.
 */
public void testAnnotations03() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"public class Y {\n" +
		"  @MyAnnot\n" +
		"  int field;\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getField("field").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot\n",
		annotations);
}

/*
 * Ensure that the annotations for a package declaration are correct.
 */
public void testAnnotations04() throws CoreException {
	createWorkingCopy(
		"@MyAnnot\n" +
		"package p;"
	);
	IAnnotation[] annotations = this.workingCopy.getPackageDeclaration("p").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot\n",
		annotations);
}

/*
 * Ensure that the annotations for a local variable are correct.
 */
public void testAnnotations05() throws JavaModelException {
	createWorkingCopy(
		"package p;\n" +
		"public class Y {\n" +
		"  void foo() {\n" +
		"    @MyAnnot\n" +
		"    int var1 = 2;\n" +
		"  }\n" +
		"}"
	);
	IAnnotation[] annotations = getLocalVariable(this.workingCopy, "var1 = 2;", "var1").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot\n",
		annotations);
}

/*
 * Ensure that an int member annotation is correct.
 */
public void testAnnotations06() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(intMember=2)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(intMember=(int)2)\n",
		annotations);
}

/*
 * Ensure that a long member annotation is correct.
 */
public void testAnnotations07() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(longMember=123456789L)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(longMember=123456789L)\n",
		annotations);
}

/*
 * Ensure that a float member annotation is correct.
 */
public void testAnnotations08() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(floatMember=1.2f)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(floatMember=1.2f)\n",
		annotations);
}

/*
 * Ensure that a double member annotation is correct.
 */
public void testAnnotations09() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(doubleMember=1.2)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(doubleMember=(double)1.2)\n",
		annotations);
}

/*
 * Ensure that a char member annotation is correct.
 */
public void testAnnotations10() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(charMember='a')\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(charMember=\'a\')\n",
		annotations);
}

/*
 * Ensure that a boolean member annotation is correct.
 */
public void testAnnotations11() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(booleanMember=true)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(booleanMember=true)\n",
		annotations);
}

/*
 * Ensure that a String member annotation is correct.
 */
public void testAnnotations12() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(stringMember=\"abc\")\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(stringMember=\"abc\")\n",
		annotations);
}

/*
 * Ensure that an annotation member annotation is correct.
 */
public void testAnnotations13() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(annotationMember=@MyOtherAnnot(1))\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(annotationMember=@MyOtherAnnot((int)1))\n",
		annotations);
}

/*
 * Ensure that a class literal member annotation is correct.
 */
public void testAnnotations14() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(classLiteralMember=Object.class)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(classLiteralMember=Object.class)\n",
		annotations);
}

/*
 * Ensure that a qualified name member annotation is correct.
 */
public void testAnnotations15() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(qualifiedMember=MyEnum.FIRST)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(qualifiedMember=MyEnum.FIRST)\n",
		annotations);
}

/*
 * Ensure that a array member annotation is correct.
 */
public void testAnnotations16() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(arrayMember={1, 2, 3})\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(arrayMember={(int)1, (int)2, (int)3})\n",
		annotations);
}

/*
 * Ensure that a empty array member annotation is correct.
 */
public void testAnnotations17() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(arrayMember={})\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(arrayMember=[unknown]{})\n",
		annotations);
}

/*
 * Ensure that a qualified annotation is correct
 */
public void testAnnotations18() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@x . y. MyAnnot(x='a', y=false)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@x.y.MyAnnot(x='a', y=false)\n",
		annotations);
}

/*
 * Ensure that a annotation with an unknown member kind is correct
 */
public void testAnnotations19() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(unknown=1 + 2.3)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(unknown=<null>)\n",
		annotations);
}

/*
 * Ensure that a single member annotation is correct
 */
public void testAnnotations20() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(1)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot((int)1)\n",
		annotations);
}

/*
 * Ensure that an heterogeneous array member annotation is correct.
 */
public void testAnnotations21() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(arrayMember={1, 2.3, 1 + 3.4, 'a'})\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(arrayMember=[unknown]{(int)1, (double)2.3, <null>, \'a\'})\n",
		annotations);
}

/*
 * Ensure that an annotation with syntax error is correct.
 */
public void testAnnotations22() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(name=)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(name=<null>)\n",
		annotations);
}

/*
 * Ensure that an heterogeneous array member annotation is correct.
 * (regression test for bug 207445 IMemberValuePair with heterogenous array values should be of kind K_UNKNOWN)
 */
public void testAnnotations23() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(arrayMember={1, \"abc\"})\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(arrayMember=[unknown]{(int)1, \"abc\"})\n",
		annotations);
}

/*
 * Ensure that the annotations for a method parameter are correct.
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=209661)
 */
public void testAnnotations24() throws JavaModelException {
	createWorkingCopy(
		"package p;\n" +
		"public class Y {\n" +
		"  void foo(@MyAnnot int arg1) {\n" +
		"  }\n" +
		"}"
	);
	IAnnotation[] annotations = getLocalVariable(this.workingCopy, "arg1", "arg1").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot\n",
		annotations);
}

/*
 * Ensure that a simple name member annotation is correct.
 */
public void testAnnotations25() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"import static MyEnum.FIRST;\n" +
		"@MyAnnot(simpleMember=FIRST)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(simpleMember=FIRST)\n",
		annotations);
}

/*
 * Ensure that a simple name member annotation with an array {null} value is correct.
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=220940 )
 */
public void testAnnotations26() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(value={null})\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot([unknown]{<null>})\n",
		annotations);
}
/*
 * Ensure that the recovered annotation is correct
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=228464 )
 */
public void testAnnotations27() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"@MyAnnot(name=)\n" +
		"public class Y {\n" +
		"}"
	);
	IAnnotation[] annotations = this.workingCopy.getType("Y").getAnnotations();
	assertAnnotationsEqual(
		"@MyAnnot(name=<null>)\n",
		annotations);
}
/*
 * Ensures that getFullyQualifiedName() behaves correctly for a top level source type
 */
public void testGetFullyQualifiedName1() {
	IType type = getCompilationUnit("/P/src/p/X.java").getType("X");
	assertEquals("p.X", type.getFullyQualifiedName());
}

/*
 * Ensures that getFullyQualifiedName() behaves correctly for a top level source type
 */
public void testGetFullyQualifiedName2() {
	IType type = getCompilationUnit("/P/src/X.java").getType("X");
	assertEquals("X", type.getFullyQualifiedName());
}

/*
 * Ensures that getFullyQualifiedName() behaves correctly for a member type
 */
public void testGetFullyQualifiedName3() {
	IType type = getCompilationUnit("/P/src/p/X.java").getType("X").getType("Member");
	assertEquals("p.X$Member", type.getFullyQualifiedName());
}

/*
 * Ensures that getFullyQualifiedName() behaves correctly for a local type
 */
public void testGetFullyQualifiedName4() {
	IType type = getCompilationUnit("/P/src/p/X.java").getType("X").getMethod("foo", new String[0]).getType("Local", 1);
	assertEquals("p.X$Local", type.getFullyQualifiedName());
}

/*
 * Ensures that getFullyQualifiedName('.') behaves correctly for a top level source type
 */
public void testGetFullyQualifiedName5() {
	IType type = getCompilationUnit("/P/src/p/X.java").getType("X");
	assertEquals("p.X", type.getFullyQualifiedName('.'));
}

/*
 * Ensures that getFullyQualifiedName('.') behaves correctly for a top level source type
 */
public void testGetFullyQualifiedName6() {
	IType type = getCompilationUnit("/P/src/X.java").getType("X");
	assertEquals("X", type.getFullyQualifiedName('.'));
}

/*
 * Ensures that getFullyQualifiedName() behaves correctly for a member type
 */
public void testGetFullyQualifiedName7() {
	IType type = getCompilationUnit("/P/src/p/X.java").getType("X").getType("Member");
	assertEquals("p.X.Member", type.getFullyQualifiedName('.'));
}

/*
 * Ensures that getFullyQualifiedName() behaves correctly for a local type
 */
public void testGetFullyQualifiedName8() {
	IType type = getCompilationUnit("/P/src/p/X.java").getType("X").getMethod("foo", new String[0]).getType("Local", 1);
	assertEquals("p.X.Local", type.getFullyQualifiedName('.'));
}

/*
 * Ensures that the categories for a class are correct.
 */
public void testGetCategories01() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"/**\n" +
		" * @category test\n" +
		" */\n" +
		"public class Y {\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"test\n",
		categories);
}

/*
 * Ensures that the categories for an interface are correct.
 */
public void testGetCategories02() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"/**\n" +
		" * @category test\n" +
		" */\n" +
		"public interface Y {\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"test\n",
		categories);
}

/*
 * Ensures that the categories for an enumeration type are correct.
 */
public void testGetCategories03() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"/**\n" +
		" * @category test\n" +
		" */\n" +
		"public enum Y {\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"test\n",
		categories);
}

/*
 * Ensures that the categories for an annotation type type are correct.
 */
public void testGetCategories04() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"/**\n" +
		" * @category test\n" +
		" */\n" +
		"public @interface Y {\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"test\n",
		categories);
}

/*
 * Ensures that the categories for a method are correct.
 */
public void testGetCategories05() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category test\n" +
		"   */\n" +
		"  void foo() {}\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getMethod("foo", new String[0]).getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"test\n",
		categories);
}

/*
 * Ensures that the categories for a constructor are correct.
 */
public void testGetCategories06() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category test\n" +
		"   */\n" +
		"  public Y() {}\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getMethod("Y", new String[0]).getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"test\n",
		categories);
}

/*
 * Ensures that the categories for a field are correct.
 */
public void testGetCategories07() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category test\n" +
		"   */\n" +
		"  int field;\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getField("field").getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"test\n",
		categories);
}

/*
 * Ensures that the categories for a member type are correct.
 */
public void testGetCategories08() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category test\n" +
		"   */\n" +
		"  class Member {}\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getType("Member").getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"test\n",
		categories);
}

/*
 * Ensures that the categories for an element that has no categories is empty.
 */
public void testGetCategories09() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"  */\n" +
		"  void foo() {}\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getMethod("foo", new String[0]).getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"",
		categories);
}

/*
 * Ensures that the categories for an element that has multiple category tags is correct.
 */
public void testGetCategories10() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category test1\n" +
		"   * @category test2\n" +
		"   */\n" +
		"  void foo() {}\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getMethod("foo", new String[0]).getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"test1\n" +
		"test2\n",
		categories);
}

/*
 * Ensures that the categories for an element that has multiple categories for one category tag is correct.
 */
public void testGetCategories11() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category test1 test2\n" +
		"   */\n" +
		"  void foo() {}\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getMethod("foo", new String[0]).getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"test1\n" +
		"test2\n",
		categories);
}
public void testGetCategories12() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category test1 test2\n" +
		"   */\n" +
		"  void foo() {}\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getMethod("foo", new String[0]).getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"test1\n" +
		"test2\n",
		categories);
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=125676
public void testGetCategories13() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category " +
		"	 *		test\n" +
		"   */\n" +
		"  void foo() {}\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getMethod("foo", new String[0]).getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"",
		categories);
}
public void testGetCategories14() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category" +
		"	 *		test\n" +
		"   */\n" +
		"  void foo() {}\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getMethod("foo", new String[0]).getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"",
		categories);
}
public void testGetCategories15() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category test1" +
		"	 *		test2\n" +
		"   */\n" +
		"  void foo() {}\n" +
		"}"
	);
	String[] categories = this.workingCopy.getType("Y").getMethod("foo", new String[0]).getCategories();
	assertStringsEqual(
		"Unexpected categories",
		"test1\n",
		categories);
}

/*
 * Ensures that the children of a type for a given category are correct.
 */
public void testGetChildrenForCategory01() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category test\n" +
		"   */\n" +
		"  int field;\n" +
		"  /**\n" +
		"   * @category test\n" +
		"   */\n" +
		"  void foo1() {}\n" +
		"  /**\n" +
		"   * @category test\n" +
		"   */\n" +
		"  void foo2() {}\n" +
		"  /**\n" +
		"   * @category other\n" +
		"   */\n" +
		"  void foo3() {}\n" +
		"}"
	);
	IJavaElement[] children = this.workingCopy.getType("Y").getChildrenForCategory("test");
	assertElementsEqual(
		"Unexpected children",
		"field [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]\n" +
		"foo1() [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]\n" +
		"foo2() [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]",
		children);
}

/*
 * Ensures that the children of a type for a given category are correct.
 */
public void testGetChildrenForCategory02() throws CoreException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category test1 test2\n" +
		"   */\n" +
		"  class Member {}\n" +
		"  /**\n" +
		"   * @category test1\n" +
		"   */\n" +
		"  void foo1() {}\n" +
		"  /**\n" +
		"   * @category test2\n" +
		"   */\n" +
		"  void foo2() {}\n" +
		"}"
	);
	IJavaElement[] children = this.workingCopy.getType("Y").getChildrenForCategory("test1");
	assertElementsEqual(
		"Unexpected children",
		"Member [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]\n" +
		"foo1() [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]",
		children);
}
public void testGetChildrenForCategory03() throws CoreException, IOException {
	createWorkingCopyComputingProblems(
		"package p;\n" +
		"public class Y {\n" +
		"  /**\n" +
		"   * @category fields test all\n" +
		"   */\n" +
		"  int field;\n" +
		"  /**\n" +
		"   * @category methods test all\n" +
		"   */\n" +
		"  void foo1() {}\n" +
		"  /**\n" +
		"   * @category methods test all\n" +
		"   */\n" +
		"  void foo2() {}\n" +
		"  /**\n" +
		"   * @category methods other all\n" +
		"   */\n" +
		"  void foo3() {}\n" +
		"}"
	);
	IJavaElement[] tests  = this.workingCopy.getType("Y").getChildrenForCategory("test");
	assertElementsEqual(
		"Unexpected children",
		"field [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]\n" +
		"foo1() [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]\n" +
		"foo2() [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]",
		tests);
	IJavaElement[] methods = this.workingCopy.getType("Y").getChildrenForCategory("methods");
	assertElementsEqual(
		"Unexpected children",
		"foo1() [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]\n" +
		"foo2() [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]\n" +
		"foo3() [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]",
		methods);
	IJavaElement[] others = this.workingCopy.getType("Y").getChildrenForCategory("other");
	assertElementsEqual(
		"Unexpected children",
		"foo3() [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]",
		others);
	IJavaElement[] all = this.workingCopy.getType("Y").getChildrenForCategory("all");
	assertElementsEqual(
		"Unexpected children",
		"field [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]\n" +
		"foo1() [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]\n" +
		"foo2() [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]\n" +
		"foo3() [in Y [in [Working copy] Y.java [in p [in src [in P]]]]]",
		all);
}

/**
 * Ensures <code>getContents()</code> returns the correct value
 * for a <code>CompilationUnit</code> that is not present
 */
public void testGetContentsForNotPresent() {
	CompilationUnit compilationUnit = (CompilationUnit)getCompilationUnit("/P/src/p/Absent.java");

	assertSourceEquals("Unexpected contents for non present cu", "", new String(compilationUnit.getContents()));
}
/*
 * Ensures that getContents() doesn't throw a NullPointerException for a non-existing cu on a remote file system
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=213427 )
 */
public void testGetContentsForNotPresentRemote() throws CoreException, URISyntaxException {
	IWorkspace workspace = getWorkspace();
	IProject project = workspace.getRoot().getProject("Foo");
	try {
		IProjectDescription description = workspace.newProjectDescription("Foo");
		description.setLocationURI(new URI("jdt.core.test:///foo"));
		project.create(description, null);
		CompilationUnit remoteCU = (CompilationUnit) getCompilationUnit("/Foo/X.java");
		Exception actual = null;
		try {
			remoteCU.getContents();
		} catch (Exception e) {
			actual = e;
		}
		assertExceptionEquals(
			"Unexpected exception",
			"<null>",
			actual);
	} finally {
		project.delete(true, null);
	}
 }
/**
 * Tests Java element retrieval via source position
 */
public void testGetElementAt() throws JavaModelException {
	IType type = this.cu.getType("X");
	ISourceRange sourceRange= type.getSourceRange();
	//ensure that we are into the body of the type
	IJavaElement element=
		this.cu.getElementAt(sourceRange.getOffset() + type.getElementName().length() + 1);
	assertTrue("Should have found a type", element instanceof IType);
	assertEquals(
		"Should have found X",
		"X",
		element.getElementName());
	//ensure that null is returned if there is no element other than the compilation
 	//unit itself at the given position
 	element= this.cu.getElementAt(this.cu.getSourceRange().getOffset() + 1);
 	assertEquals("Should have not found any element", null, element);
}
/**
 * Tests import declararion retrieval via source position.
 * (regression test for bug 14331 ICompilationUnit.getElementAt dos not find import decl)
 */
public void testGetElementAt2() throws JavaModelException {
	IImportContainer container = this.cu.getImportContainer();
	ISourceRange sourceRange= container.getSourceRange();
	//ensure that we are inside the import container
	IJavaElement element= this.cu.getElementAt(sourceRange.getOffset() + 1);
	assertTrue("Should have found an import", element instanceof IImportDeclaration);
	assertEquals(
		"Import not found",
		"p2.*",
		 element.getElementName());
}
/*
 * Ensures that the right field is returnd in a muti-declaration field.
 */
public void testGetElementAt3() throws JavaModelException {
	int fieldPos = this.cu.getSource().indexOf("f5");
	IJavaElement element= this.cu.getElementAt(fieldPos);
	assertEquals(
		"Unexpected field found",
		this.cu.getType("X").getField("f5"),
		 element);
}
/*
 * Ensures that the right field is returnd in a muti-declaration field.
 */
public void testGetElementAt4() throws JavaModelException {
	int fieldPos = this.cu.getSource().indexOf("f6");
	IJavaElement element= this.cu.getElementAt(fieldPos);
	assertEquals(
		"Unexpected field found",
		this.cu.getType("X").getField("f6"),
		 element);
}
/*
 * Ensures that the right field is returnd in a muti-declaration field.
 */
public void testGetElementAt5() throws JavaModelException {
	int fieldPos = this.cu.getSource().indexOf("f7");
	IJavaElement element= this.cu.getElementAt(fieldPos);
	assertEquals(
		"Unexpected field found",
		this.cu.getType("X").getField("f7"),
		 element);
}
/*
 * Ensures that the right field is returned in a muti-declaration field.
 */
public void testGetElementAt6() throws JavaModelException {
	int fieldPos = this.cu.getSource().indexOf("int f5");
	IJavaElement element= this.cu.getElementAt(fieldPos);
	assertEquals(
		"Unexpected field found",
		this.cu.getType("X").getField("f5"),
		element);
}
/*
 * Ensures that the right type is returnd if an annotation type as a comment in its header.
 */
public void testGetElementAt7() throws JavaModelException {
	int fieldPos = this.cu.getSource().indexOf("Annot");
	IJavaElement element= this.cu.getElementAt(fieldPos);
	assertEquals(
		"Unexpected type found",
		this.cu.getType("Annot"),
		element);
}
/**
 * Ensures that correct number of fields with the correct names, modifiers, signatures
 * and declaring types exist in a type.
 */
public void testGetFields() throws JavaModelException {
	IType type = this.cu.getType("X");
	IField[] fields= type.getFields();
	String[] fieldNames = new String[] {"f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8"};
	String[] flags = new String[] {"public", "protected", "private", "", "", "", "", ""};
	String[] signatures = new String[] {"I", "QObject;", "QX;", "Qjava.lang.String;", "I", "I", "I", "I"};
	assertEquals("Wrong number of fields returned",  fieldNames.length, fields.length);
	for (int i = 0; i < fields.length; i++) {
		assertEquals("Incorrect name for the " + i + " field", fieldNames[i], fields[i].getElementName());
		String mod= Flags.toString(fields[i].getFlags());
		assertEquals("Unexpected modifier for " + fields[i].getElementName(), flags[i], mod);
		assertEquals("Unexpected type signature for " + fields[i].getElementName(), signatures[i], fields[i].getTypeSignature());
		assertEquals("Unexpected declaring type for " + fields[i].getElementName(), type, fields[i].getDeclaringType());
		assertTrue("Field should exist " + fields[i], fields[i].exists());
	}
}
/**
 * Ensure that import declaration handles are returned from the
 * compilation unit.
 * Checks non-existant handle, on demand and not.
 */
public void testGetImport() {
	IImportDeclaration imprt = this.cu.getImport("java.lang");
	assertTrue("Import should not exist " + imprt, !imprt.exists());

	imprt = this.cu.getImport("p2.*");
	assertTrue("Import should exist " + imprt, imprt.exists());

	imprt = this.cu.getImport("p3.Z");
	assertTrue("Import should exist " + imprt, imprt.exists());
}
/**
 * Ensures that correct number of imports with the correct names
 * exist in "GraphicsTest" compilation unit.
 */
public void testGetImports() throws JavaModelException {
	IImportDeclaration[] imprts = this.cu.getImports();
	IImportContainer container= this.cu.getImportContainer();
	String[] importNames = new String[] {"p2.*", "p3.Z"};

	assertEquals("Wrong number of imports returned", importNames.length, imprts.length);
	for (int i = 0; i < imprts.length; i++) {
		assertTrue("Incorrect name for the type in this position: " + imprts[i].getElementName(), imprts[i].getElementName().equals(importNames[i]));
		assertTrue("Import does not exist " + imprts[i], imprts[i].exists());
		if (i == 0) {
			assertTrue("Import is not on demand " + imprts[i], imprts[i].isOnDemand());
			assertTrue("Import should be non-static " + imprts[i], imprts[i].getFlags() == Flags.AccDefault);
		} else {
			assertTrue("Import is on demand " + imprts[i], !imprts[i].isOnDemand());
			assertTrue("Import should be non-static " + imprts[i], imprts[i].getFlags() == Flags.AccDefault);
		}
		assertTrue("Container import does not equal import", container.getImport(imprts[i].getElementName()).equals(imprts[i]));
	}

	assertTrue("Import container must exist and have children", container.exists() && container.hasChildren());
	ISourceRange containerRange= container.getSourceRange();
	assertEquals(
		"Offset container range not correct",
		imprts[0].getSourceRange().getOffset(),
		containerRange.getOffset());
	assertEquals(
		"Length container range not correct",
		imprts[imprts.length-1].getSourceRange().getOffset() + imprts[imprts.length-1].getSourceRange().getLength(),
		containerRange.getOffset() + containerRange.getLength());
	assertSourceEquals("Source not correct",
		"import p2.*;\n" +
		"import p3.Z;",
		container.getSource());

}
/**
 * Ensure that type handles are returned from the
 * compilation unit for an inner type.
 */
public void testGetInnerTypes() throws JavaModelException {
	IType type1 = this.cu.getType("X");
	assertTrue("X type should have children", type1.hasChildren());
	assertTrue("X type superclass name should be null", type1.getSuperclassName() == null);
	String[] superinterfaceNames= type1.getSuperInterfaceNames();
	assertEquals("X type should have one superinterface", 1, superinterfaceNames.length);
	assertEquals("Unexpected super interface name", "Runnable", superinterfaceNames[0]);
	assertEquals("Fully qualified name of the type is incorrect", "p.X", type1.getFullyQualifiedName());
	IType type2 = type1.getType("Inner");
	superinterfaceNames = type2.getSuperInterfaceNames();
	assertEquals("X$Inner type should not have a superinterface", 0, superinterfaceNames.length);
	assertEquals("Fully qualified name of the inner type is incorrect", "p.X$Inner", type2.getFullyQualifiedName());
	assertEquals("Declaring type of the inner type is incorrect", type1, type2.getDeclaringType());
	IType type3 = type2.getType("InnerInner");
	assertTrue("InnerInner type should not have children", !type3.hasChildren());
}
/*
 * Ensures that the key for a top level type is correct
 */
public void testGetKey1() {
	IType type = this.cu.getType("X");
	assertEquals("Lp/X;", type.getKey());
}
/*
 * Ensures that the key for a member type is correct
 */
public void testGetKey2() {
	IType type = this.cu.getType("X").getType("Inner");
	assertEquals("Lp/X$Inner;", type.getKey());
}
/*
 * Ensures that the key for a secondary type is correct
 */
public void testGetKey3() {
	IType type = this.cu.getType("I");
	assertEquals("Lp/X~I;", type.getKey());
}
/*
 * Ensures that the key for an anonymous type is correct
 */
public void testGetKey4() {
	IType type = this.cu.getType("X").getMethod("foo", new String[0]).getType("", 1);
	assertEquals("Lp/X$1;", type.getKey());
}
/**
 * Ensures that a method has the correct return type, parameters and exceptions.
 */
public void testGetMethod1() throws JavaModelException {
	IType type = this.cu.getType("X");
	IMethod foo = type.getMethod("foo", new String[]{"QY;"});
	String[] exceptionTypes= foo.getExceptionTypes();
	assertEquals("Wrong number of exception types", 1, exceptionTypes.length);
	assertEquals("Unxepected exception type", "QIOException;", exceptionTypes[0]);
	assertEquals("Wrong return type", "V", foo.getReturnType());
	String[] parameterNames = foo.getParameterNames();
	assertEquals("Wrong number of parameter names", 1, parameterNames.length);
	assertEquals("Unexpected parameter name", "y", parameterNames[0]);
}
/**
 * Ensures that a method has the correct AccVarargs flag set.
 */
public void testGetMethod2() throws JavaModelException {
	IType type = this.cu.getType("X");
	IMethod method = type.getMethod("testIsVarArgs", new String[]{"QString;", "[QObject;"});
	assertTrue("Should have the AccVarargs flag set", Flags.isVarargs(method.getFlags()));
}
/**
 * Ensures that a constructor has the correct AccVarargs flag set.
 * (regression test for bug 77422 [1.5] ArrayIndexOutOfBoundsException with vararg constructor of generic superclass)
 */
public void testGetMethod3() throws JavaModelException {
	IType type = this.cu.getType("X");
	IMethod method = type.getMethod("X", new String[]{"[QString;"});
	assertTrue("Should have the AccVarargs flag set", Flags.isVarargs(method.getFlags()));
}
/**
 * Ensures that correct number of methods with the correct names and modifiers
 * exist in a type.
 */
public void testGetMethods() throws JavaModelException {
	IType type = this.cu.getType("X");
	IMethod[] methods= type.getMethods();
	String[] methodNames = new String[] {"foo", "bar", "fred", "fred2", "testIsVarArgs", "X", "foo2", "foo3", "foo4"};
	String[] flags = new String[] {"public", "protected static", "private", "private", "", "", "native", "volatile", "strictfp"};
	assertEquals("Wrong number of methods returned", methodNames.length, methods.length);
	for (int i = 0; i < methods.length; i++) {
		assertEquals("Incorrect name for the " + i + " method", methodNames[i], methods[i].getElementName());
		int modifiers = methods[i].getFlags() & ~Flags.AccVarargs;
		String mod= Flags.toString(modifiers);
		assertEquals("Unexpected modifier for " + methods[i].getElementName(), flags[i], mod);
		assertTrue("Method does not exist " + methods[i], methods[i].exists());
	}
}
/**
 * Ensures that correct modifiers are reported for a method in an interface.
 */
public void testCheckInterfaceMethodModifiers() throws JavaModelException {
	IType type = this.cu.getType("I");
	IMethod method = type.getMethod("run", new String[0]);
	String expectedModifiers = "";
	String modifiers = Flags.toString(method.getFlags() & ~Flags.AccVarargs);
	assertEquals("Expected modifier for " + method.getElementName(), expectedModifiers, modifiers);
}
/*
 * Ensures that IType#getSuperInterfaceTypeSignatures() is correct for a source type.
 */
public void testGetSuperInterfaceTypeSignatures() throws JavaModelException {
	IType type = this.cu.getType("Y");
	assertStringsEqual(
		"Unexpected signatures",
		"QI2<QE;>;\n",
		type.getSuperInterfaceTypeSignatures());
}
/**
 * Ensure that the same element is returned for the primary element of a
 * compilation unit.
 */
public void testGetPrimary() {
	IJavaElement primary = this.cu.getPrimaryElement();
	assertEquals("Primary element for a compilation unit should be the same", this.cu, primary);
	primary = this.cu.getPrimary();
	assertEquals("Primary for a compilation unit should be the same", this.cu, primary);

}
/*
 * Ensures that the occurrence count for an initializer is correct
 */
public void testGetOccurrenceCount01() {
	IInitializer initializer = this.cu.getType("X").getInitializer(2);
	assertEquals("Unexpected occurrence count", 2, initializer.getOccurrenceCount());
}
/*
 * Ensures that the occurrence count for an anonymous type is correct
 */
public void testGetOccurrenceCount02() {
	IType type = this.cu.getType("X").getMethod("foo", new String[]{"QY;"}).getType("", 3);
	assertEquals("Unexpected occurrence count", 3, type.getOccurrenceCount());
}
/**
 * Ensures that correct number of package declarations with the correct names
 * exist a compilation unit.
 */
public void testGetPackages() throws JavaModelException {
	IPackageDeclaration[] packages = this.cu.getPackageDeclarations();
	String packageName = "p";
	assertEquals("Wrong number of packages returned", 1, packages.length);
	assertEquals("Wrong package declaration returned: ", packageName, packages[0].getElementName());
}
/**
 * Ensure that type handles are returned from the
 * compilation unit.
 * Checks non-existant handle and existing handles.
 */
public void testGetType() {
	IType type = this.cu.getType("someType");
	assertTrue("Type should not exist " + type, !type.exists());

	type = this.cu.getType("X");
	assertTrue("Type should exist " + type, type.exists());

	type = this.cu.getType("I"); // secondary type
	assertTrue("Type should exist " + type, type.exists());
}
/*
 * Ensures that getTypeQualifiedName() behaves correctly for a top level source type
 */
public void testGetTypeQualifiedName1() {
	IType type = getCompilationUnit("/P/src/p/X.java").getType("X");
	assertEquals("X", type.getTypeQualifiedName());
}

/*
 * Ensures that getTypeQualifiedName() behaves correctly for a top level source type
 */
public void testGetTypeQualifiedName2() {
	IType type = getCompilationUnit("/P/src/X.java").getType("X");
	assertEquals("X", type.getTypeQualifiedName());
}

/*
 * Ensures that getTypeQualifiedName() behaves correctly for a member type
 */
public void testGetTypeQualifiedName3() {
	IType type = getCompilationUnit("/P/src/p/X.java").getType("X").getType("Member");
	assertEquals("X$Member", type.getTypeQualifiedName());
}

/*
 * Ensures that getTypeQualifiedName() behaves correctly for a local type
 */
public void testGetTypeQualifiedName4() {
	IType type = getCompilationUnit("/P/src/p/X.java").getType("X").getMethod("foo", new String[0]).getType("Local", 1);
	assertEquals("X$Local", type.getTypeQualifiedName());
}

/*
 * Ensures that getTypeQualifiedName('.') behaves correctly for a top level source type
 */
public void testGetTypeQualifiedName5() {
	IType type = getCompilationUnit("/P/src/p/X.java").getType("X");
	assertEquals("X", type.getTypeQualifiedName('.'));
}

/*
 * Ensures that getTypeQualifiedName('.') behaves correctly for a top level source type
 */
public void testGetTypeQualifiedName6() {
	IType type = getCompilationUnit("/P/src/X.java").getType("X");
	assertEquals("X", type.getTypeQualifiedName('.'));
}

/*
 * Ensures that getTypeQualifiedName() behaves correctly for a member type
 */
public void testGetTypeQualifiedName7() {
	IType type = getCompilationUnit("/P/src/p/X.java").getType("X").getType("Member");
	assertEquals("X.Member", type.getTypeQualifiedName('.'));
}

/*
 * Ensures that getTypeQualifiedName() behaves correctly for a local type
 */
public void testGetTypeQualifiedName8() {
	IType type = getCompilationUnit("/P/src/p/X.java").getType("X").getMethod("foo", new String[0]).getType("Local", 1);
	assertEquals("X.Local", type.getTypeQualifiedName('.'));
}
/**
 * Ensures that correct number of types with the correct names and modifiers
 * exist in a compilation unit.
 */
public void testGetTypes() throws JavaModelException {
	IType[] types = this.cu.getTypes();
	String[] typeNames = new String[] {"X", "I", "I2", "I3", "Y", "Colors", "Annot"};
	String[] flags = new String[] {"public", "", "", "", "", "", ""};
	boolean[] isClass = new boolean[] {true, false, false, false, true, false, false};
	boolean[] isInterface = new boolean[] {false, true, true, true, false, false, true};
	boolean[] isAnnotation = new boolean[] {false, false, false, false, false, false, true};
	boolean[] isEnum = new boolean[] {false, false, false, false, false, true, false};
	String[] superclassName = new String[] {null, null, null, null, null, null, null};
	String[] superclassType = new String[] {null, null, null, null, null, null, null};
	String[][] superInterfaceNames = new String[][] {
			new String[] {"Runnable"}, new String[0], new String[0], new String[0], new String[] {"I2<E>"}, new String[0], new String[0]
	};
	String[][] superInterfaceTypes = new String[][] {
			new String[] {"QRunnable;"}, new String[0], new String[0], new String[0], new String[] {"QI2<QE;>;"}, new String[0], new String[0]
	};
	String[][] formalTypeParameters = new String[][] {
		new String[0], new String[0], new String[] {"E"}, new String[0], new String[] {"E"}, new String[0], new String[0]
	};

	assertEquals("Wrong number of types returned", typeNames.length, types.length);
	for (int i = 0; i < types.length; i++) {
		assertEquals("Incorrect name for the " + i + " type", typeNames[i], types[i].getElementName());
		String mod= Flags.toString(types[i].getFlags());
		assertEquals("Unexpected modifier for " + types[i].getElementName(), flags[i], mod);
		assertTrue("Type does not exist " + types[i], types[i].exists());
		assertEquals("Incorrect isClass for the " + i + " type", isClass[i], types[i].isClass());
		assertEquals("Incorrect isInterface for the " + i + " type", isInterface[i], types[i].isInterface());
		assertEquals("Incorrect isAnnotation for the " + i + " type", isAnnotation[i], types[i].isAnnotation());
		assertEquals("Incorrect isEnum for the " + i + " type", isEnum[i], types[i].isEnum());
		assertEquals("Incorrect superclassName for the " + i + " type", superclassName[i], types[i].getSuperclassName());
		assertEquals("Incorrect superclassType for the " + i + " type", superclassType[i], types[i].getSuperclassTypeSignature());
		assertEquals("Incorrect superInterfaceNames for the " + i + " type", superInterfaceNames[i].length, types[i].getSuperInterfaceNames().length);
		assertEquals("Incorrect superInterfaceTypes for the " + i + " type", superInterfaceTypes[i].length, types[i].getSuperInterfaceTypeSignatures().length);
		assertEquals("Incorrect formalTypeParameters for the " + i + " type", formalTypeParameters[i].length, types[i].getTypeParameters().length);
	}
}
/**
 * Ensures that a compilation unit has children.
 */
public void testHasChildren() throws JavaModelException {
	this.cu.close();
	assertTrue("A closed compilation unit should have children", this.cu.hasChildren());
	this.cu.getChildren();
	assertTrue("The compilation unit should have children", this.cu.hasChildren());
}
/**
 * Ensures that a compilation unit's resource has not changed.
 */
public void testHasResourceChanged() {
	assertTrue(
		"A compilation unit's resource should not have changed",
		!this.cu.hasResourceChanged());
}
/*
 * Ensures that hasChildren doesn't return true for an import container that doesn't exist
 * (regression test for bug 76761 [model] ImportContainer.hasChildren() should not return true
 */
public void testImportContainerHasChildren() throws JavaModelException {
	IImportContainer importContainer = getCompilationUnit("/Test/DoesNotExist.java").getImportContainer();
	boolean gotException = false;
	try {
		importContainer.hasChildren();
	} catch (JavaModelException e) {
		gotException = e.isDoesNotExist();
	}
	assertTrue("Should get a not present exception", gotException);
}
/*
 * Ensures that isEnumConstant returns true for a field representing an enum constant.
 */
public void testIsEnumConstant1() throws JavaModelException {
	IField field = this.cu.getType("Colors").getField("BLUE");
	assertTrue("Colors#BLUE should be an enum constant", field.isEnumConstant());
}
/*
 * Ensures that isEnumConstant returns false for a field that is not representing an enum constant.
 */
public void testIsEnumConstant2() throws JavaModelException {
	IField field = this.cu.getType("X").getField("f1");
	assertTrue("X#f1 should not be an enum constant", !field.isEnumConstant());
}
/*
 * Ensure that the utility method Util.#getNameWithoutJavaLikeExtension(String) works as expected
 * (regression test for bug 107735 StringIndexOutOfBoundsException in Util.getNameWithoutJavaLikeExtension())
 */
public void testNameWithoutJavaLikeExtension() {
	String name = Util.getNameWithoutJavaLikeExtension("Test.aj");
	assertEquals("Unepected name without extension", "Test.aj", name);
}
/**
 * Ensures that a compilation unit that does not exist responds
 * false to #exists() and #isOpen()
 */
public void testNotPresent1() {
	ICompilationUnit compilationUnit = ((IPackageFragment)this.cu.getParent()).getCompilationUnit("DoesNotExist.java");
	assertTrue("CU should not be open", !compilationUnit.isOpen());
	assertTrue("CU should not exist", !compilationUnit.exists());
	assertTrue("CU should still not be open", !compilationUnit.isOpen());
}
/**
 * Ensures that a compilation unit that does not exist
 * (because it is a child of a jar package fragment)
 * responds false to #exists() and #isOpen()
 * (regression test for PR #1G2RKD2)
 */
public void testNotPresent2() throws CoreException {
	ICompilationUnit compilationUnit = getPackageFragment("P", getExternalJCLPathString(), "java.lang").getCompilationUnit("DoesNotExist.java");
	assertTrue("CU should not be open", !compilationUnit.isOpen());
	assertTrue("CU should not exist", !compilationUnit.exists());
	assertTrue("CU should still not be open", !compilationUnit.isOpen());
}

/*
 * Ensure that the absence of visibility flags is correctly reported as package default
 * (regression test fo bug 127213 Flags class missing methods)
 */
public void testPackageDefaultFlag1() throws JavaModelException {
	IField field = this.cu.getType("X").getField("f4");
	assertTrue("X#f4 should be package default", Flags.isPackageDefault(field.getFlags()));
}

/*
 * Ensure that the presence of a visibility flags is correctly reported as non package default
 * (regression test fo bug 127213 Flags class missing methods)
 */
public void testPackageDefaultFlag2() throws JavaModelException {
	IType type = this.cu.getType("X");
	assertTrue("X should not be package default", !Flags.isPackageDefault(type.getFlags()));
}

/*
 * Ensure that the presence of a visibility flags as well as the deprecated flag is correctly reported as non package default
 * (regression test fo bug 127213 Flags class missing methods)
 */
public void testPackageDefaultFlag3() throws JavaModelException {
	IField field = this.cu.getType("X").getField("f2");
	assertTrue("X#f2 should not be package default", !Flags.isPackageDefault(field.getFlags()));
}

/*
 * Ensure that the absence of a visibility flags and the presence of the deprecated flag is correctly reported as package default
 * (regression test fo bug 127213 Flags class missing methods)
 */
public void testPackageDefaultFlag4() throws JavaModelException {
	IType type = this.cu.getType("I");
	assertTrue("X should be package default", Flags.isPackageDefault(type.getFlags()));
}

/**
 * Ensures that the "structure is known" flag is set for a valid compilation unit.
 */
public void testStructureKnownForCU() throws JavaModelException {
	assertTrue("Structure is unknown for valid CU", this.cu.isStructureKnown());
}
/**
 *  Ensures that the "structure is unknown" flag is set for a non valid compilation unit.
 */
public void testStructureUnknownForCU() throws CoreException {
	try {
		this.createFile(
			"/P/src/p/Invalid.java",
			"@#D(03");
		ICompilationUnit badCU = getCompilationUnit("/P/src/p/Invalid.java");
		assertTrue("Structure is known for an invalid CU", !badCU.isStructureKnown());
	} finally {
		deleteFile("/P/src/p/Invalid.java");
	}
}

/*
 * Ensure that the super flags is correctly reported
 * (regression test fo bug 127213 Flags class missing methods)
 */
public void testSuperFlag1() throws JavaModelException {
	assertTrue("Should contain super flag", Flags.isSuper(Flags.AccSuper));
}

/*
 * Ensure that the super flags is correctly reported
 * (regression test fo bug 127213 Flags class missing methods)
 */
public void testSuperFlag2() throws JavaModelException {
	assertTrue("Should not contain super flag", !Flags.isSuper(Flags.AccDefault));
}

/*
 * Verify fix for bug 73884: [1.5] Unexpected error for class implementing generic interface
 * (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=73884)
 */
public void testBug73884() throws CoreException {
	try {
		String cuSource =
			"package p;\n" +
			"public interface I<T> {\n" +
			"}";
		createFile("/P/src/p/I.java", cuSource);
		ITypeParameter[] typeParameters = getCompilationUnit("/P/src/p/I.java").getType("I").getTypeParameters();
		assertTypeParametersEqual(
			"T\n",
			typeParameters);
	} finally {
		deleteFile("/P/src/p/I.java");
	}
}

/*
 * Ensure that the type parameters for a type are correct.
 */
public void testTypeParameter1() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"public class Y<T> {\n" +
		"}"
	);
	ITypeParameter[] typeParameters = this.workingCopy.getType("Y").getTypeParameters();
	assertTypeParametersEqual(
		"T\n",
		typeParameters);
}

/*
 * Ensure that the type parameters for a type are correct.
 */
public void testTypeParameter2() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"public class Y<T, U> {\n" +
		"}"
	);
	ITypeParameter[] typeParameters = this.workingCopy.getType("Y").getTypeParameters();
	assertTypeParametersEqual(
		"T\n" +
		"U\n",
		typeParameters);
}

/*
 * Ensure that the type parameters for a type are correct.
 */
public void testTypeParameter3() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"public class Y<T extends List> {\n" +
		"}"
	);
	ITypeParameter[] typeParameters = this.workingCopy.getType("Y").getTypeParameters();
	assertTypeParametersEqual(
		"T extends List\n",
		typeParameters);
}

/*
 * Ensure that the type parameters for a type are correct.
 */
public void testTypeParameter4() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"public class Y<T extends List & Runnable & Comparable> {\n" +
		"}"
	);
	ITypeParameter[] typeParameters = this.workingCopy.getType("Y").getTypeParameters();
	assertTypeParametersEqual(
		"T extends List & Runnable & Comparable\n",
		typeParameters);
}

/*
 * Ensure that the type parameters for a method are correct.
 * (regression test for bug 75658 [1.5] SourceElementParser do not compute correctly bounds of type parameter)
 */
public void testTypeParameter5() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"public class Y {\n" +
		"  <T extends List, U extends X & Runnable> void foo() {\n" +
		"  }\n" +
		"}"
	);
	ITypeParameter[] typeParameters = this.workingCopy.getType("Y").getMethod("foo", new String[]{}).getTypeParameters();
	assertTypeParametersEqual(
		"T extends List\n" +
		"U extends X & Runnable\n",
		typeParameters);
}

/*
 * Verify fix for bug 78275: [recovery] NPE in GoToNextPreviousMemberAction with syntax error
 * (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=78275)
 */
public void testBug78275() throws CoreException {
	try {
		String cuSource =
			"public class X {\n" +
			"	void a() {\n" +
			"	     }\n" +
			"	}\n" +
			"	void m() {}\n" +
			"}\n";
		createFile("/P/src/X.java", cuSource);
		IType type = getCompilationUnit("/P/src/X.java").getType("X");
		IInitializer[] initializers = type.getInitializers();
		assertEquals("Invalid number of initializers", 1, initializers.length);
		assertTrue("Invalid length for initializer", initializers[0].getSourceRange().getLength() > 0);
	} finally {
		deleteFile("/P/src/X.java");
	}
}
public void test110172() throws CoreException {
	try {
		String source =
			"/**\n" +
			" * Class X javadoc \n" +
			" */\n" +
			"public class X {\n" +
			"	/**\n" +
			"	 * Javadoc for initializer\n" +
			"	 */\n" +
			"	static {\n" +
			"	}\n" +
			"	\n" +
			"	 /**\n" +
			"	  * Javadoc for field f \n" +
			"	  */\n" +
			"	public int f;\n" +
			"	\n" +
			"	/**\n" +
			"	 * Javadoc for method foo\n" +
			"	 */\n" +
			"	public void foo(int i, long l, String s) {\n" +
			"	}\n" +
			"	\n" +
			"	/**\n" +
			"	 * Javadoc for member type A\n" +
			"	 */\n" +
			"	public class A {\n" +
			"	}\n" +
			"\n" +
			"	/**\n" +
			"	 * Javadoc for constructor X(int)\n" +
			"	 */\n" +
			"	X(int i) {\n" +
			"	}\n" +
			"	\n" +
			"	/**\n" +
			"	 * Javadoc for f3\n" +
			"	 */\n" +
			"	/*\n" +
			"	 * Not a javadoc comment\n" +
			"	 */\n" +
			"	/**\n" +
			"	 * Real javadoc for f3\n" +
			"	 */\n" +
			"	public String f3;\n" +
			"	\n" +
			"	public int f2;\n" +
			"	\n" +
			"	public void foo2() {\n" +
			"	}\n" +
			"	\n" +
			"	public class B {\n" +
			"	}\n" +
			"\n" +
			"	X() {\n" +
			"	}\n" +
			"	\n" +
			"	{\n" +
			"	}\n" +
			"}";
		createFile("/P/src/X.java", source);
		IType type = getCompilationUnit("/P/src/X.java").getType("X");
		IJavaElement[] members = type.getChildren();
		final int length = members.length;
		assertEquals("Wrong number", 11, length);
		for (int i = 0; i < length; i++) {
			final IJavaElement element = members[i];
			assertTrue(element instanceof IMember);
			final ISourceRange javadocRange = ((IMember) element).getJavadocRange();
			final String elementName = element.getElementName();
			if ("f".equals(elementName)) {
				assertNotNull("No javadoc source range", javadocRange);
				final int start = javadocRange.getOffset();
				final int end = javadocRange.getLength() + start - 1;
				String javadocSource = source.substring(start, end);
				assertTrue("Wrong javadoc", javadocSource.indexOf("field f") != -1);
			} else if ("foo".equals(elementName)) {
				assertNotNull("No javadoc source range", javadocRange);
				final int start = javadocRange.getOffset();
				final int end = javadocRange.getLength() + start - 1;
				String javadocSource = source.substring(start, end);
				assertTrue("Wrong javadoc", javadocSource.indexOf("method foo") != -1);
			} else if ("A".equals(elementName)) {
				assertNotNull("No javadoc source range", javadocRange);
				final int start = javadocRange.getOffset();
				final int end = javadocRange.getLength() + start - 1;
				String javadocSource = source.substring(start, end);
				assertTrue("Wrong javadoc", javadocSource.indexOf("member type A") != -1);
			} else if ("X".equals(elementName)) {
				// need treatment for the two constructors
				assertTrue("Not an IMethod", element instanceof IMethod);
				IMethod method = (IMethod) element;
				switch(method.getNumberOfParameters()) {
					case 0 :
						assertNull("Has a javadoc source range", javadocRange);
						break;
					case 1:
						assertNotNull("No javadoc source range", javadocRange);
						final int start = javadocRange.getOffset();
						final int end = javadocRange.getLength() + start - 1;
						String javadocSource = source.substring(start, end);
						assertTrue("Wrong javadoc", javadocSource.indexOf("constructor") != -1);
				}
			} else if ("f3".equals(elementName)) {
				assertNotNull("No javadoc source range", javadocRange);
				final int start = javadocRange.getOffset();
				final int end = javadocRange.getLength() + start - 1;
				String javadocSource = source.substring(start, end);
				assertTrue("Wrong javadoc", javadocSource.indexOf("Real") != -1);
			} else if ("f2".equals(elementName)) {
				assertNull("Has a javadoc source range", javadocRange);
			} else if ("foo2".equals(elementName)) {
				assertNull("Has a javadoc source range", javadocRange);
			} else if ("B".equals(elementName)) {
				assertNull("Has a javadoc source range", javadocRange);
			} else if (element instanceof IInitializer) {
				IInitializer initializer = (IInitializer) element;
				if (Flags.isStatic(initializer.getFlags())) {
					assertNotNull("No javadoc source range", javadocRange);
					final int start = javadocRange.getOffset();
					final int end = javadocRange.getLength() + start - 1;
					String javadocSource = source.substring(start, end);
					assertTrue("Wrong javadoc", javadocSource.indexOf("initializer") != -1);
				} else {
					assertNull("Has a javadoc source range", javadocRange);
				}
			}
		}
	} finally {
		deleteFile("/P/src/X.java");
	}
}
public void test120902() throws CoreException {
	try {
		String source =
			"/**\r\n" +
			" * Toy\r\n" +
			" */\r\n" +
			"public class X {\r\n" +
			"}";
		createFile("/P/src/X.java", source);
		final ICompilationUnit compilationUnit = getCompilationUnit("/P/src/X.java");
		IType type = compilationUnit.getType("X");
		ISourceRange javadocRange = type.getJavadocRange();
		assertNotNull("No source range", javadocRange);
		compilationUnit.getBuffer().setContents("");
		try {
			javadocRange = type.getJavadocRange();
			assertNull("Got a source range", javadocRange);
		} catch (ArrayIndexOutOfBoundsException e) {
			assertFalse("Should not happen", true);
		}
	} finally {
		deleteFile("/P/src/X.java");
	}
}

public void testApplyEdit() throws CoreException {
	try {
		String source =
			"public class X {\n" +
			"}\n";
		createFile("/P/src/X.java", source);
		ICompilationUnit compilationUnit = getCompilationUnit("/P/src/X.java");

		ReplaceEdit edit= new ReplaceEdit(0, 6, "private");

		UndoEdit undoEdit= compilationUnit.applyTextEdit(edit, null);

		String newSource =
			"private class X {\n" +
			"}\n";

		assertEquals(newSource, compilationUnit.getSource());

		compilationUnit.applyTextEdit(undoEdit, null);

		assertEquals(source, compilationUnit.getSource());
	} finally {
		deleteFile("/P/src/X.java");
	}
}

public void testApplyEdit2() throws CoreException {
	try {
		String source =
			"public class X {\n" +
			"}\n";
		createFile("/P/src/X.java", source);
		ICompilationUnit compilationUnit = getCompilationUnit("/P/src/X.java");

		ImportRewrite importRewrite= ImportRewrite.create(compilationUnit, true);
		importRewrite.addImport("java.util.Vector");
		importRewrite.addImport("java.util.ArrayList");

		TextEdit edit= importRewrite.rewriteImports(null);

		UndoEdit undoEdit= compilationUnit.applyTextEdit(edit, null);

		String newSource =
			"import java.util.ArrayList;\n" +
			"import java.util.Vector;\n" +
			"\n" +
			"public class X {\n" +
			"}\n";

		assertEquals(newSource, compilationUnit.getSource());

		compilationUnit.applyTextEdit(undoEdit, null);

		assertEquals(source, compilationUnit.getSource());
	} finally {
		deleteFile("/P/src/X.java");
	}
}

/*
 * Ensures that IBuffer.ITextEditCapability.applyTextEdit() is not called when doing a Java model operation
 * on a compilation unit since some implementations don't support such a call
 * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=262389)
 */
public void testApplyEdit3() throws CoreException {
	class DisabledTestBuffer extends Buffer implements IBuffer.ITextEditCapability {
		public DisabledTestBuffer(IFile file, IOpenable owner, boolean readOnly) {
			super(file, owner, readOnly);
		}
		public UndoEdit applyTextEdit(TextEdit edit, IProgressMonitor monitor) throws JavaModelException {
			throw new RuntimeException("Should not call applyTextEdit()");
		}
	}
	this.workingCopy = getWorkingCopy("/P/src/X.java", "public class X {}", new WorkingCopyOwner() {
		public IBuffer createBuffer(ICompilationUnit copy) {
			return new DisabledTestBuffer((IFile) copy.getResource(), copy, false);
		}
	});
	this.workingCopy.createType("class Y {}", null, false, null);
	assertSourceEquals(
		"Unexpeted source", 
		"public class X {}\n" + 
		"\n" + 
		"class Y {}",
		this.workingCopy.getSource());
}

/*
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
 * Ensures that negative values work while annotating local variables.
 */
public void testBug248312() throws CoreException{
	createWorkingCopy(
			"package p;\n" +
			"interface A {\n" +
			"	static int VAL = 2;\n" +
			"}\n" +
			"public @interface Y {\n" +
			"  public int member_int() default -1;\n" +
			"  public int member_int2() default -1;\n" +
			"  public float member_float() default -1.0f\n" +
			"  public double member_double=-1.0\n" +
			"  public long member_long=-1L\n" +
			"}\n" +
			"public class Test{\n" +
			"	void testMethod(){\n" +
			"		@Y(member_int=-2) @Y(member_float=-2.0f)\n" +
			"		@Y(member_double=-2.0) @Y(member_long=-2L)\n" +
			"		@Y(member_int2=-A.VAL)\n" +
			"		Object testField1\n" +
			"	}\n" +
			"}"
			);
	ILocalVariable variable1 = selectLocalVariable(this.workingCopy, "testField1");
	IAnnotation[] annotations = variable1.getAnnotations();
	assertAnnotationsEqual(
	"@Y(member_int=(int)-2)\n" +
	"@Y(member_float=-2.0f)\n" +
	"@Y(member_double=(double)-2.0)\n" +
	"@Y(member_long=-2L)\n" +
	"@Y(member_int2=<null>)\n",
	annotations);
}

public void testBug246594() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"public class Z<T extends Object & I<? super T>> {\n" +
		"}\n" +
		"public interface I<T> {}"
	);
	IType type = this.workingCopy.getType("Z");
	ITypeParameter[] typeParameters = type.getTypeParameters();
	assertStringsEqual("Type parameter signature", "T:QObject;:QI<-QT;>;\n", type.getTypeParameterSignatures());
	assertStringsEqual("Type parameter bounds signatures", 
					"QObject;\n" +
					"QI<-QT;>;\n", 
					typeParameters[0].getBoundsSignatures());
}
public void testBug246594a() throws CoreException {
	createWorkingCopy(
		"package p;\n" +
		"interface Collection<E> {\n" +
		"public <T> boolean containsAll(Collection<T> c);\n" +
		"public <T extends E & I<? super String>> boolean addAll(Collection<T> c);\n" +
		"}" +
		"public interface I<T> {}");
	IMethod[] methods = this.workingCopy.getType("Collection").getMethods();//<T:TE;>
	ITypeParameter[] typeParameters = methods[1].getTypeParameters();
	assertStringsEqual("Type parameter bounds signatures", 
			"QE;\n" +
			"QI<-QString;>;\n", 
			typeParameters[0].getBoundsSignatures());
	
}


}

Back to the top