Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: aa2ec77c8a21e75133b31ded6f4437ce3674be89 (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
/*******************************************************************************
 * Copyright (c) 2007, 2010 Intel 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:
 * Intel Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.core.settings.model.util;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ICModelStatus;
import org.eclipse.cdt.core.model.IIncludeEntry;
import org.eclipse.cdt.core.model.IIncludeFileEntry;
import org.eclipse.cdt.core.model.ILibraryEntry;
import org.eclipse.cdt.core.model.IMacroEntry;
import org.eclipse.cdt.core.model.IMacroFileEntry;
import org.eclipse.cdt.core.model.IOutputEntry;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.ISourceEntry;
import org.eclipse.cdt.core.resources.IPathEntryVariableManager;
import org.eclipse.cdt.core.settings.model.CExternalSetting;
import org.eclipse.cdt.core.settings.model.COutputEntry;
import org.eclipse.cdt.core.settings.model.CSourceEntry;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICExclusionPatternPathEntry;
import org.eclipse.cdt.core.settings.model.ICExternalSetting;
import org.eclipse.cdt.core.settings.model.ICIncludePathEntry;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICOutputEntry;
import org.eclipse.cdt.core.settings.model.ICSettingBase;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.cdt.core.settings.model.extension.CBuildData;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.settings.model.extension.CFileData;
import org.eclipse.cdt.core.settings.model.extension.CFolderData;
import org.eclipse.cdt.core.settings.model.extension.CLanguageData;
import org.eclipse.cdt.core.settings.model.extension.CResourceData;
import org.eclipse.cdt.internal.core.CdtVarPathEntryVariableManager;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.cdtvariables.CoreVariableSubstitutor;
import org.eclipse.cdt.internal.core.cdtvariables.DefaultVariableContextInfo;
import org.eclipse.cdt.internal.core.cdtvariables.ICoreVariableContextInfo;
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
import org.eclipse.cdt.internal.core.model.APathEntry;
import org.eclipse.cdt.internal.core.model.CModelStatus;
import org.eclipse.cdt.internal.core.model.PathEntry;
import org.eclipse.cdt.internal.core.settings.model.CConfigurationDescriptionCache;
import org.eclipse.cdt.internal.core.settings.model.IInternalCCfgInfo;
import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;

public class PathEntryTranslator {
	public static final int OP_ADD = 1;
	public static final int OP_REMOVE = 2;
	public static final int OP_REPLACE = 3;

	public static final int INCLUDE_BUILT_INS = 1;
	public static final int INCLUDE_USER = 1 << 1;
	public static final int INCLUDE_ALL = INCLUDE_BUILT_INS | INCLUDE_USER;

	static String PATH_ENTRY = "pathentry"; //$NON-NLS-1$
	static String ATTRIBUTE_KIND = "kind"; //$NON-NLS-1$
	static String ATTRIBUTE_PATH = "path"; //$NON-NLS-1$
	static String ATTRIBUTE_BASE_PATH = "base-path"; //$NON-NLS-1$
	static String ATTRIBUTE_BASE_REF = "base-ref"; //$NON-NLS-1$
	static String ATTRIBUTE_EXPORTED = "exported"; //$NON-NLS-1$
	static String ATTRIBUTE_SOURCEPATH = "sourcepath"; //$NON-NLS-1$
	static String ATTRIBUTE_ROOTPATH = "roopath"; //$NON-NLS-1$
	static String ATTRIBUTE_PREFIXMAPPING = "prefixmapping"; //$NON-NLS-1$
	static String ATTRIBUTE_EXCLUDING = "excluding"; //$NON-NLS-1$
	static String ATTRIBUTE_INCLUDE = "include"; //$NON-NLS-1$
	static String ATTRIBUTE_INCLUDE_FILE= "include-file"; //$NON-NLS-1$
	static String ATTRIBUTE_LIBRARY = "library"; //$NON-NLS-1$
	static String ATTRIBUTE_SYSTEM = "system"; //$NON-NLS-1$
	static String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
	static String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$
	static String ATTRIBUTE_MACRO_FILE = "macro-file"; //$NON-NLS-1$
	static String VALUE_TRUE = "true"; //$NON-NLS-1$

	static final IPathEntry[] NO_PATHENTRIES = new IPathEntry[0];

	private static final char[] SPEC_CHARS = new char[] { '*', '?' };
	private PathSettingsContainer fRcDataHolder;
	private IProject fProject;
	private CConfigurationData fCfgData;
	private PathSettingsContainer fTranslatedFilters;
	private Map<IPath, ResourceInfo> fResourceMap = new HashMap<IPath, ResourceInfo>();
	private IWorkspaceRoot fRoot = ResourcesPlugin.getWorkspace().getRoot();

	private static class VarSubstitutor extends CoreVariableSubstitutor {
		ICConfigurationDescription fCfg;
		ICdtVariableManager fMngr = CCorePlugin.getDefault().getCdtVariableManager();

		public VarSubstitutor(ICConfigurationDescription cfgDescription) {
			super(new DefaultVariableContextInfo(ICoreVariableContextInfo.CONTEXT_CONFIGURATION, cfgDescription), "", " ");  //$NON-NLS-1$  //$NON-NLS-2$
			fCfg = cfgDescription;
		}

		@Override
		protected ResolvedMacro resolveMacro(ICdtVariable macro)
				throws CdtVariableException {
			if (!CdtVarPathEntryVariableManager.isPathEntryVariable(macro, fCfg, fMngr))
				return super.resolveMacro(macro);
			return new ResolvedMacro(macro.getName(), CdtVariableResolver.createVariableReference(macro.getName()));
		}
	}

	public static final class ReferenceSettingsInfo{
		private IPath[] fRefProjPaths;
		private ICExternalSetting[] fExtSettings;

		public ReferenceSettingsInfo(ICConfigurationDescription cfgDescription) {
			fExtSettings = cfgDescription.getExternalSettings();
			Map<String, String> map = cfgDescription.getReferenceInfo();
			fRefProjPaths = new IPath[map.size()];
			int num = 0;
			for (String proj : map.keySet()) {
				fRefProjPaths[num++] = new Path(proj).makeAbsolute();
			}
		}

		public ReferenceSettingsInfo(IPath[] projPaths, ICExternalSetting extSettings[]) {
			if (projPaths != null)
				fRefProjPaths = projPaths.clone();
			if (extSettings != null)
				fExtSettings = extSettings.clone();
		}

		public IPath[] getReferencedProjectsPaths() {
			if (fRefProjPaths != null)
				return fRefProjPaths.clone();
			return new IPath[0];
		}

		public Map<String, String> getRefProjectsMap() {
			if (fRefProjPaths != null && fRefProjPaths.length != 0) {
				Map<String, String> map = new HashMap<String, String>(fRefProjPaths.length);
				for (IPath fRefProjPath : fRefProjPaths) {
					map.put(fRefProjPath.segment(0), ""); //$NON-NLS-1$
				}
				return map;
			}
			return new HashMap<String, String>(0);
		}

		public ICExternalSetting[] getExternalSettings() {
			if (fExtSettings != null)
				return fExtSettings.clone();
			return new ICExternalSetting[0];
		}
	}

	private static class PathEntryKyndStore {
		private static final int INDEX_CDT_LIBRARY = 0;
		private static final int INDEX_CDT_PROJECT = 1;
		private static final int INDEX_CDT_SOURCE = 2;
		private static final int INDEX_CDT_INCLUDE = 3;
		private static final int INDEX_CDT_CONTAINER = 4;
		private static final int INDEX_CDT_MACRO = 5;
		private static final int INDEX_CDT_OUTPUT = 6;
		private static final int INDEX_CDT_INCLUDE_FILE = 7;
		private static final int INDEX_CDT_MACRO_FILE = 8;

		private static final int STORAGE_SIZE = 9;

		private static final int ENTRY_KINDS[] = new int[]{
			IPathEntry.CDT_LIBRARY,
			IPathEntry.CDT_PROJECT,
			IPathEntry.CDT_SOURCE,
			IPathEntry.CDT_INCLUDE,
			IPathEntry.CDT_CONTAINER,
			IPathEntry.CDT_MACRO,
			IPathEntry.CDT_OUTPUT,
			IPathEntry.CDT_INCLUDE_FILE,
			IPathEntry.CDT_MACRO_FILE,
		};
//		private static final int INEXISTENT_INDEX = -1;

		@SuppressWarnings("unchecked")
		private Map<String, IPathEntry>[] fEntryStorage = new Map[STORAGE_SIZE];

		private int kindToIndex(int kind) {
			switch (kind) {
			case IPathEntry.CDT_LIBRARY:
				return INDEX_CDT_LIBRARY;
			case IPathEntry.CDT_PROJECT:
				return INDEX_CDT_PROJECT;
			case IPathEntry.CDT_SOURCE:
				return INDEX_CDT_SOURCE;
			case IPathEntry.CDT_INCLUDE:
				return INDEX_CDT_INCLUDE;
			case IPathEntry.CDT_CONTAINER:
				return INDEX_CDT_CONTAINER;
			case IPathEntry.CDT_MACRO:
				return INDEX_CDT_MACRO;
			case IPathEntry.CDT_OUTPUT:
				return INDEX_CDT_OUTPUT;
			case IPathEntry.CDT_INCLUDE_FILE:
				return INDEX_CDT_INCLUDE_FILE;
			case IPathEntry.CDT_MACRO_FILE:
				return INDEX_CDT_MACRO_FILE;
			}
			throw new IllegalArgumentException(UtilMessages.getString("PathEntryTranslator.0")); //$NON-NLS-1$
		}

		public static int[] getSupportedKinds() {
			return ENTRY_KINDS.clone();
		}

		public Map<String, IPathEntry> get(int kind) {
			return fEntryStorage[kindToIndex(kind)];
		}

		public Map<String, IPathEntry> put(int kind, Map<String, IPathEntry> object) {
			int index = kindToIndex(kind);
			Map<String, IPathEntry> old = fEntryStorage[index];
			fEntryStorage[index] = object;
			return old;
		}
	}

	private static class LangEntryInfo {
		ICLanguageSettingEntry fLangEntry;
		ResolvedEntry fResolvedEntry;

		public LangEntryInfo(ICLanguageSettingEntry lEntry, ResolvedEntry re) {
			fLangEntry = lEntry;
			fResolvedEntry = re;
		}
	}

	private class RcDesInfo {
		List<ResolvedEntry> fResolvedEntries;
		KindBasedStore<List<LangEntryInfo>> fLangEntries;

		private RcDesInfo(ResourceInfo rcInfo) {
			fResolvedEntries = new ArrayList<ResolvedEntry>();
			fLangEntries = new KindBasedStore<List<LangEntryInfo>>();
		}

		public void add(LangEntryInfo info) {
			List<LangEntryInfo> list = fLangEntries.get(info.fLangEntry.getKind());
			if (list == null) {
				list = new ArrayList<LangEntryInfo>();
				fLangEntries.put(info.fLangEntry.getKind(), list);
			}
			list.add(info);
		}

		public ICLanguageSettingEntry[] getEntries(int kind) {
			List<LangEntryInfo> list = fLangEntries.get(kind);
			if (list != null) {
				ICLanguageSettingEntry[] entries = new ICLanguageSettingEntry[list.size()];
				for (int i = 0; i < entries.length; i++) {
					LangEntryInfo info = list.get(i);
					entries[i] = info.fLangEntry;
				}
				return entries;
			}
			return new ICLanguageSettingEntry[0];


		}
	}

	private static ICLanguageSettingEntry createLangEntry(ResolvedEntry entry) {
		PathEntryValueInfo pathEntryValue = entry.getResolvedValue();
		String name = pathEntryValue.getName();

		int flags = ICSettingEntry.RESOLVED;
		if (entry.isReadOnly())
			flags |= ICSettingEntry.READONLY;
		if (entry.isBuiltIn())
			flags |= ICSettingEntry.BUILTIN;

		IPath path = pathEntryValue.getFullPath();
		if (path != null) {
			flags |= ICSettingEntry.VALUE_WORKSPACE_PATH;
		} else {
			path = pathEntryValue.getLocation();
		}

		int kind = entry.fEntry.getEntryKind();
		switch (kind) {
			case IPathEntry.CDT_LIBRARY:{
				if (path != null) {
					ILibraryEntry libEntry = (ILibraryEntry)entry.fEntry;
					return (ICLanguageSettingEntry) CDataUtil.createEntry(ICSettingEntry.LIBRARY_FILE, name, null, null, flags,
							libEntry.getSourceAttachmentPath(),
							libEntry.getSourceAttachmentRootPath(),
							libEntry.getSourceAttachmentPrefixMapping());
				}
				break;
			}
//			case IPathEntry.CDT_PROJECT:
//				return ICLanguageSettingEntry;
//			case IPathEntry.CDT_SOURCE:
//				return INDEX_CDT_SOURCE;
			case IPathEntry.CDT_INCLUDE:{
				if (path != null) {
					return CDataUtil.createCIncludePathEntry(name, flags);
				}
				break;
			}
//			case IPathEntry.CDT_CONTAINER:
//				return INDEX_CDT_CONTAINER;
			case IPathEntry.CDT_MACRO:
				if (name.length() != 0) {
					String value = pathEntryValue.getValue();
					return CDataUtil.createCMacroEntry(name, value, flags);
				}
				break;
//			case IPathEntry.CDT_OUTPUT:
//				return INDEX_CDT_OUTPUT;
			case IPathEntry.CDT_INCLUDE_FILE:{
				if (path != null) {
					return CDataUtil.createCIncludeFileEntry(name, flags);
				}
				break;
			}
			case IPathEntry.CDT_MACRO_FILE:{
				if (path != null) {
					return CDataUtil.createCMacroFileEntry(name, flags);
				}
				break;
			}
		}
		return null;
	}

	private class ResourceInfo {
		IResource fRc;
		boolean fExists;

		public ResourceInfo(IResource rc, boolean exists) {
			fRc = rc;
			fExists = exists;
		}
	}

	private class PathEntryValueInfo {
		private ResourceInfo fResourceInfo;
		private IPath fLocation;
		private String fName;
		private String fValue;
		private ResolvedEntry fResolvedEntry;

		private PathEntryValueInfo(ResolvedEntry rEntry) {
			fResolvedEntry = rEntry;

			init();
		}

		public IPath getFullPath() {
			if (fResourceInfo != null)
				return fResourceInfo.fRc.getFullPath();
			return null;
		}

		public IPath getLocation() {
			if (fResourceInfo != null)
				return fResourceInfo.fRc.getLocation();
			return fLocation;
		}

		public String getName() {
			if (fName != null)
				return fName;
			return ""; //$NON-NLS-1$
		}

		public String getValue() {
			if (fValue != null)
				return fValue;
			return ""; //$NON-NLS-1$
		}

		private void init() {
			IPathEntry entry = fResolvedEntry.fEntry;
			int peKind = entry.getEntryKind();
			IPath basePath = null, valuePath = null;
			boolean isFile = false;
			boolean calcPath = false;
			switch (peKind) {
			case IPathEntry.CDT_MACRO:
				IMacroEntry me = (IMacroEntry)entry;
				fName = me.getMacroName();
				fValue = me.getMacroValue();
				break;
			case IPathEntry.CDT_LIBRARY:
				isFile = true;
				calcPath = true;
				ILibraryEntry le = (ILibraryEntry)entry;
				basePath = le.getBasePath();
				valuePath = le.getLibraryPath();
				break;
			case IPathEntry.CDT_INCLUDE:
				isFile = false;
				calcPath = true;
				IIncludeEntry ie = (IIncludeEntry)entry;
				basePath = ie.getBasePath();
				valuePath = ie.getIncludePath();
				break;
			case IPathEntry.CDT_INCLUDE_FILE:
				isFile = true;
				calcPath = true;
				IIncludeFileEntry ife = (IIncludeFileEntry)entry;
				basePath = ife.getBasePath();
				valuePath = ife.getIncludeFilePath();
				break;
			case IPathEntry.CDT_MACRO_FILE:
				isFile = true;
				calcPath = true;
				IMacroFileEntry mfe = (IMacroFileEntry)entry;
				basePath = mfe.getBasePath();
				valuePath = mfe.getMacroFilePath();
				break;
			case IPathEntry.CDT_PROJECT:
			case IPathEntry.CDT_SOURCE:
			case IPathEntry.CDT_CONTAINER:
			case IPathEntry.CDT_OUTPUT:
				fResourceInfo = fResolvedEntry.getResourceInfo();
				break;
			}

			if (calcPath) {
				do {
					IPath unresolvedBase = basePath;
					IPath unresolvedValue = valuePath;
					IPathEntryVariableManager mngr = CCorePlugin.getDefault().getPathEntryVariableManager();

					basePath = mngr.resolvePath(basePath);
					valuePath = mngr.resolvePath(valuePath);

					fName = unresolvedBase.isEmpty() ? unresolvedValue.toString() : unresolvedBase.append(unresolvedValue).toString();
					fValue = fName;

					if (!basePath.isEmpty()) {
						IPath loc = basePath;
						if (!loc.isAbsolute()) {
							ResourceInfo rcInfo = findResourceInfo(fRoot, loc.append(valuePath), !isFile);
							if (rcInfo.fExists) {
								fResourceInfo = rcInfo;
								fName = unresolvedBase.append(unresolvedValue).toString();
								fValue = fName;
								break;
							}
						}
						fLocation = loc.append(valuePath);
						break;
					}

					if (!valuePath.isAbsolute()) {
						ResourceInfo rcInfo = fResolvedEntry.getResourceInfo();
						if (rcInfo.fExists) {
							if (rcInfo.fRc.getType() == IResource.FILE) {
								rcInfo = findResourceInfo(fRoot, rcInfo.fRc.getFullPath().removeLastSegments(1), true);
							}
							IPath location = rcInfo.fRc.getLocation();
							if (location != null && rcInfo.fRc.getType() != IResource.FILE) {
								rcInfo = findResourceInfo((IContainer)rcInfo.fRc, valuePath, !isFile);
								fResourceInfo = rcInfo;
								break;
							}
						}
					}

					fLocation = valuePath;
				} while (false);
			}
		}
	}

	private class ResolvedEntry {
		private IPathEntry fEntry;
		private ResourceInfo fResourceInfo;
		private ResourceInfo[] fFilterInfos;
		private PathEntryValueInfo fResolvedValue;
		private PathEntryResolveInfoElement fResolveElement;
		private boolean fIsReadOnly;
		private boolean fIsBuiltIn;

		public ResolvedEntry(IPathEntry entry, PathEntryResolveInfoElement resolveElement) {
			fEntry = entry;
			fResolveElement = resolveElement;
			fIsReadOnly = areEntriesReadOnly(fResolveElement);
			fIsBuiltIn = fIsReadOnly;
		}

		public ResolvedEntry(IPathEntry entry, boolean isReadOnly) {
			fEntry = entry;
			fIsReadOnly = isReadOnly;
		}

		public boolean isReadOnly() {
			return fIsReadOnly;
		}

		public boolean isBuiltIn() {
			return fIsBuiltIn;
		}

		public ResourceInfo getResourceInfo() {
			if (fResourceInfo == null) {
				fResourceInfo = findResourceInfo(fRoot, getEntryFullPath(fEntry), true);
			}
			return fResourceInfo;
		}

		public ResourceInfo[] getFilterInfos() {
			if (fFilterInfos == null) {
				IPath[] paths = obtainFilters(fEntry);
				if (paths.length == 0) {
					fFilterInfos = new ResourceInfo[0];
				} else {
					ResourceInfo rcInfo = getResourceInfo();
					if (rcInfo.fExists) {
						if (rcInfo.fRc.getType() == IResource.FILE) {
							fFilterInfos = new ResourceInfo[0];
						} else {
							List<ResourceInfo> list = new ArrayList<ResourceInfo>();
							for (IPath path : paths) {
								list.addAll(Arrays.asList(processFilter((IContainer)rcInfo.fRc, path)));
							}
							fFilterInfos = new ResourceInfo[list.size()];
							list.toArray(fFilterInfos);
						}
					} else {
						fFilterInfos = new ResourceInfo[paths.length];
						for (int i = 0; i < paths.length; i++) {
							fFilterInfos[i] = processInexistingResourceFilter((IContainer)rcInfo.fRc, paths[i]);
						}
					}
				}
			}
			return fFilterInfos;
		}

		private ResourceInfo[] processFilter(IContainer container, IPath path) {
			return resolveFilter(container, path);
		}

		private ResourceInfo processInexistingResourceFilter(IContainer container, IPath path) {
			IFolder f = container.getFolder(path);
			ResourceInfo rcInfo = new ResourceInfo(f, false);
			addRcInfoToMap(rcInfo);

			addResolvedFilterToMap(container.getFullPath(), new ResourceInfo[]{rcInfo}, true);
			return rcInfo;
		}

		public IPathEntry getEntry() {
			return fEntry;
		}

		public PathEntryValueInfo getResolvedValue() {
			if (fResolvedValue == null) {
				fResolvedValue = new PathEntryValueInfo(this);
			}
			return fResolvedValue;
		}


	}

	private static class PathEntryComposer {
		private IPath fPath;
		private ICSettingEntry fLangEntry;
		private Set<IPath> fFiltersSet;
		private boolean fIsExported;
		private IProject fProject;

		PathEntryComposer(IPath path, IProject project/*, ICConfigurationDescription cfgDescription*/) {
			fPath = toProjectPath(path);
			fProject = project;
		}

		private static IPath toProjectPath(IPath path) {
			if (path.segmentCount() > 1)
				path = new Path(path.segment(0));

			return path.makeAbsolute();
		}

		PathEntryComposer(ICExclusionPatternPathEntry entry, IProject project/*, ICConfigurationDescription cfgDescription*/) {
			fPath = new Path(entry.getValue());
			fLangEntry = entry;
			fProject = project;
			IPath[] exclusions = entry.getExclusionPatterns();
			if (exclusions.length != 0) {
				fFiltersSet = new HashSet<IPath>(exclusions.length);
				fFiltersSet.addAll(Arrays.asList(entry.getExclusionPatterns()));
			}
		}

		PathEntryComposer(IPath path, ICLanguageSettingEntry entry, boolean exported, IProject project/*, ICConfigurationDescription cfgDescription*/) {
			fPath = path;
			fLangEntry = entry;
			fIsExported = exported;
			fProject = project;
		}

		public void addFilter(IPath path) {
			if (fFiltersSet == null)
				fFiltersSet = new HashSet<IPath>();

			fFiltersSet.add(path);
		}

		public ICSettingEntry getSettingEntry() {
			return fLangEntry;
		}

		public IPath getPath() {
			return fPath;
		}

		public IPath[] getExclusionPatterns() {
			if (fFiltersSet != null)
				return fFiltersSet.toArray(new IPath[fFiltersSet.size()]);
			return new IPath[0];
		}

		private IPath[][] getEntryPath(ICSettingEntry entry, ICConfigurationDescription cfgDescription) {
			return valueToEntryPath(entry.getName(), (entry.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH) != 0, cfgDescription);
		}

		private IPath[][] valueToEntryPath(String value, boolean isWsp, ICConfigurationDescription cfgDescription) {
			String[] pathVarValues = resolveKeepingPathEntryFars(value, cfgDescription);
			IPath result[][] = new IPath[2][pathVarValues.length];
			for (int i = 0; i < pathVarValues.length; i++) {
				String resolvedValue = resolveAll(value, cfgDescription);
				IPath resolvedPath = new Path(resolvedValue);
				IPath pathVarPath = new Path(pathVarValues[i]);
				if (isWsp) {
					if (!resolvedPath.isAbsolute()) {
						result[0][i] = fProject.getFullPath().makeRelative();
						result[1][i] = pathVarPath;
					} else {
						if (resolvedPath.segmentCount() != 0) {
							String projName = resolvedPath.segment(0);
							IPath valuePath = resolvedPath.removeFirstSegments(1).makeRelative();
							if (pathVarPath.segmentCount() != 0) {
								String resolvedProjName = projName;
								String varProjName = pathVarPath.segment(0);
								IPath resolvedProjPath = CCorePlugin.getDefault().getPathEntryVariableManager().resolvePath(new Path(varProjName));
								if (resolvedProjPath.segmentCount() == 1 && resolvedProjName.equals(resolvedProjPath.segment(0))) {
									projName = varProjName;
									valuePath = pathVarPath.removeFirstSegments(1).makeRelative();
								}
							}

							result[0][i] = new Path(projName);
							result[1][i] = valuePath;
						} else if (pathVarPath.isRoot()) {
							result[1][i] = ResourcesPlugin.getWorkspace().getRoot().getLocation();
						}
					}
				} else {
					if (!resolvedPath.isAbsolute()) {
						IPath location = fProject.getLocation();
						if (location != null)
							pathVarPath = location.append(pathVarPath);
					}
					result[1][i] = pathVarPath;
				}
			}

			return result;
		}

		public IPathEntry[] toPathEntry(ICConfigurationDescription cfgDescription, boolean keepPathInfo) {
			IPath path = keepPathInfo ? fPath : fProject.getFullPath();
			IPathEntry[] result = new IPathEntry[0];
			if (fLangEntry != null) {
				switch (fLangEntry.getKind()) {
				case ICSettingEntry.INCLUDE_FILE:{
						IPath paths[][] = getEntryPath(fLangEntry, cfgDescription);
						result = new IPathEntry[paths[0].length];
						for (int i = 0; i < result.length; i++)
							result[i] = CoreModel.newIncludeFileEntry(path, null, paths[0][i], paths[1][i], getExclusionPatterns(), fIsExported);
						return result;
					}
				case ICSettingEntry.INCLUDE_PATH:{
						IPath paths[][] = getEntryPath(fLangEntry, cfgDescription);
						ICIncludePathEntry ipe = (ICIncludePathEntry)fLangEntry;

						result = new IPathEntry[paths[0].length];
						for (int i = 0; i < result.length; i++)
							result[i] = CoreModel.newIncludeEntry(path, paths[0][i], paths[1][i], !ipe.isLocal(), getExclusionPatterns(), fIsExported);
						return result;
					}
				case ICSettingEntry.MACRO:
					result = new IPathEntry[1];
					result[0] = CoreModel.newMacroEntry(path, fLangEntry.getName(), fLangEntry.getValue(), getExclusionPatterns(), fIsExported);
					return result;
				case ICSettingEntry.MACRO_FILE:{
						IPath paths[][] = getEntryPath(fLangEntry, cfgDescription);
						result = new IPathEntry[paths[0].length];
						for (int i = 0; i < result.length; i++)
							result[i] = CoreModel.newMacroFileEntry(path, paths[0][i], null, paths[1][i], getExclusionPatterns(), fIsExported);
						return result;
					}
				case ICSettingEntry.LIBRARY_PATH:
				case ICSettingEntry.LIBRARY_FILE:
					// Bug 100844 don't contribute library files back to the CModel as a library files, as supplied by the build system,
					// aren't currently resolved
					return null;
//				case ICSettingEntry.LIBRARY_FILE:{
//						IPath paths[][] = getEntryPath(fLangEntry, cfgDescription);
//						result = new IPathEntry[paths[0].length];
//						for (int i = 0; i < result.length; i++)
//							result[i] = CoreModel.newLibraryEntry(path, paths[0][i], paths[1][i], null, null, null, fIsExported);
//						return result;
//					}
				case ICSettingEntry.OUTPUT_PATH:
					result = new IPathEntry[1];
					result[0] = CoreModel.newOutputEntry(fPath, getExclusionPatterns());
					return result;
				case ICSettingEntry.SOURCE_PATH:
					result = new IPathEntry[1];
					result[0] = CoreModel.newSourceEntry(fPath, getExclusionPatterns());
					return result;
				default:
					return result; // empty
				}
			} else if (fPath != null) {
				result = new IPathEntry[1];
				result[0] = CoreModel.newProjectEntry(fPath, fIsExported);
				return result;
			}
			return result; // empty
		}
	}

	private static String resolveAll(String value, ICConfigurationDescription cfgDescription) {
		try {
			return CCorePlugin.getDefault().getCdtVariableManager().resolveValue(value, "", " ", cfgDescription); //$NON-NLS-1$ //$NON-NLS-2$
		} catch (CdtVariableException e) {
			CCorePlugin.log(e);
		}
		return value;
	}

	private static String[] resolveKeepingPathEntryFars(String value, ICConfigurationDescription cfgDescription) {
		String[] result = new String[] { value }; // default value;
		try {
			VarSubstitutor substitutor = new VarSubstitutor(cfgDescription);

			result = CdtVariableResolver.resolveToStringList(value, substitutor);
			if (result == null || result.length == 0)
				result = new String[] {	CdtVariableResolver.resolveToString(value, substitutor) };
		} catch (CdtVariableException e) {
			CCorePlugin.log(e);
		}
		return result;
	}

	public static class PathEntryCollector {
		private PathSettingsContainer fStorage;
		private KindBasedStore<LinkedHashMap<ICSettingEntry, PathEntryComposer>> fStore;
		private KindBasedStore<LinkedHashMap<EntryNameKey, PathEntryComposer>> fNameKeyMapStore; //utility map, does not contain all entries, only those added explicitly
		private LinkedHashMap<IPath, PathEntryComposer> fRefProjMap;
		private IProject fProject;

		private PathEntryCollector(IProject project/*, ICConfigurationDescription cfgDescription*/) {
			fStorage = PathSettingsContainer.createRootContainer();
			fStorage.setValue(this);
			fStore = new KindBasedStore<LinkedHashMap<ICSettingEntry, PathEntryComposer>>(false);
			fNameKeyMapStore = new KindBasedStore<LinkedHashMap<EntryNameKey, PathEntryComposer>>(false);
			fProject = project;
		}

		private PathEntryCollector(PathSettingsContainer container, KindBasedStore<LinkedHashMap<ICSettingEntry, PathEntryComposer>> store, IProject project/*, ICConfigurationDescription cfgDescription*/) {
			fStorage = container;
			fStore = store;
			fNameKeyMapStore = new KindBasedStore<LinkedHashMap<EntryNameKey, PathEntryComposer>>(false);
			fProject = project;
		}

		public void setSourceOutputEntries(int kind, ICExclusionPatternPathEntry entries[]) {
			Map<ICSettingEntry, PathEntryComposer> map = getEntriesMap(kind, true);
			Map<EntryNameKey, PathEntryComposer> nameKeyMap = getEntriesNameKeyMap(kind, true);
			for (ICExclusionPatternPathEntry entry : entries) {
				entry = CDataUtil.makeAbsolute(fProject, entry, true);
				EntryNameKey nameKey = new EntryNameKey(entry);
				PathEntryComposer old = nameKeyMap.get(nameKey);
				if (old != null) {
					entry = CDataUtil.addRemoveExclusionsToEntry(entry,
							((ICExclusionPatternPathEntry)old.fLangEntry).getExclusionPatterns(),
							true);
				}
				PathEntryComposer newComposer = new PathEntryComposer(entry, fProject/*, fCfg*/);
				map.put(entry, newComposer);
				nameKeyMap.put(nameKey, newComposer);
			}
		}

		public void setRefProjects(IPath []paths) {
			if (paths == null || paths.length == 0) {
				fRefProjMap = null;
			} else {
				fRefProjMap = new LinkedHashMap<IPath, PathEntryComposer>();
				for (IPath path : paths) {
					PathEntryComposer cs = new PathEntryComposer(path, fProject/*, fCfg*/);
					IPath composerPath = cs.getPath();
					fRefProjMap.put(composerPath, cs);
				}
			}
		}

		public PathEntryCollector createChild(IPath path) {
			if (path.segmentCount() == 0)
				return this;

			PathEntryCollector cr = (PathEntryCollector)fStorage.getChildContainer(path, false, false).getValue();
			if (cr != this) {
				IPath basePath = cr.getPath();
				path = path.removeFirstSegments(basePath.segmentCount());
				return cr.createChild(path);
			}

			PathSettingsContainer newContainer = fStorage.getChildContainer(path, true, true);
			@SuppressWarnings("unchecked")
			KindBasedStore<LinkedHashMap<ICSettingEntry, PathEntryComposer>> cloneStore =
				(KindBasedStore<LinkedHashMap<ICSettingEntry, PathEntryComposer>>)fStore.clone();
			IKindBasedInfo<LinkedHashMap<ICSettingEntry, PathEntryComposer>> info[] = cloneStore.getContents();
			for (IKindBasedInfo<LinkedHashMap<ICSettingEntry, PathEntryComposer>> kindInfo : info) {
				LinkedHashMap<ICSettingEntry, PathEntryComposer> map = kindInfo.getInfo();
				if (map != null) {
					@SuppressWarnings("unchecked")
					LinkedHashMap<ICSettingEntry, PathEntryComposer> clone = (LinkedHashMap<ICSettingEntry, PathEntryComposer>)map.clone();
					kindInfo.setInfo(clone);
				}
			}
			PathEntryCollector newCr = new PathEntryCollector(newContainer, cloneStore, fProject/*, fCfg*/);
			newContainer.setValue(newCr);
			return newCr;
		}

		public IPath getPath() {
			return fStorage.getPath();
		}

		public void setEntries(int kind, ICLanguageSettingEntry entries[], Set<ICSettingEntry> exportedEntries) {
			IPath path = getPath();
			HashSet<ICSettingEntry> parentSet = getEntriesSetCopy(kind);
			@SuppressWarnings("unchecked")
			HashSet<ICSettingEntry> removedParentSet = (HashSet<ICSettingEntry>)parentSet.clone();
			HashSet<ICLanguageSettingEntry> addedThisSet = new HashSet<ICLanguageSettingEntry>(Arrays.asList(entries));
			removedParentSet.removeAll(addedThisSet);
			addedThisSet.removeAll(parentSet);


			if (removedParentSet.size() != 0) {
				PathEntryCollector parent = getParent();
				IPath parentPath = parent.getPath();

				int segsToRemove = parentPath.segmentCount();
				if (segsToRemove > path.segmentCount())
					segsToRemove = path.segmentCount() - 1;
				if (segsToRemove < 0)
					segsToRemove = 0;

				IPath filterPath = path.removeFirstSegments(segsToRemove);

				parent.addFilter(kind, filterPath, removedParentSet);

				Map<ICSettingEntry, PathEntryComposer> map = getEntriesMap(kind, true);
				for (ICSettingEntry item : removedParentSet) {
					map.remove(item);
				}
			}

			if (addedThisSet.size() != 0) {
				Map<ICSettingEntry, PathEntryComposer> map = getEntriesMap(kind, true);
				IPath fullPath = fProject.getFullPath().append(path);
				for (int i = 0; i < entries.length; i++) {
					if (!addedThisSet.remove(entries[i]))
						continue;

					ICLanguageSettingEntry entry = entries[i];
					map.put(entry, new PathEntryComposer(fullPath, entry, exportedEntries.contains(entry), fProject/*, fCfg*/));
				}
			}
		}

		private LinkedHashMap<ICSettingEntry, PathEntryComposer> getEntriesMap(int kind, boolean create) {
			LinkedHashMap<ICSettingEntry, PathEntryComposer> map = fStore.get(kind);
			if (map == null && create) {
				map = new LinkedHashMap<ICSettingEntry, PathEntryComposer>();
				fStore.put(kind, map);
			}
			return map;
		}

		private LinkedHashMap<EntryNameKey, PathEntryComposer> getEntriesNameKeyMap(int kind, boolean create) {
			LinkedHashMap<EntryNameKey, PathEntryComposer> map = fNameKeyMapStore.get(kind);
			if (map == null && create) {
				map = new LinkedHashMap<EntryNameKey, PathEntryComposer>();
				fNameKeyMapStore.put(kind, map);
			}
			return map;
		}

		private void addFilter(int kind, IPath path, Set<ICSettingEntry> entriesSet) {
			if (entriesSet.size() == 0)
				return;

			Map<ICSettingEntry, PathEntryComposer> map = fStore.get(kind);
			for (ICSettingEntry fltPath : entriesSet) {
				PathEntryComposer cs = map.get(fltPath);
				cs.addFilter(path);
			}
		}

		public PathEntryCollector getParent() {
			if (fStorage.isRoot())
				return null;
			PathSettingsContainer cr = fStorage.getParentContainer();
			return (PathEntryCollector)cr.getValue();
		}

		private HashSet<ICSettingEntry> getEntriesSetCopy(int kind) {
			Map<ICSettingEntry, PathEntryComposer> map = getEntriesMap(kind, false);
			if (map != null) {
				return new HashSet<ICSettingEntry>(map.keySet());
			}
			return new HashSet<ICSettingEntry>(0);
		}

		private List<PathEntryComposer> getCollectedEntriesList(final int kind) {
			final List<PathEntryComposer> list = new ArrayList<PathEntryComposer>();
			final Set<PathEntryComposer> set = new HashSet<PathEntryComposer>();
			fStorage.accept(new IPathSettingsContainerVisitor() {

				@Override
				public boolean visit(PathSettingsContainer container) {
					PathEntryCollector clr = (PathEntryCollector)container.getValue();
					clr.getLocalCollectedEntries(kind, list, set);
					return true;
				}

			});

			return list;
		}

		private void getLocalCollectedEntries(int kind, List<PathEntryComposer> list, Set<PathEntryComposer> addedEntries) {
			Map<ICSettingEntry, PathEntryComposer> map = getEntriesMap(kind, false);
			if (map == null)
				return;

			for (PathEntryComposer pathEntryComposer : map.values()) {
				if (addedEntries.add(pathEntryComposer)) {
					list.add(pathEntryComposer);
				}
			}
		}

		public List<IPathEntry> getEntries(int peKind, List<IPathEntry> list, int flags, ICConfigurationDescription cfgDescription) {
			Set<IPathEntry> set = new LinkedHashSet<IPathEntry>();

			int sKind = peKindToSettingKind(peKind);
			List<PathEntryComposer> composerList = null;
			if (sKind != 0) {
				composerList = getCollectedEntriesList(sKind);
			} else if (peKind == IPathEntry.CDT_PROJECT) {
				if (fRefProjMap != null && fRefProjMap.size() != 0) {
					composerList = new ArrayList<PathEntryComposer>(fRefProjMap.values());
				}
			}
			if (composerList != null) {
				PathEntryKyndStore store = new PathEntryKyndStore();
				for (PathEntryComposer cs : composerList) {
					ICSettingEntry entry = cs.getSettingEntry();
					if (checkFilter(cs, entry, flags)) {
						IPathEntry[] pe = null;
						if (isBuiltIn(entry) && cs.getPath().segmentCount() > 1) {
							String name = entry.getName();
							Map<String, IPathEntry> map = store.get(peKind);
							if (map == null) {
								map = new HashMap<String, IPathEntry>();
								store.put(peKind, map);
							}
							if (!map.containsKey(name)) {
								pe = cs.toPathEntry(cfgDescription, false);
								if (pe != null) {
									if (pe.length > 1) {
										System.out.println();
									}
									map.put(name, pe[0]);
								}
							}
						} else {
							pe = cs.toPathEntry(cfgDescription, true);
						}
						if (pe != null)
							set.addAll(Arrays.asList(pe));
					}
				}
			}

			if (list == null) {
				list = new ArrayList<IPathEntry>(set);
			} else {
				list.addAll(set);
			}
			return list;
		}

		private static boolean checkFilter(PathEntryComposer cs, ICSettingEntry entry, int flags) {
			boolean builtIn = isBuiltIn(entry);

//			if (builtIn && cs.getPath().segmentCount() > 1)
//				return false;
			if ((flags & INCLUDE_BUILT_INS) != 0 && builtIn)
				return true;
			if ((flags & INCLUDE_USER) != 0 && !builtIn)
				return true;
			return false;
		}

		private static boolean isBuiltIn(ICSettingEntry entry) {
			return entry != null &&	(entry.isBuiltIn() || entry.isReadOnly());
		}

		public List<IPathEntry> getEntries(List<IPathEntry> list, int flags, ICConfigurationDescription cfgDescription) {
			if (list == null)
				list = new ArrayList<IPathEntry>();
			int peKinds[] = PathEntryKyndStore.getSupportedKinds();
			for (int peKind : peKinds) {
				getEntries(peKind, list, flags, cfgDescription);
			}

			return list;
		}

		public IPathEntry[] getEntries(int flags, ICConfigurationDescription cfgDescription) {
			List<IPathEntry> list = getEntries(null, flags,cfgDescription);
			IPathEntry[] entries = list.toArray(new IPathEntry[list.size()]);
			return entries;
		}
	}

	private static LangEntryInfo createLangEntryInfo(ResolvedEntry entry) {
		ICLanguageSettingEntry le = createLangEntry(entry);
		if (le != null) {
			return new LangEntryInfo(le, entry);
		}
		return null;
	}


	private static boolean areEntriesReadOnly(PathEntryResolveInfoElement el) {
		switch (el.getRawEntry().getEntryKind()) {
		case IPathEntry.CDT_LIBRARY:
		case IPathEntry.CDT_INCLUDE:
		case IPathEntry.CDT_MACRO:
		case IPathEntry.CDT_INCLUDE_FILE:
		case IPathEntry.CDT_MACRO_FILE:
		case IPathEntry.CDT_SOURCE:
		case IPathEntry.CDT_OUTPUT:
			return false;
//		case IPathEntry.CDT_PROJECT:
//		case IPathEntry.CDT_CONTAINER:
		}
		return true;
	}


	private IPath getEntryFullPath(IPathEntry entry) {
		IPath path = entry.getPath();
		if (path == null)
			return fProject.getFullPath();
		else if (path.isAbsolute())
			return path;
		return fProject.getFullPath().append(path);

	}

	private IPath[] obtainFilters(IPathEntry entry) {
		switch (entry.getEntryKind()) {
		case IPathEntry.CDT_INCLUDE:
		case IPathEntry.CDT_INCLUDE_FILE:
		case IPathEntry.CDT_MACRO:
		case IPathEntry.CDT_OUTPUT:
		case IPathEntry.CDT_SOURCE:
			return ((APathEntry)entry).getExclusionPatterns();
		}
		return new IPath[0];
	}

	public PathEntryTranslator(IProject project, CConfigurationData cfgData) {
		fProject = project;
		fCfgData = cfgData;
		fRcDataHolder = createRcDataHolder(cfgData);
		fTranslatedFilters = PathSettingsContainer.createRootContainer();
		fTranslatedFilters.setValue(new ResourceInfo[]{new ResourceInfo(fRoot, true)});
	}

	private static PathSettingsContainer createRcDataHolder(CConfigurationData cfgData) {
		return CDataUtil.createRcDataHolder(cfgData);
	}

	public ReferenceSettingsInfo applyPathEntries(PathEntryResolveInfo info, int op) {
		ResolvedEntry[] rEntries = getResolvedEntries(info);
		return addPathEntries(rEntries, op);
	}

	private RcDesInfo getRcDesInfo(PathSettingsContainer cr, ResourceInfo rcInfo) {
		IResource rc = rcInfo.fRc;
		IPath projPath = rc.getProjectRelativePath();
		PathSettingsContainer child = cr.getChildContainer(projPath, true, true);
		RcDesInfo rcDes = (RcDesInfo)child.getValue();
		if (rcDes == null) {
			rcDes = new RcDesInfo(rcInfo);
			child.setValue(rcDes);
		}
		return rcDes;
	}

	private ReferenceSettingsInfo addPathEntries(ResolvedEntry[] rEntries, int op) {
		PathSettingsContainer cr = PathSettingsContainer.createRootContainer();
		cr.setValue(new RcDesInfo(new ResourceInfo(fProject, true)));
		List<IPathEntry> srcList = new ArrayList<IPathEntry>();
		List<IPathEntry> outList = new ArrayList<IPathEntry>();
		List<ResolvedEntry> projList = new ArrayList<ResolvedEntry>();
		List<ResolvedEntry> exportSettingsList = new ArrayList<ResolvedEntry>();
		ICSourceEntry srcEntries[] = null;
		ICOutputEntry outEntries[] = null;
		ResourceInfo rcInfo;
		for (ResolvedEntry rEntry : rEntries) {
			if (rEntry.isReadOnly())
				continue;
			if (toLanguageEntryKind(rEntry.fEntry.getEntryKind()) == 0) {
				switch (rEntry.fEntry.getEntryKind()) {
				case IPathEntry.CDT_SOURCE:
					srcList.add(rEntry.fEntry);
					break;
				case IPathEntry.CDT_OUTPUT:
					outList.add(rEntry.fEntry);
					break;
				case IPathEntry.CDT_PROJECT:
					projList.add(rEntry);
					break;
				}
				continue;
			}

			if (rEntry.getEntry().isExported()) {
				exportSettingsList.add(rEntry);
			}
			rcInfo = rEntry.getResourceInfo();
			RcDesInfo rcDes = getRcDesInfo(cr, rcInfo);

			rcDes.fResolvedEntries.add(rEntry);

			ResourceInfo[] fInfos = rEntry.getFilterInfos();
			for (ResourceInfo fInfo : fInfos) {
				getRcDesInfo(cr, fInfo);
			}
		}

		if (srcList.size() != 0) {
			srcEntries = toCSourceEntries(srcList);
		}
		if (outList.size() != 0) {
			outEntries = toCOutputEntries(outList);
		}

		propagateValues(cr, new ArrayList<LangEntryInfo>(0));

		//applying settings
		applyOutputEntries(outEntries, op);
		applySourceEntries(srcEntries, op);
		applyLangSettings(cr, op);

		IPath refProjPaths[] = new IPath[projList.size()];
		for (int i = 0; i < refProjPaths.length; i++) {
			ResolvedEntry e = projList.get(i);
			refProjPaths[i] = e.getResourceInfo().fRc.getFullPath();
		}

		ICExternalSetting extSettings[];
		if (exportSettingsList.size() != 0) {
			extSettings = new ICExternalSetting[1];
			List<ICLanguageSettingEntry> list = new ArrayList<ICLanguageSettingEntry>(exportSettingsList.size());
			for (int i = 0; i < exportSettingsList.size(); i++) {
				ResolvedEntry re = exportSettingsList.get(i);
				ICLanguageSettingEntry le = createLangEntry(re);
				if (le != null)
					list.add(le);
			}
			ICLanguageSettingEntry expEntries[] = list.toArray(new ICLanguageSettingEntry[list.size()]);
			extSettings[0] = new CExternalSetting(null, null, null, expEntries);
		} else {
			extSettings = new ICExternalSetting[0];
		}

		return new ReferenceSettingsInfo(refProjPaths, extSettings);
	}

	private static ICSourceEntry[] toCSourceEntries(List<IPathEntry> list) {
		ICSourceEntry[] entries = new ICSourceEntry[list.size()];
		for (int i = 0; i < entries.length; i++) {
			entries[i] = toCSourceEntry((ISourceEntry)list.get(i), true);
		}
		return entries;
	}

	private static ICOutputEntry[] toCOutputEntries(List<IPathEntry> list) {
		ICOutputEntry[] entries = new ICOutputEntry[list.size()];
		for (int i = 0; i < entries.length; i++) {
			entries[i] = toCOutputEntry((IOutputEntry)list.get(i), true);
		}
		return entries;
	}


	private static ICSourceEntry toCSourceEntry(ISourceEntry entry, boolean makeProjRelative) {
		IPath path = entry.getPath();
		if (makeProjRelative && path.isAbsolute())
			path = path.removeFirstSegments(1);
		return new CSourceEntry(path,
				entry.getExclusionPatterns(),
				ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
	}

	private static ICOutputEntry toCOutputEntry(IOutputEntry entry, boolean makeProjRelative) {
		IPath path = entry.getPath();
		if (makeProjRelative && path.isAbsolute())
			path = path.removeFirstSegments(1);
		return new COutputEntry(path,
				entry.getExclusionPatterns(),
				ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
	}

	private static ICSettingEntry[] replaceUserEntries(ICSettingEntry[] oldEntries, ICSettingEntry[] newUsrEntries) {
		Set<ICSettingEntry> set = new LinkedHashSet<ICSettingEntry>();
		Class<?> componentType = null;

		if (newUsrEntries != null) {
			for (ICSettingEntry entry : newUsrEntries) {
				if (entry.isBuiltIn() || entry.isReadOnly())
					continue;
				set.add(entry);
			}
			componentType = newUsrEntries.getClass().getComponentType();
		}

		if (oldEntries != null) {
			for (ICSettingEntry entry : oldEntries) {
				if (entry.isBuiltIn() || entry.isReadOnly())
					set.add(entry);
			}
			if (componentType == null)
				componentType = oldEntries.getClass().getComponentType();
		}

		if (componentType != null) {
			ICSettingEntry[] result = (ICSettingEntry[])Array.newInstance(componentType, set.size());
			set.toArray(result);
			return result;
		}
		return null;
	}

	private void applySourceEntries(ICSourceEntry entries[], int op) {
		ICSourceEntry[] oldEntries = fCfgData.getSourceEntries();
		oldEntries = (ICSourceEntry[])CDataUtil.makeRelative(fProject, oldEntries, true);
		entries = (ICSourceEntry[])CDataUtil.makeRelative(fProject, entries, true);
		entries = (ICSourceEntry[])replaceUserEntries(oldEntries, entries);

		switch (op) {
		case OP_ADD:
			if (entries != null && entries.length != 0) {
				Set<ICSourceEntry> set = new LinkedHashSet<ICSourceEntry>();
				set.addAll(Arrays.asList(oldEntries));
				set.addAll(Arrays.asList(entries));
				fCfgData.setSourceEntries(set.toArray(new ICSourceEntry[set.size()]));
			}
			break;
		case OP_REMOVE:
			if (entries != null && entries.length != 0) {
				Set<ICSourceEntry> set = new HashSet<ICSourceEntry>();
				set.addAll(Arrays.asList(oldEntries));
				set.removeAll(Arrays.asList(entries));
				fCfgData.setSourceEntries(set.toArray(new ICSourceEntry[set.size()]));
			}
			break;
		case OP_REPLACE:
		default:
			if (entries != null) {
				fCfgData.setSourceEntries(entries);
			} else {
				fCfgData.setSourceEntries(new ICSourceEntry[0]);
			}
			break;
		}
	}

	private void applyOutputEntries(ICOutputEntry entries[], int op) {
		CBuildData bData = fCfgData.getBuildData();
		if (bData == null) {
			CCorePlugin.log(UtilMessages.getString("PathEntryTranslator.2")); //$NON-NLS-1$
			return;
		}

		ICOutputEntry[] oldEntries = bData.getOutputDirectories();
		oldEntries = (ICOutputEntry[])CDataUtil.makeRelative(fProject, oldEntries, true);
		entries = (ICOutputEntry[])CDataUtil.makeRelative(fProject, entries, true);
		entries = (ICOutputEntry[])replaceUserEntries(oldEntries, entries);

		switch (op) {
		case OP_ADD:
			if (entries != null && entries.length != 0) {
				Set<ICOutputEntry> set = new LinkedHashSet<ICOutputEntry>();
				set.addAll(Arrays.asList(oldEntries));
				set.addAll(Arrays.asList(entries));
				bData.setOutputDirectories(set.toArray(new ICOutputEntry[set.size()]));
			}
			break;
		case OP_REMOVE:
			if (entries != null && entries.length != 0) {
				Set<ICOutputEntry> set = new HashSet<ICOutputEntry>();
				set.addAll(Arrays.asList(oldEntries));
				set.removeAll(Arrays.asList(entries));
				bData.setOutputDirectories(set.toArray(new ICOutputEntry[set.size()]));
			}
			break;
		case OP_REPLACE:
		default:
			if (entries != null) {
				bData.setOutputDirectories(entries);
			} else {
				bData.setOutputDirectories(new ICOutputEntry[0]);
			}
			break;
		}
	}

	private void applyLangSettings(PathSettingsContainer cr, int op) {
		PathSettingsContainer crs[] = cr.getChildren(true);
		for (PathSettingsContainer cur : crs) {
			RcDesInfo desInfo = (RcDesInfo)cur.getValue();
			try {
				CResourceData rcData = getResourceData(cur.getPath(), true, true);
				applyEntries(rcData, desInfo, op);
			} catch (CoreException e) {
				CCorePlugin.log(e);
			}
		}

		CResourceData[] rcDatas = getResourceDatas();
		for (CResourceData rcData : rcDatas) {
			PathSettingsContainer c = cr.getChildContainer(rcData.getPath(), false, false);
			if (cr.getPath().makeRelative().equals(rcData.getPath().makeRelative())) {
				continue;
			}

			RcDesInfo desInfo = (RcDesInfo) c.getValue();
			applyEntries(rcData, desInfo, op);
		}
	}

	private CResourceData[] getResourceDatas() {
		PathSettingsContainer crs[] = fRcDataHolder.getChildren(true);
		List<CResourceData> list = new ArrayList<CResourceData>(crs.length);
		for (PathSettingsContainer cur : crs) {
			list.add((CResourceData)cur.getValue());
		}
		return list.toArray(new CResourceData[list.size()]);
	}

	private CResourceData getResourceData(IPath path, boolean create, boolean exactPath) throws CoreException{
		PathSettingsContainer rcDataH = fRcDataHolder.getChildContainer(path, false, exactPath);
		if (rcDataH != null) {
			return (CResourceData)rcDataH.getValue();
		} else if (create) {
			ResourceInfo rcInfo = findResourceInfo(fProject, path, true);
			CResourceData base = getResourceData(path, false, false);

			CResourceData newRcData;
			if (rcInfo.fRc.getType() == IResource.FILE) {
				if (base.getType() == ICSettingBase.SETTING_FILE) {
					newRcData = fCfgData.createFileData(path, (CFileData)base);
				} else {
					CFolderData folderData = (CFolderData)base;
					CLanguageData lDatas[] = folderData.getLanguageDatas();
					CLanguageData baseLData = CDataUtil.findLanguagDataForFile(rcInfo.fRc.getFullPath().lastSegment(), fProject, lDatas);
					newRcData = fCfgData.createFileData(path, folderData, baseLData);
				}
			} else {
				while (base.getType() == ICSettingBase.SETTING_FILE) {
					base = getResourceData(base.getPath().removeLastSegments(1), false, false);
				}

				newRcData = fCfgData.createFolderData(path, (CFolderData)base);
			}

			fRcDataHolder.getChildContainer(path, true, true).setValue(newRcData);
			return newRcData;
		}
		return null;
	}

	private void applyEntries(CResourceData rcData, RcDesInfo info, int op) {
		CLanguageData lDatas[] = rcData.getType() == ICSettingBase.SETTING_FILE ?
				new CLanguageData[] { ((CFileData)rcData).getLanguageData() } :
				((CFolderData) rcData).getLanguageDatas();

		for (CLanguageData lData : lDatas) {
			if (lData == null)
				continue;

			applyEntries(lData, info, op);
		}
	}


	private void applyEntries(CLanguageData lData, RcDesInfo info, int op) {
		int kinds[] = KindBasedStore.getLanguageEntryKinds();
		int supported = lData.getSupportedEntryKinds();
		for (int kind : kinds) {
			if ((supported & kind) == 0)
				continue;

			ICLanguageSettingEntry opEntries[] = info.getEntries(kind);
			ICLanguageSettingEntry oldEntries[] = lData.getEntries(kind);
			opEntries = (ICLanguageSettingEntry[])replaceUserEntries(oldEntries, opEntries);

			if (op == OP_REPLACE)
				oldEntries = null;
			ICLanguageSettingEntry result[] = composeNewEntries(oldEntries, opEntries, op);
			lData.setEntries(kind, result);
		}
	}

	private ICLanguageSettingEntry[] composeNewEntries(ICLanguageSettingEntry oldEntries[],
			ICLanguageSettingEntry newEntries[],
			int op) {
		ICLanguageSettingEntry result[];
		switch (op) {
		case OP_ADD:{
			Set<ICLanguageSettingEntry> oldSet = new HashSet<ICLanguageSettingEntry>(Arrays.asList(oldEntries));
			Set<ICLanguageSettingEntry> newSet = new HashSet<ICLanguageSettingEntry>(Arrays.asList(newEntries));
			newSet.removeAll(oldSet);
			if (newSet.size() == 0) {
				result = oldEntries;
			} else {
				result = new ICLanguageSettingEntry[oldEntries.length + newSet.size()];
				newSet.toArray(result);
				System.arraycopy(oldEntries, 0, result, newSet.size(), oldEntries.length);
			}
			break;
		}
		case OP_REMOVE:{
			Set<ICLanguageSettingEntry> oldSet = new HashSet<ICLanguageSettingEntry>(Arrays.asList(oldEntries));
			Set<ICLanguageSettingEntry> newSet = new HashSet<ICLanguageSettingEntry>(Arrays.asList(newEntries));
			oldSet.removeAll(newSet);
			if (oldSet.size() == 0) {
				result = new ICLanguageSettingEntry[0];
			} else {
				result = new ICLanguageSettingEntry[oldSet.size()];
				oldSet.toArray(result);
			}
			break;
		}
		case OP_REPLACE:
		default:
			result = newEntries;
			break;
		}

		return result;
	}

	public ReferenceSettingsInfo applyPathEntries(IPathEntry[] usrEntries, IPathEntry[] sysEntries, int op) {
		ResolvedEntry[] rEntries = getResolvedEntries(usrEntries, sysEntries);
		return addPathEntries(rEntries, op);
	}

	private void propagateValues(PathSettingsContainer cr, List<LangEntryInfo> langEntryInfoList) {

		RcDesInfo rcDes = (RcDesInfo)cr.getValue();
		if (rcDes != null) {
			List<ResolvedEntry> rEntries = rcDes.fResolvedEntries;
			List<LangEntryInfo> curLanfInfos = new ArrayList<LangEntryInfo>(rEntries.size() + langEntryInfoList.size());
			for (ResolvedEntry re : rEntries) {
				LangEntryInfo li = createLangEntryInfo(re);
				if (li != null) {
					curLanfInfos.add(li);
				}
			}

			curLanfInfos.addAll(langEntryInfoList);
			langEntryInfoList = curLanfInfos;

			for (LangEntryInfo li : langEntryInfoList) {
				rcDes.add(li);
			}
		}

		PathSettingsContainer directChildren[] = cr.getDirectChildren();
		for (PathSettingsContainer directChild : directChildren) {
			filterAndPropagate(directChild, langEntryInfoList);
		}
	}

	private void filterAndPropagate(PathSettingsContainer cr, List<LangEntryInfo> list) {
		list = new ArrayList<LangEntryInfo>(list);
		IPath path = cr.getPath();
		for (Iterator<LangEntryInfo> iter = list.iterator(); iter.hasNext();) {
			LangEntryInfo li = iter.next();
			ResolvedEntry re = li.fResolvedEntry;
			ResourceInfo[] filters = re.getFilterInfos();
			for (ResourceInfo filter : filters) {
				IResource rc = filter.fRc;
				IPath projPath = rc.getProjectRelativePath();
				if (projPath.isPrefixOf(path.makeRelative())) {
					iter.remove();
					break;
				}
			}
		}

		propagateValues(cr, list);
	}

	private int toLanguageEntryKind(int peKind) {
		switch (peKind) {
		case IPathEntry.CDT_LIBRARY:
			return ICSettingEntry.LIBRARY_FILE;
//		case IPathEntry.CDT_PROJECT:
//			return ICLanguageSettingEntry;
//		case IPathEntry.CDT_SOURCE:
//			return INDEX_CDT_SOURCE;
		case IPathEntry.CDT_INCLUDE:
			return ICSettingEntry.INCLUDE_PATH;
//		case IPathEntry.CDT_CONTAINER:
//			return INDEX_CDT_CONTAINER;
		case IPathEntry.CDT_MACRO:
			return ICSettingEntry.MACRO;
//		case IPathEntry.CDT_OUTPUT:
//			return INDEX_CDT_OUTPUT;
		case IPathEntry.CDT_INCLUDE_FILE:
			return ICSettingEntry.INCLUDE_FILE;
		case IPathEntry.CDT_MACRO_FILE:
			return ICSettingEntry.MACRO_FILE;
		}
		return 0;
	}

	private static int peKindToSettingKind(int peKind) {
		switch (peKind) {
		case IPathEntry.CDT_LIBRARY:
			return ICSettingEntry.LIBRARY_FILE;
//		case IPathEntry.CDT_PROJECT:
//			return ICLanguageSettingEntry;
		case IPathEntry.CDT_SOURCE:
			return ICSettingEntry.SOURCE_PATH;
		case IPathEntry.CDT_INCLUDE:
			return ICSettingEntry.INCLUDE_PATH;
//		case IPathEntry.CDT_CONTAINER:
//			return INDEX_CDT_CONTAINER;
		case IPathEntry.CDT_MACRO:
			return ICSettingEntry.MACRO;
		case IPathEntry.CDT_OUTPUT:
			return ICSettingEntry.OUTPUT_PATH;
		case IPathEntry.CDT_INCLUDE_FILE:
			return ICSettingEntry.INCLUDE_FILE;
		case IPathEntry.CDT_MACRO_FILE:
			return ICSettingEntry.MACRO_FILE;
		}
		return 0;
	}

	private ResolvedEntry[] getResolvedEntries(PathEntryResolveInfo info) {
		PathEntryResolveInfoElement els[] = info.getElements();
		List<ResolvedEntry> list = new ArrayList<ResolvedEntry>();
		for (PathEntryResolveInfoElement el : els) {
			getResolvedEntries(el, list);
		}
		return list.toArray(new ResolvedEntry[list.size()]);
	}

	private List<ResolvedEntry> getResolvedEntries(PathEntryResolveInfoElement el, List<ResolvedEntry> list) {
		if (list == null)
			list = new ArrayList<ResolvedEntry>();

		IPathEntry[] rpEntries = el.getResolvedEntries();
		ResolvedEntry resolvedE;
		IPathEntry rawEntry = el.getRawEntry();
		if (rawEntry.getEntryKind() == IPathEntry.CDT_PROJECT) {
			resolvedE = createResolvedEntry(rawEntry, el);
			if (resolvedE != null)
				list.add(resolvedE);
		}
		for (IPathEntry rpEntry : rpEntries) {
			resolvedE = createResolvedEntry(rpEntry, el);
			if (resolvedE != null)
				list.add(resolvedE);
		}
		return list;
	}

	private ResolvedEntry createResolvedEntry(IPathEntry entry, PathEntryResolveInfoElement el) {
		switch (entry.getEntryKind()) {
//		case IPathEntry.CDT_PROJECT:
//			//should not be here
		case IPathEntry.CDT_CONTAINER:
			//the case of extension path entry container
			return null;
		}
		return new ResolvedEntry(entry, el);
	}


	private ResolvedEntry[] getResolvedEntries(IPathEntry[] usrEntries, IPathEntry[] sysEntries) {
		int length = usrEntries != null ? usrEntries.length : 0;
		if (sysEntries != null)
			length += sysEntries.length;
		ResolvedEntry[] rEntries = new ResolvedEntry[length];
		int num = 0;
		if (usrEntries != null) {
			for (IPathEntry usrEntry : usrEntries) {
				rEntries[num++] = new ResolvedEntry(usrEntry, false);
			}
		}

		if (sysEntries != null) {
			for (IPathEntry sysEntry : sysEntries) {
				rEntries[num++] = new ResolvedEntry(sysEntry, true);
			}
		}
		return rEntries;
	}

	private ResourceInfo[] resolveFilter(IContainer container, IPath path) {
		IPath containerFullPath = container.getFullPath();
		IPath fullPath = containerFullPath.append(path);
		PathSettingsContainer cr = fTranslatedFilters.getChildContainer(fullPath, false, false);
		ResourceInfo[] baseInfos = (ResourceInfo[])cr.getValue();
		ResourceInfo[] result;
		if (!baseInfos[0].fExists) {
			// resource does not exist, always create new rc info and not add it to map
			ResourceInfo inexistent = new ResourceInfo(container.getFolder(path), false);
			result = new ResourceInfo[]{inexistent};
		} else {
			// base exists
			IPath baseTranslatedPath = cr.getPath();
			if (baseTranslatedPath.equals(fullPath)) {
				result = baseInfos;
			} else if (containerFullPath.isPrefixOf(baseTranslatedPath)) {
				IPath filterToTranslate = fullPath.removeFirstSegments(baseTranslatedPath.segmentCount());
				result = performTranslation(baseTranslatedPath, baseInfos, filterToTranslate);
			} else {
				// should never be here
				throw new IllegalStateException();
			}
		}

		return result;
	}

	private ResourceInfo[] performTranslation(IPath basePath, ResourceInfo baseInfos[], IPath filter) {
		ResourceInfo result[];
		int segCount = filter.segmentCount();
		String seg;
		int i = 0;
		for (; i < segCount; i++) {
			if (!baseInfos[0].fExists)
				break;
			seg = filter.segment(0);
			baseInfos = performTranslation(basePath, baseInfos, seg);
			basePath = basePath.append(seg);
			filter = filter.removeFirstSegments(1);
		}

		if (i < segCount) {
			result = new ResourceInfo[baseInfos.length];
			ResourceInfo baseInfo;
			IFolder rc;

			for (int k = 0; k < baseInfos.length; k++) {
				baseInfo = baseInfos[k];
				rc = (IFolder)baseInfo.fRc;
				rc = rc.getFolder(filter);
				result[k] = new ResourceInfo(rc, false);
			}
		} else {
			result = baseInfos;
		}

		return result;
	}

	private ResourceInfo[] performTranslation(IPath basePath, ResourceInfo[] baseInfos, String seg) {
		IPath filterFullPath = basePath.append(seg);
		boolean needsParsing = hasSpecChars(seg);
		List<ResourceInfo> list = new ArrayList<ResourceInfo>();
		char[] segChars = seg.toCharArray();
		for (ResourceInfo baseInfo : baseInfos) {
			IResource baseRc = baseInfo.fRc;
			if (baseRc.getType() == IResource.FILE) {
				continue;
			} else {
				IContainer baseCr = (IContainer)baseRc;
				IResource rc = baseCr.findMember(seg);
				if (rc != null) {
					ResourceInfo rcInfo = new ResourceInfo(rc, true);
					addRcInfoToMap(rcInfo);
					list.add(rcInfo);
				} else if (needsParsing) {
					try {
						IResource children[] = baseCr.members();
						ResourceInfo rcInfo;
						for (IResource child : children) {
							if (CoreModelUtil.match(segChars, child.getName().toCharArray(), true)) {
								rcInfo = new ResourceInfo(child, true);
								addRcInfoToMap(rcInfo);
								list.add(rcInfo);
							}
						}
					} catch (CoreException e) {
						CCorePlugin.log(e);
					}
				}
			}
		}

		if (list.size() == 0) {
			IFolder f = fRoot.getFolder(filterFullPath);
			ResourceInfo rcInfo = new ResourceInfo(f, false);
			addRcInfoToMap(rcInfo);
			list.add(rcInfo);
		}

		ResourceInfo[] result = new ResourceInfo[list.size()];
		list.toArray(result);
		addResolvedFilterToMap(filterFullPath, result, false);
		return result;
	}

	private boolean hasSpecChars(String str) {
		for (char ch : SPEC_CHARS) {
			if (str.indexOf(ch) != -1)
				return true;
		}
		return false;
	}

	private void addResolvedFilterToMap(IPath fullFilterPath ,ResourceInfo[] resolved, boolean check) {
		if (check) {
			PathSettingsContainer cr = fTranslatedFilters.getChildContainer(fullFilterPath, false, false);
			ResourceInfo[] infos = (ResourceInfo[])cr.getValue();
			if (!infos[0].fExists)
				return;
		}

		PathSettingsContainer cr = fTranslatedFilters.getChildContainer(fullFilterPath, true, true);
		cr.setValue(resolved);
	}

	private ResourceInfo findResourceInfo(IContainer container, IPath relPath, boolean folderIfNotExist) {
		IPath fullPath = container.getFullPath().append(relPath);
		ResourceInfo rcInfo = fResourceMap.get(fullPath);

		if (rcInfo == null) {
			IResource rc = container.findMember(relPath);
			boolean exists = true;
			if (rc == null) {
				exists = false;
				if (container.getType() == IResource.ROOT && relPath.segmentCount() == 1) {
					rc = fRoot.getProject(relPath.segment(0));
				} else if (folderIfNotExist) {
					rc = container.getFolder(relPath);
				} else {
					rc = container.getFile(relPath);
				}
			}

			rcInfo = new ResourceInfo(rc, exists);
			addRcInfoToMap(rcInfo);
		}
		return rcInfo;
	}

	private void addRcInfoToMap(ResourceInfo rcInfo) {
		IPath fullPath = rcInfo.fRc.getFullPath();
		fResourceMap.put(fullPath, rcInfo);
		addResolvedFilterToMap(fullPath, new ResourceInfo[]{rcInfo}, true);
	}

	public static IPathEntry[] decodePathEntries(IProject project, ICStorageElement el) {
		ArrayList<IPathEntry> pathEntries = new ArrayList<IPathEntry>();
		ICStorageElement children[] = el.getChildren();
		for (ICStorageElement child : children) {
			if (child.getName().equals(PATH_ENTRY)) {
				try {
					pathEntries.add(decodePathEntry(project, child));
				} catch (CModelException e) {
					CCorePlugin.log(e);
				}
			}
		}
		IPathEntry[] entries = new IPathEntry[pathEntries.size()];
		pathEntries.toArray(entries);
		return entries;
	}

	private static String getAttribute(ICStorageElement el, String attr) {
		String v = el.getAttribute(attr);
		if (v != null)
			return v;
		return ""; //$NON-NLS-1$
	}

	static IPathEntry decodePathEntry(IProject project, ICStorageElement element) throws CModelException {
		IPath projectPath = project.getFullPath();

		// kind
		String kindAttr = getAttribute(element, ATTRIBUTE_KIND);
		int kind = PathEntry.kindFromString(kindAttr);

		// exported flag
		boolean isExported = false;
		if (element.getAttribute(ATTRIBUTE_EXPORTED) != null) {
			isExported = element.getAttribute(ATTRIBUTE_EXPORTED).equals(VALUE_TRUE);
		}

		// get path and ensure it is absolute
		IPath path;
		if (element.getAttribute(ATTRIBUTE_PATH) != null) {
			path = new Path(element.getAttribute(ATTRIBUTE_PATH));
		} else {
			path = new Path(""); //$NON-NLS-1$
		}
		if (!path.isAbsolute()) {
			path = projectPath.append(path);
		}

		// check fo the base path
		IPath basePath = new Path(getAttribute(element, ATTRIBUTE_BASE_PATH));

		// get the base ref
		IPath baseRef = new Path(getAttribute(element, ATTRIBUTE_BASE_REF));

		// exclusion patterns (optional)
		String exclusion = getAttribute(element, ATTRIBUTE_EXCLUDING);
		IPath[] exclusionPatterns = APathEntry.NO_EXCLUSION_PATTERNS;
		if (exclusion != null && exclusion.length() > 0) {
			char[][] patterns = CharOperation.splitOn('|', exclusion.toCharArray());
			int patternCount;
			if ((patternCount = patterns.length) > 0) {
				exclusionPatterns = new IPath[patternCount];
				for (int j = 0; j < patterns.length; j++) {
					exclusionPatterns[j] = new Path(new String(patterns[j]));
				}
			}
		}

		// recreate the entry
		switch (kind) {
			case IPathEntry.CDT_PROJECT:
				return CoreModel.newProjectEntry(path, isExported);
			case IPathEntry.CDT_LIBRARY: {
				IPath libraryPath = new Path(getAttribute(element, ATTRIBUTE_LIBRARY));
				// source attachment info (optional)
				IPath sourceAttachmentPath = element.getAttribute(ATTRIBUTE_SOURCEPATH) != null ? new Path(
						element.getAttribute(ATTRIBUTE_SOURCEPATH)) : null;
				IPath sourceAttachmentRootPath = element.getAttribute(ATTRIBUTE_ROOTPATH) != null ? new Path(
						element.getAttribute(ATTRIBUTE_ROOTPATH)) : null;
				IPath sourceAttachmentPrefixMapping = element.getAttribute(ATTRIBUTE_PREFIXMAPPING) != null ? new Path(
						element.getAttribute(ATTRIBUTE_PREFIXMAPPING)) : null;

				if (!baseRef.isEmpty()) {
					return CoreModel.newLibraryRefEntry(path, baseRef, libraryPath);
				}
				return CoreModel.newLibraryEntry(path, basePath, libraryPath, sourceAttachmentPath, sourceAttachmentRootPath,
					sourceAttachmentPrefixMapping, isExported);
			}
			case IPathEntry.CDT_SOURCE: {
				// must be an entry in this project or specify another
				// project
				String projSegment = path.segment(0);
				if (projSegment != null && projSegment.equals(project.getName())) { // this
					// project
					return CoreModel.newSourceEntry(path, exclusionPatterns);
				}
				// another project
				return CoreModel.newProjectEntry(path, isExported);
			}
			case IPathEntry.CDT_OUTPUT:
				return CoreModel.newOutputEntry(path, exclusionPatterns);
			case IPathEntry.CDT_INCLUDE: {
				// include path info
				IPath includePath = new Path(getAttribute(element, ATTRIBUTE_INCLUDE));
				// isSysteminclude
				boolean isSystemInclude = false;
				if (element.getAttribute(ATTRIBUTE_SYSTEM) != null) {
					isSystemInclude = getAttribute(element, ATTRIBUTE_SYSTEM).equals(VALUE_TRUE);
				}
				if (!baseRef.isEmpty()) {
					return CoreModel.newIncludeRefEntry(path, baseRef, includePath);
				}
				return CoreModel.newIncludeEntry(path, basePath, includePath, isSystemInclude, exclusionPatterns, isExported);
			}
			case IPathEntry.CDT_INCLUDE_FILE: {
				// include path info
				IPath includeFilePath = new Path(getAttribute(element, ATTRIBUTE_INCLUDE_FILE));
				return CoreModel.newIncludeFileEntry(path, basePath, baseRef, includeFilePath, exclusionPatterns, isExported);
			}
			case IPathEntry.CDT_MACRO: {
				String macroName = getAttribute(element, ATTRIBUTE_NAME);
				String macroValue = getAttribute(element, ATTRIBUTE_VALUE);
				if (!baseRef.isEmpty()) {
					return CoreModel.newMacroRefEntry(path, baseRef, macroName);
				}
				return CoreModel.newMacroEntry(path, macroName, macroValue, exclusionPatterns, isExported);
			}
			case IPathEntry.CDT_MACRO_FILE: {
				IPath macroFilePath = new Path(getAttribute(element, ATTRIBUTE_MACRO_FILE));
				return CoreModel.newMacroFileEntry(path, basePath, baseRef, macroFilePath, exclusionPatterns, isExported);
			}
			case IPathEntry.CDT_CONTAINER: {
				IPath id = new Path(getAttribute(element, ATTRIBUTE_PATH));
				return CoreModel.newContainerEntry(id, isExported);
			}
			default: {
				ICModelStatus status = new CModelStatus(IStatus.ERROR, "PathEntry: unknown kind (" + kindAttr + ")"); //$NON-NLS-1$ //$NON-NLS-2$
				throw new CModelException(status);
			}
		}
	}

	private static CConfigurationData getCfgData(ICConfigurationDescription cfgDescription) {
		return cfgDescription instanceof CConfigurationDescriptionCache ?
				(CConfigurationData)cfgDescription : ((IInternalCCfgInfo)cfgDescription).getConfigurationData(false);
	}

	private static void addOutputEntries(PathEntryCollector cr, CConfigurationData cfgData) {
		CBuildData bData = cfgData.getBuildData();
		if (bData != null) {
			ICOutputEntry oEntries[] = bData.getOutputDirectories();
			if (oEntries != null && oEntries.length != 0) {
				cr.setSourceOutputEntries(ICSettingEntry.OUTPUT_PATH, oEntries);
			}
		}
	}

	public static PathEntryCollector collectEntries(IProject project, final ICConfigurationDescription cfgDescription) {
		CConfigurationData cfgData = getCfgData(cfgDescription);

		ReferenceSettingsInfo refInfo = new ReferenceSettingsInfo(cfgDescription);
		ICConfigurationDescription[] allCfgDescriptions = cfgDescription.isPreferenceConfiguration() ?
				new ICConfigurationDescription[] { cfgDescription } :
				cfgDescription.getProjectDescription().getConfigurations();

		CConfigurationData[] allDatas = new CConfigurationData[allCfgDescriptions.length];
		for (int i = 0; i < allCfgDescriptions.length; i++) {
			allDatas[i] = getCfgData(allCfgDescriptions[i]);
		}

		final PathEntryCollector collector = new PathEntryCollector(project/*, cfgDescription*/);
		PathSettingsContainer rcDatas = createRcDataHolder(cfgData);
		ICSourceEntry sEntries[] = cfgData.getSourceEntries();
		if (sEntries != null && sEntries.length != 0) {
			collector.setSourceOutputEntries(ICSettingEntry.SOURCE_PATH, sEntries);
		}
		for (CConfigurationData allData : allDatas) {
			addOutputEntries(collector, allData);
		}
		final HashSet<ICSettingEntry> exportedSettings = new HashSet<ICSettingEntry>();
		collector.setRefProjects(refInfo.getReferencedProjectsPaths());
		ICExternalSetting[] settings = refInfo.getExternalSettings();
		for (ICExternalSetting setting : settings) {
			exportedSettings.addAll(Arrays.asList(setting.getEntries()));
		}

		final int kinds[] = KindBasedStore.getLanguageEntryKinds();
		rcDatas.accept(new IPathSettingsContainerVisitor() {
			@Override
			public boolean visit(PathSettingsContainer container) {
				CResourceData rcData = (CResourceData)container.getValue();
				if (rcData != null) {
					PathEntryCollector child = collector.createChild(container.getPath());
					for (int kind : kinds) {
						Set<ICLanguageSettingEntry> set = new LinkedHashSet<ICLanguageSettingEntry>();
						if (collectResourceDataEntries(cfgDescription, kind, rcData, set)) {
							ICLanguageSettingEntry[] entries = set.toArray(new ICLanguageSettingEntry[set.size()]);
							child.setEntries(kind, entries, exportedSettings);
						}
					}
				}
				return true;
			}
		});
		return collector;
	}

	private static boolean collectResourceDataEntries(ICConfigurationDescription cfgDescription, int kind, CResourceData rcData, Set<ICLanguageSettingEntry> list) {
		CLanguageData[] lDatas = null;
		if (rcData instanceof CFolderData) {
			lDatas = ((CFolderData)rcData).getLanguageDatas();
		} else if (rcData instanceof CFileData) {
			CLanguageData lData = ((CFileData)rcData).getLanguageData();
			if (lData != null)
				lDatas = new CLanguageData[] {lData};
		} else {
			Exception e = new Exception(UtilMessages.getString("PathEntryTranslator.1") + rcData.getClass().getName()); //$NON-NLS-1$
			IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, e.getMessage(), e);
			CCorePlugin.log(status);
		}
		if (lDatas == null || lDatas.length == 0) {
			return false;
		}

		IProject project = cfgDescription.getProjectDescription().getProject();
		if (ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(project)) {
			IResource rc = findResourceInWorkspace(project, rcData.getPath());
			if (rc != null) {
				for (CLanguageData lData : lDatas) {
					list.addAll(LanguageSettingsProvidersSerializer.getSettingEntriesByKind(cfgDescription, rc, lData.getLanguageId(), kind));
				}
			}
			return list.size()>0;

		}
		// Legacy logic (before Language Settings Providers)
		boolean supported = false;
		for (CLanguageData lData : lDatas) {
			if (collectLanguageDataEntries(kind, lData, list))
				supported = true;
		}
		return supported;
	}

	private static boolean collectLanguageDataEntries(int kind, CLanguageData lData, Set<ICLanguageSettingEntry> list) {
		if ((kind & lData.getSupportedEntryKinds()) != 0) {
			ICLanguageSettingEntry[] entries = lData.getEntries(kind);
			if (entries != null && entries.length != 0) {
				list.addAll(Arrays.asList(entries));
			}
			return true;
		}

		return false;
	}

	public static IPathEntry[] getPathEntries(IProject project, ICConfigurationDescription cfgDescription, int flags) {
		PathEntryCollector cr = collectEntries(project, cfgDescription);
		return cr.getEntries(flags, cfgDescription);
	}

	private static IResource findResourceInWorkspace(IProject project, IPath workspacePath) {
		IResource rc;
		if (project != null) {
			rc = project.findMember(workspacePath);
		} else {
			rc = ResourcesPlugin.getWorkspace().getRoot().findMember(workspacePath);
		}
		return rc;
	}
}

Back to the top