mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 23:35:48 +02:00
making resource tree to appear as "compacted" for the user
This commit is contained in:
parent
2d2311a2a6
commit
e1e1bc2e19
6 changed files with 388 additions and 152 deletions
|
@ -100,6 +100,13 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting
|
||||||
return super.processLine(line, epm);
|
return super.processLine(line, epm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO - test cases
|
||||||
|
@Override
|
||||||
|
public void shutdown() {
|
||||||
|
LanguageSettingsManager.buildResourceTree(this, currentCfgDescription, currentLanguageId, currentProject);
|
||||||
|
super.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trivial Error Parser which allows highlighting of output lines matching the patterns
|
* Trivial Error Parser which allows highlighting of output lines matching the patterns
|
||||||
* of this parser. Intended for better troubleshooting experience.
|
* of this parser. Intended for better troubleshooting experience.
|
||||||
|
|
|
@ -778,4 +778,127 @@ public class LanguageSettingsManagerTests extends TestCase {
|
||||||
// check for no side effect
|
// check for no side effect
|
||||||
assertSame(provider, providers.get(0));
|
assertSame(provider, providers.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public void testBuildResourceTree_FileInFolder() throws Exception {
|
||||||
|
// sample entries
|
||||||
|
CMacroEntry entry = new CMacroEntry("MACRO", null, 0);
|
||||||
|
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
entries.add(entry);
|
||||||
|
|
||||||
|
// create resources
|
||||||
|
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||||
|
IFile file = ResourceHelper.createFile(project, "file.cpp");
|
||||||
|
assertNotNull(file);
|
||||||
|
|
||||||
|
// create a provider and set the entries
|
||||||
|
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||||
|
provider.setSettingEntries(null, file, null, entries);
|
||||||
|
// build the hierarchy
|
||||||
|
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
||||||
|
|
||||||
|
// check that entries go to highest possible level
|
||||||
|
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null));
|
||||||
|
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public void testBuildResourceTree_FileInSubFolder() throws Exception {
|
||||||
|
// sample entries
|
||||||
|
CMacroEntry entry = new CMacroEntry("MACRO", null, 0);
|
||||||
|
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
entries.add(entry);
|
||||||
|
|
||||||
|
// create resources
|
||||||
|
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||||
|
IFolder folder = ResourceHelper.createFolder(project, "Folder");
|
||||||
|
IFile file = ResourceHelper.createFile(project, "Folder/file.cpp");
|
||||||
|
|
||||||
|
// create a provider and set the entries
|
||||||
|
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||||
|
provider.setSettingEntries(null, file, null, entries);
|
||||||
|
// build the hierarchy
|
||||||
|
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
||||||
|
|
||||||
|
// check that entries go to highest possible level
|
||||||
|
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null));
|
||||||
|
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder, null));
|
||||||
|
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public void testBuildResourceTree_TwoSubFolders() throws Exception {
|
||||||
|
// sample entries
|
||||||
|
List<ICLanguageSettingEntry> entries1 = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
entries1.add(new CMacroEntry("MACRO_1", null, 0));
|
||||||
|
List<ICLanguageSettingEntry> entries2 = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
entries2.add(new CMacroEntry("MACRO_2", null, 0));
|
||||||
|
|
||||||
|
// create resources
|
||||||
|
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||||
|
IFolder folder1 = ResourceHelper.createFolder(project, "Folder1");
|
||||||
|
IFolder folder2 = ResourceHelper.createFolder(project, "Folder2");
|
||||||
|
IFile file1 = ResourceHelper.createFile(project, "Folder1/file1.cpp");
|
||||||
|
IFile file2 = ResourceHelper.createFile(project, "Folder2/file2.cpp");
|
||||||
|
|
||||||
|
// create a provider and set the entries
|
||||||
|
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||||
|
provider.setSettingEntries(null, file1, null, entries1);
|
||||||
|
provider.setSettingEntries(null, file2, null, entries2);
|
||||||
|
// build the hierarchy
|
||||||
|
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
||||||
|
|
||||||
|
// check that entries go to highest possible level
|
||||||
|
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null));
|
||||||
|
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder1, null));
|
||||||
|
|
||||||
|
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null));
|
||||||
|
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder2, null));
|
||||||
|
|
||||||
|
assertEquals(0, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null).size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public void testBuildResourceTree_IncrementalBuildFlippingSettings() throws Exception {
|
||||||
|
// sample entries
|
||||||
|
List<ICLanguageSettingEntry> entries1 = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
entries1.add(new CMacroEntry("MACRO_1", null, 0));
|
||||||
|
List<ICLanguageSettingEntry> entries2 = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
entries2.add(new CMacroEntry("MACRO_2", null, 0));
|
||||||
|
|
||||||
|
// create resources
|
||||||
|
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||||
|
IFile file1 = ResourceHelper.createFile(project, "file1.cpp");
|
||||||
|
IFile file2 = ResourceHelper.createFile(project, "file2.cpp");
|
||||||
|
IFile file3 = ResourceHelper.createFile(project, "file3.cpp");
|
||||||
|
|
||||||
|
// create a provider
|
||||||
|
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||||
|
|
||||||
|
// set the entries for the first 2 files
|
||||||
|
provider.setSettingEntries(null, file1, null, entries1);
|
||||||
|
provider.setSettingEntries(null, file2, null, entries1);
|
||||||
|
// build the hierarchy
|
||||||
|
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
||||||
|
// double-check where the entries go
|
||||||
|
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null));
|
||||||
|
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null));
|
||||||
|
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null));
|
||||||
|
|
||||||
|
// set the entries for the second+third files (with overlap)
|
||||||
|
provider.setSettingEntries(null, file2, null, entries2);
|
||||||
|
provider.setSettingEntries(null, file3, null, entries2);
|
||||||
|
// build the hierarchy
|
||||||
|
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
||||||
|
// check where the entries go, it should not lose entries for the first file
|
||||||
|
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null));
|
||||||
|
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null));
|
||||||
|
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file3, null));
|
||||||
|
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -823,156 +823,6 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public void testSort_Kinds() throws Exception {
|
|
||||||
// create sample entries
|
|
||||||
CIncludePathEntry includePathEntry1 = new CIncludePathEntry("path1", 0);
|
|
||||||
CIncludePathEntry includePathEntry2 = new CIncludePathEntry("path2", 0);
|
|
||||||
CMacroEntry macroEntry1 = new CMacroEntry("MACRO1", null, 0);
|
|
||||||
CMacroEntry macroEntry2 = new CMacroEntry("MACRO2", null, 0);
|
|
||||||
CIncludeFileEntry includeFileEntry1 = new CIncludeFileEntry("file1", 0);
|
|
||||||
CIncludeFileEntry includeFileEntry2 = new CIncludeFileEntry("file2", 0);
|
|
||||||
CMacroFileEntry macroFileEntry1 = new CMacroFileEntry("file1", 0);
|
|
||||||
CMacroFileEntry macroFileEntry2 = new CMacroFileEntry("file2", 0);
|
|
||||||
CLibraryPathEntry libraryPathEntry1 = new CLibraryPathEntry("lib1", 0);
|
|
||||||
CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib2", 0);
|
|
||||||
CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file1", 0);
|
|
||||||
CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file2", 0);
|
|
||||||
|
|
||||||
// place entries in unsorted list
|
|
||||||
List<ICLanguageSettingEntry> unsortedEntries = new ArrayList<ICLanguageSettingEntry>();
|
|
||||||
unsortedEntries.add(macroEntry1);
|
|
||||||
unsortedEntries.add(macroFileEntry1);
|
|
||||||
unsortedEntries.add(macroEntry2);
|
|
||||||
unsortedEntries.add(includePathEntry1);
|
|
||||||
unsortedEntries.add(includeFileEntry1);
|
|
||||||
unsortedEntries.add(macroFileEntry2);
|
|
||||||
unsortedEntries.add(libraryFileEntry1);
|
|
||||||
unsortedEntries.add(includeFileEntry2);
|
|
||||||
unsortedEntries.add(libraryFileEntry2);
|
|
||||||
unsortedEntries.add(libraryPathEntry1);
|
|
||||||
unsortedEntries.add(includePathEntry2);
|
|
||||||
unsortedEntries.add(libraryPathEntry2);
|
|
||||||
|
|
||||||
// create a provider and set the entries
|
|
||||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
|
||||||
provider.setSettingEntries(null, null, null, unsortedEntries);
|
|
||||||
|
|
||||||
// retrieve and check that language settings got sorted properly
|
|
||||||
assertEquals(PROVIDER_1, provider.getId());
|
|
||||||
int i=0;
|
|
||||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
|
||||||
assertEquals(includePathEntry1, actual.get(i++));
|
|
||||||
assertEquals(includePathEntry2, actual.get(i++));
|
|
||||||
assertEquals(includeFileEntry1, actual.get(i++));
|
|
||||||
assertEquals(includeFileEntry2, actual.get(i++));
|
|
||||||
assertEquals(macroEntry1, actual.get(i++));
|
|
||||||
assertEquals(macroEntry2, actual.get(i++));
|
|
||||||
assertEquals(macroFileEntry1, actual.get(i++));
|
|
||||||
assertEquals(macroFileEntry2, actual.get(i++));
|
|
||||||
assertEquals(libraryPathEntry1, actual.get(i++));
|
|
||||||
assertEquals(libraryPathEntry2, actual.get(i++));
|
|
||||||
assertEquals(libraryFileEntry1, actual.get(i++));
|
|
||||||
assertEquals(libraryFileEntry2, actual.get(i++));
|
|
||||||
|
|
||||||
assertEquals(unsortedEntries.size(), actual.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public void testSort_Entries() throws Exception {
|
|
||||||
// create sample entries
|
|
||||||
CIncludePathEntry includePathEntry1 = new CIncludePathEntry("path_B", 0);
|
|
||||||
CIncludePathEntry includePathEntry2 = new CIncludePathEntry("path_A", 0);
|
|
||||||
CMacroEntry macroEntry1 = new CMacroEntry("MACRO_A", null, 0);
|
|
||||||
CMacroEntry macroEntry2 = new CMacroEntry("MACRO_B", null, 0);
|
|
||||||
CIncludeFileEntry includeFileEntry1 = new CIncludeFileEntry("file_B", 0);
|
|
||||||
CIncludeFileEntry includeFileEntry2 = new CIncludeFileEntry("file_A", 0);
|
|
||||||
CMacroFileEntry macroFileEntry1 = new CMacroFileEntry("file_B", 0);
|
|
||||||
CMacroFileEntry macroFileEntry2 = new CMacroFileEntry("file_A", 0);
|
|
||||||
CLibraryPathEntry libraryPathEntry1 = new CLibraryPathEntry("lib_B", 0);
|
|
||||||
CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib_A", 0);
|
|
||||||
CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file_B", 0);
|
|
||||||
CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file_A", 0);
|
|
||||||
|
|
||||||
// place entries in unsorted list
|
|
||||||
List<ICLanguageSettingEntry> unsortedEntries = new ArrayList<ICLanguageSettingEntry>();
|
|
||||||
// macros will be sorted by name
|
|
||||||
unsortedEntries.add(macroEntry2);
|
|
||||||
unsortedEntries.add(macroEntry1);
|
|
||||||
// paths are not sorted only grouped by kind
|
|
||||||
unsortedEntries.add(macroFileEntry1);
|
|
||||||
unsortedEntries.add(macroFileEntry2);
|
|
||||||
unsortedEntries.add(includePathEntry1);
|
|
||||||
unsortedEntries.add(includePathEntry2);
|
|
||||||
unsortedEntries.add(includeFileEntry1);
|
|
||||||
unsortedEntries.add(includeFileEntry2);
|
|
||||||
unsortedEntries.add(libraryFileEntry1);
|
|
||||||
unsortedEntries.add(libraryFileEntry2);
|
|
||||||
unsortedEntries.add(libraryPathEntry1);
|
|
||||||
unsortedEntries.add(libraryPathEntry2);
|
|
||||||
|
|
||||||
// create a provider and set the entries
|
|
||||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
|
||||||
provider.setSettingEntries(null, null, null, unsortedEntries);
|
|
||||||
|
|
||||||
// retrieve and check that language settings got sorted properly
|
|
||||||
assertEquals(PROVIDER_1, provider.getId());
|
|
||||||
int i=0;
|
|
||||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
|
||||||
assertEquals(includePathEntry1, actual.get(i++));
|
|
||||||
assertEquals(includePathEntry2, actual.get(i++));
|
|
||||||
assertEquals(includeFileEntry1, actual.get(i++));
|
|
||||||
assertEquals(includeFileEntry2, actual.get(i++));
|
|
||||||
assertEquals(macroEntry1, actual.get(i++));
|
|
||||||
assertEquals(macroEntry2, actual.get(i++));
|
|
||||||
assertEquals(macroFileEntry1, actual.get(i++));
|
|
||||||
assertEquals(macroFileEntry2, actual.get(i++));
|
|
||||||
assertEquals(libraryPathEntry1, actual.get(i++));
|
|
||||||
assertEquals(libraryPathEntry2, actual.get(i++));
|
|
||||||
assertEquals(libraryFileEntry1, actual.get(i++));
|
|
||||||
assertEquals(libraryFileEntry2, actual.get(i++));
|
|
||||||
|
|
||||||
assertEquals(unsortedEntries.size(), actual.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public void testSort_Undef() throws Exception {
|
|
||||||
// create sample entries
|
|
||||||
CMacroEntry macroEntry1 = new CMacroEntry("MACRO_1", null, 0);
|
|
||||||
CMacroEntry macroEntry2A = new CMacroEntry("MACRO_2", null, ICSettingEntry.UNDEFINED);
|
|
||||||
CMacroEntry macroEntry2B = new CMacroEntry("MACRO_2", null, 0);
|
|
||||||
CMacroEntry macroEntry2C = new CMacroEntry("MACRO_2", null, ICSettingEntry.BUILTIN);
|
|
||||||
CMacroEntry macroEntry3 = new CMacroEntry("MACRO_3", null, 0);
|
|
||||||
|
|
||||||
// place entries in unsorted list
|
|
||||||
List<ICLanguageSettingEntry> unsortedEntries = new ArrayList<ICLanguageSettingEntry>();
|
|
||||||
// macros will be sorted by name and keep order for the same name
|
|
||||||
unsortedEntries.add(macroEntry2A);
|
|
||||||
unsortedEntries.add(macroEntry3);
|
|
||||||
unsortedEntries.add(macroEntry2B);
|
|
||||||
unsortedEntries.add(macroEntry1);
|
|
||||||
unsortedEntries.add(macroEntry2C);
|
|
||||||
|
|
||||||
// create a provider and set the entries
|
|
||||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
|
||||||
provider.setSettingEntries(null, null, null, unsortedEntries);
|
|
||||||
|
|
||||||
// retrieve and check that language settings got sorted properly
|
|
||||||
assertEquals(PROVIDER_1, provider.getId());
|
|
||||||
int i=0;
|
|
||||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
|
||||||
assertEquals(macroEntry1, actual.get(i++));
|
|
||||||
assertEquals(macroEntry2A, actual.get(i++));
|
|
||||||
assertEquals(macroEntry2B, actual.get(i++));
|
|
||||||
assertEquals(macroEntry2C, actual.get(i++));
|
|
||||||
assertEquals(macroEntry3, actual.get(i++));
|
|
||||||
|
|
||||||
assertEquals(unsortedEntries.size(), actual.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public void testLanguageAndNull() throws Exception {
|
public void testLanguageAndNull() throws Exception {
|
||||||
|
@ -1292,6 +1142,154 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
||||||
List<ICLanguageSettingEntry> actual = providerClone.getSettingEntries(null, null, null);
|
List<ICLanguageSettingEntry> actual = providerClone.getSettingEntries(null, null, null);
|
||||||
assertNull(actual);
|
assertNull(actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public void testSort_Kinds() throws Exception {
|
||||||
|
// create sample entries
|
||||||
|
CIncludePathEntry includePathEntry1 = new CIncludePathEntry("path1", 0);
|
||||||
|
CIncludePathEntry includePathEntry2 = new CIncludePathEntry("path2", 0);
|
||||||
|
CMacroEntry macroEntry1 = new CMacroEntry("MACRO1", null, 0);
|
||||||
|
CMacroEntry macroEntry2 = new CMacroEntry("MACRO2", null, 0);
|
||||||
|
CIncludeFileEntry includeFileEntry1 = new CIncludeFileEntry("file1", 0);
|
||||||
|
CIncludeFileEntry includeFileEntry2 = new CIncludeFileEntry("file2", 0);
|
||||||
|
CMacroFileEntry macroFileEntry1 = new CMacroFileEntry("file1", 0);
|
||||||
|
CMacroFileEntry macroFileEntry2 = new CMacroFileEntry("file2", 0);
|
||||||
|
CLibraryPathEntry libraryPathEntry1 = new CLibraryPathEntry("lib1", 0);
|
||||||
|
CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib2", 0);
|
||||||
|
CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file1", 0);
|
||||||
|
CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file2", 0);
|
||||||
|
|
||||||
|
// place entries in unsorted list
|
||||||
|
List<ICLanguageSettingEntry> unsortedEntries = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
unsortedEntries.add(macroEntry1);
|
||||||
|
unsortedEntries.add(macroFileEntry1);
|
||||||
|
unsortedEntries.add(macroEntry2);
|
||||||
|
unsortedEntries.add(includePathEntry1);
|
||||||
|
unsortedEntries.add(includeFileEntry1);
|
||||||
|
unsortedEntries.add(macroFileEntry2);
|
||||||
|
unsortedEntries.add(libraryFileEntry1);
|
||||||
|
unsortedEntries.add(includeFileEntry2);
|
||||||
|
unsortedEntries.add(libraryFileEntry2);
|
||||||
|
unsortedEntries.add(libraryPathEntry1);
|
||||||
|
unsortedEntries.add(includePathEntry2);
|
||||||
|
unsortedEntries.add(libraryPathEntry2);
|
||||||
|
|
||||||
|
// create a provider and set the entries
|
||||||
|
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||||
|
provider.setSettingEntries(null, null, null, unsortedEntries);
|
||||||
|
|
||||||
|
// retrieve and check that language settings got sorted properly
|
||||||
|
int i=0;
|
||||||
|
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||||
|
assertEquals(includePathEntry1, actual.get(i++));
|
||||||
|
assertEquals(includePathEntry2, actual.get(i++));
|
||||||
|
assertEquals(includeFileEntry1, actual.get(i++));
|
||||||
|
assertEquals(includeFileEntry2, actual.get(i++));
|
||||||
|
assertEquals(macroEntry1, actual.get(i++));
|
||||||
|
assertEquals(macroEntry2, actual.get(i++));
|
||||||
|
assertEquals(macroFileEntry1, actual.get(i++));
|
||||||
|
assertEquals(macroFileEntry2, actual.get(i++));
|
||||||
|
assertEquals(libraryPathEntry1, actual.get(i++));
|
||||||
|
assertEquals(libraryPathEntry2, actual.get(i++));
|
||||||
|
assertEquals(libraryFileEntry1, actual.get(i++));
|
||||||
|
assertEquals(libraryFileEntry2, actual.get(i++));
|
||||||
|
|
||||||
|
assertEquals(unsortedEntries.size(), actual.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public void testSort_Entries() throws Exception {
|
||||||
|
// create sample entries
|
||||||
|
CIncludePathEntry includePathEntry1 = new CIncludePathEntry("path_B", 0);
|
||||||
|
CIncludePathEntry includePathEntry2 = new CIncludePathEntry("path_A", 0);
|
||||||
|
CMacroEntry macroEntry1 = new CMacroEntry("MACRO_A", null, 0);
|
||||||
|
CMacroEntry macroEntry2 = new CMacroEntry("MACRO_B", null, 0);
|
||||||
|
CIncludeFileEntry includeFileEntry1 = new CIncludeFileEntry("file_B", 0);
|
||||||
|
CIncludeFileEntry includeFileEntry2 = new CIncludeFileEntry("file_A", 0);
|
||||||
|
CMacroFileEntry macroFileEntry1 = new CMacroFileEntry("file_B", 0);
|
||||||
|
CMacroFileEntry macroFileEntry2 = new CMacroFileEntry("file_A", 0);
|
||||||
|
CLibraryPathEntry libraryPathEntry1 = new CLibraryPathEntry("lib_B", 0);
|
||||||
|
CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib_A", 0);
|
||||||
|
CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file_B", 0);
|
||||||
|
CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file_A", 0);
|
||||||
|
|
||||||
|
// place entries in unsorted list
|
||||||
|
List<ICLanguageSettingEntry> unsortedEntries = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
// macros will be sorted by name
|
||||||
|
unsortedEntries.add(macroEntry2);
|
||||||
|
unsortedEntries.add(macroEntry1);
|
||||||
|
// paths are not sorted only grouped by kind
|
||||||
|
unsortedEntries.add(macroFileEntry1);
|
||||||
|
unsortedEntries.add(macroFileEntry2);
|
||||||
|
unsortedEntries.add(includePathEntry1);
|
||||||
|
unsortedEntries.add(includePathEntry2);
|
||||||
|
unsortedEntries.add(includeFileEntry1);
|
||||||
|
unsortedEntries.add(includeFileEntry2);
|
||||||
|
unsortedEntries.add(libraryFileEntry1);
|
||||||
|
unsortedEntries.add(libraryFileEntry2);
|
||||||
|
unsortedEntries.add(libraryPathEntry1);
|
||||||
|
unsortedEntries.add(libraryPathEntry2);
|
||||||
|
|
||||||
|
// create a provider and set the entries
|
||||||
|
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||||
|
provider.setSettingEntries(null, null, null, unsortedEntries);
|
||||||
|
|
||||||
|
// retrieve and check that language settings got sorted properly
|
||||||
|
int i=0;
|
||||||
|
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||||
|
assertEquals(includePathEntry1, actual.get(i++));
|
||||||
|
assertEquals(includePathEntry2, actual.get(i++));
|
||||||
|
assertEquals(includeFileEntry1, actual.get(i++));
|
||||||
|
assertEquals(includeFileEntry2, actual.get(i++));
|
||||||
|
assertEquals(macroEntry1, actual.get(i++));
|
||||||
|
assertEquals(macroEntry2, actual.get(i++));
|
||||||
|
assertEquals(macroFileEntry1, actual.get(i++));
|
||||||
|
assertEquals(macroFileEntry2, actual.get(i++));
|
||||||
|
assertEquals(libraryPathEntry1, actual.get(i++));
|
||||||
|
assertEquals(libraryPathEntry2, actual.get(i++));
|
||||||
|
assertEquals(libraryFileEntry1, actual.get(i++));
|
||||||
|
assertEquals(libraryFileEntry2, actual.get(i++));
|
||||||
|
|
||||||
|
assertEquals(unsortedEntries.size(), actual.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public void testSort_Undef() throws Exception {
|
||||||
|
// create sample entries
|
||||||
|
CMacroEntry macroEntry1 = new CMacroEntry("MACRO_1", null, 0);
|
||||||
|
CMacroEntry macroEntry2A = new CMacroEntry("MACRO_2", null, ICSettingEntry.UNDEFINED);
|
||||||
|
CMacroEntry macroEntry2B = new CMacroEntry("MACRO_2", null, 0);
|
||||||
|
CMacroEntry macroEntry2C = new CMacroEntry("MACRO_2", null, ICSettingEntry.BUILTIN);
|
||||||
|
CMacroEntry macroEntry3 = new CMacroEntry("MACRO_3", null, 0);
|
||||||
|
|
||||||
|
// place entries in unsorted list
|
||||||
|
List<ICLanguageSettingEntry> unsortedEntries = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
// macros will be sorted by name and keep order for the same name
|
||||||
|
unsortedEntries.add(macroEntry2A);
|
||||||
|
unsortedEntries.add(macroEntry3);
|
||||||
|
unsortedEntries.add(macroEntry2B);
|
||||||
|
unsortedEntries.add(macroEntry1);
|
||||||
|
unsortedEntries.add(macroEntry2C);
|
||||||
|
|
||||||
|
// create a provider and set the entries
|
||||||
|
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||||
|
provider.setSettingEntries(null, null, null, unsortedEntries);
|
||||||
|
|
||||||
|
// retrieve and check that language settings got sorted properly
|
||||||
|
int i=0;
|
||||||
|
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||||
|
assertEquals(macroEntry1, actual.get(i++));
|
||||||
|
assertEquals(macroEntry2A, actual.get(i++));
|
||||||
|
assertEquals(macroEntry2B, actual.get(i++));
|
||||||
|
assertEquals(macroEntry2C, actual.get(i++));
|
||||||
|
assertEquals(macroEntry3, actual.get(i++));
|
||||||
|
|
||||||
|
assertEquals(unsortedEntries.size(), actual.size());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,14 @@ public class LanguageSettingsManager {
|
||||||
return LanguageSettingsExtensionManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId);
|
return LanguageSettingsExtensionManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*/
|
||||||
|
public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IProject project) {
|
||||||
|
LanguageSettingsExtensionManager.buildResourceTree(provider, cfgDescription, languageId, project);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of setting entries of a certain kind (such as include paths)
|
* Returns the list of setting entries of a certain kind (such as include paths)
|
||||||
* for the given configuration description, resource and language. This is a
|
* for the given configuration description, resource and language. This is a
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
||||||
|
|
||||||
private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$
|
private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static WeakHashSet<List<ICLanguageSettingEntry>> listLSEPool = new WeakHashSet<List<ICLanguageSettingEntry>>() {
|
private static WeakHashSet<List<ICLanguageSettingEntry>> lseListPool = new WeakHashSet<List<ICLanguageSettingEntry>>() {
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<ICLanguageSettingEntry> add(List<ICLanguageSettingEntry> list) {
|
public synchronized List<ICLanguageSettingEntry> add(List<ICLanguageSettingEntry> list) {
|
||||||
return super.add(list);
|
return super.add(list);
|
||||||
|
@ -129,7 +129,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
||||||
langMap = new HashMap<String, List<ICLanguageSettingEntry>>();
|
langMap = new HashMap<String, List<ICLanguageSettingEntry>>();
|
||||||
fStorage.put(languageId, langMap);
|
fStorage.put(languageId, langMap);
|
||||||
}
|
}
|
||||||
List<ICLanguageSettingEntry> sortedEntries = listLSEPool.add(Collections.unmodifiableList(sortEntries(entries)));
|
List<ICLanguageSettingEntry> sortedEntries = lseListPool.add(Collections.unmodifiableList(sortEntries(entries)));
|
||||||
langMap.put(rcProjectPath, sortedEntries);
|
langMap.put(rcProjectPath, sortedEntries);
|
||||||
} else {
|
} else {
|
||||||
// do not keep nulls in the tables
|
// do not keep nulls in the tables
|
||||||
|
|
|
@ -13,8 +13,10 @@ package org.eclipse.cdt.internal.core.language.settings.providers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
@ -23,12 +25,16 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider;
|
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider;
|
||||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable;
|
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
|
import org.eclipse.cdt.core.model.LanguageManager;
|
||||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||||
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
|
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
|
||||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||||
import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer;
|
import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer;
|
||||||
|
import org.eclipse.core.resources.IContainer;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
|
@ -41,6 +47,7 @@ import org.eclipse.core.runtime.IExtensionRegistry;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.core.runtime.content.IContentType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class {@code LanguageSettingsExtensionManager} manages {@link ILanguageSettingsProvider} extensions
|
* Class {@code LanguageSettingsExtensionManager} manages {@link ILanguageSettingsProvider} extensions
|
||||||
|
@ -385,6 +392,99 @@ public class LanguageSettingsExtensionManager {
|
||||||
return new ArrayList<ICLanguageSettingEntry>(0);
|
return new ArrayList<ICLanguageSettingEntry>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*/
|
||||||
|
public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IContainer folder) {
|
||||||
|
IResource[] members = null;
|
||||||
|
try {
|
||||||
|
members = folder.members();
|
||||||
|
} catch (Exception e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
if (members==null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (IResource rc : members) {
|
||||||
|
if (rc instanceof IContainer) {
|
||||||
|
buildResourceTree(provider, cfgDescription, languageId, (IContainer) rc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int rcNumber = members.length;
|
||||||
|
|
||||||
|
Map<List<ICLanguageSettingEntry>, Integer> listMap = new HashMap<List<ICLanguageSettingEntry>, Integer>();
|
||||||
|
|
||||||
|
// on the first pass find majority entries
|
||||||
|
List<ICLanguageSettingEntry> majorityEntries = null;
|
||||||
|
List<ICLanguageSettingEntry> candidate = null;
|
||||||
|
int candidateCount = 0;
|
||||||
|
for (IResource rc : members) {
|
||||||
|
if (rc instanceof IFile) {
|
||||||
|
IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(rc.getName());
|
||||||
|
if (contentType==null) {
|
||||||
|
rcNumber--;
|
||||||
|
if (candidateCount > rcNumber/2) {
|
||||||
|
majorityEntries = candidate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ILanguage lang = LanguageManager.getInstance().getLanguage(contentType);
|
||||||
|
List<String> languageScope = provider.getLanguageScope();
|
||||||
|
if (lang==null || (languageScope!=null && !languageScope.contains(lang.getId()))) {
|
||||||
|
rcNumber--;
|
||||||
|
if (candidateCount > rcNumber/2) {
|
||||||
|
majorityEntries = candidate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, rc, languageId);
|
||||||
|
if (entries==null && rc instanceof IContainer) {
|
||||||
|
rcNumber--;
|
||||||
|
if (candidateCount > rcNumber/2) {
|
||||||
|
majorityEntries = candidate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer count = listMap.get(entries);
|
||||||
|
if (count==null) {
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
if (count > rcNumber/2) {
|
||||||
|
majorityEntries = entries;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (count>candidateCount) {
|
||||||
|
candidateCount = count;
|
||||||
|
candidate = entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
listMap.put(entries, count);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (majorityEntries!=null) {
|
||||||
|
provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (IResource rc : members) {
|
||||||
|
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, rc, languageId);
|
||||||
|
if (entries!=null && entries==majorityEntries) {
|
||||||
|
if (!(rc instanceof IFile)) { // preserve information which files were collected
|
||||||
|
provider.setSettingEntries(cfgDescription, rc, languageId, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean checkBit(int flags, int bit) {
|
private static boolean checkBit(int flags, int bit) {
|
||||||
return (flags & bit) == bit;
|
return (flags & bit) == bit;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue