From e0149be3a3456395c43f6065f9b388571e10d582 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 27 Oct 2012 08:46:06 -0400 Subject: [PATCH] Bug 392966: Indexing only source files in the build doesn't work properly with new scanner discovery --- .../LanguageSettingsManagerTests.java | 33 +++++++++++ .../org/eclipse/cdt/core/model/CoreModel.java | 56 ++++++++++++------- .../model/ICConfigurationDescription.java | 7 ++- .../LanguageSettingsProvidersSerializer.java | 2 +- 4 files changed, 76 insertions(+), 22 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java index 66ab7ac5fe4..17f861e4010 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManagerTests.java @@ -17,6 +17,7 @@ import java.util.List; import junit.framework.TestSuite; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; +import org.eclipse.cdt.core.settings.model.CIncludeFileEntry; import org.eclipse.cdt.core.settings.model.CIncludePathEntry; import org.eclipse.cdt.core.settings.model.CMacroEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -649,6 +650,38 @@ public class LanguageSettingsManagerTests extends BaseTestCase { assertEquals(3, includes.size()); } + /** + * Test ability to get entries by kind. + */ + public void testEntriesByKind_CompositeKind() throws Exception { + MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID); + + // contribute the entries + List entries = new ArrayList(); + entries.add(new CIncludePathEntry("path0", 0)); + entries.add(new CMacroEntry("MACRO0", "value0",0)); + entries.add(new CIncludePathEntry("path1", 0)); + entries.add(new CMacroEntry("MACRO1", "value1",0)); + entries.add(new CIncludePathEntry("path2", 0)); + + entries.add(new CIncludeFileEntry("include-path-file", 0)); + + ILanguageSettingsProvider provider0 = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, entries); + List providers = new ArrayList(); + providers.add(provider0); + cfgDescription.setLanguageSettingProviders(providers); + + // retrieve entries by kind + List result = LanguageSettingsProvidersSerializer + .getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH | ICSettingEntry.MACRO); + assertEquals(new CIncludePathEntry("path0", 0), result.get(0)); + assertEquals(new CMacroEntry("MACRO0", "value0",0), result.get(1)); + assertEquals(new CIncludePathEntry("path1", 0), result.get(2)); + assertEquals(new CMacroEntry("MACRO1", "value1",0), result.get(3)); + assertEquals(new CIncludePathEntry("path2", 0), result.get(4)); + assertEquals(5, result.size()); + } + /** * Test ability to serialize providers for a configuration. */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java index 313cc76e9e2..b24886879f6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java @@ -13,10 +13,13 @@ package org.eclipse.cdt.core.model; import java.net.URI; +import java.util.List; import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.resources.IPathEntryStore; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSetting; @@ -26,6 +29,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.WriteAccessException; +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.BatchOperation; import org.eclipse.cdt.internal.core.model.CModel; @@ -1253,27 +1257,41 @@ public class CoreModel { if(!mngr.isNewStyleCfg(indexCfg)){ return oldIsScannerInformationEmpty(resource); } - ICLanguageSetting lSetting = indexCfg.getLanguageSettingForFile(resource.getProjectRelativePath(), false); - if(lSetting != null && lSetting instanceof CLanguageSettingCache){ - if(!((CLanguageSettingCache)lSetting).containsDiscoveredScannerInfo()) - lSetting = null; - } - if(lSetting != null){ - ICLanguageSettingEntry[] entries = lSetting.getSettingEntries(ICSettingEntry.INCLUDE_PATH); - if(entries.length != 0) - return false; + + if (indexCfg instanceof ILanguageSettingsProvidersKeeper) { + List languageIds = LanguageSettingsManager.getLanguages(resource, indexCfg); + for (String langId : languageIds) { + List entries = LanguageSettingsProvidersSerializer.getSettingEntriesByKind(indexCfg, resource, langId, + ICSettingEntry.INCLUDE_PATH | ICSettingEntry.MACRO | ICSettingEntry.INCLUDE_FILE | ICSettingEntry.MACRO_FILE); + if (!(entries == null || entries.isEmpty())) { + return false; + } + } + return true; - entries = lSetting.getSettingEntries(ICSettingEntry.MACRO); - if(entries.length != 0) - return false; + } else { + ICLanguageSetting lSetting = indexCfg.getLanguageSettingForFile(resource.getProjectRelativePath(), false); + if(lSetting != null && lSetting instanceof CLanguageSettingCache){ + if(!((CLanguageSettingCache)lSetting).containsDiscoveredScannerInfo()) + lSetting = null; + } + if(lSetting != null){ + ICLanguageSettingEntry[] entries = lSetting.getSettingEntries(ICSettingEntry.INCLUDE_PATH); + if(entries.length != 0) + return false; - entries = lSetting.getSettingEntries(ICSettingEntry.INCLUDE_FILE); - if(entries.length != 0) - return false; - - entries = lSetting.getSettingEntries(ICSettingEntry.MACRO_FILE); - if(entries.length != 0) - return false; + entries = lSetting.getSettingEntries(ICSettingEntry.MACRO); + if(entries.length != 0) + return false; + + entries = lSetting.getSettingEntries(ICSettingEntry.INCLUDE_FILE); + if(entries.length != 0) + return false; + + entries = lSetting.getSettingEntries(ICSettingEntry.MACRO_FILE); + if(entries.length != 0) + return false; + } } } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java index cc53679e3d1..e39a03be2d4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICConfigurationDescription.java @@ -369,12 +369,15 @@ public interface ICConfigurationDescription extends ICSettingContainer, ICSettin boolean isPreferenceConfiguration(); /** - * Convenience method to return a language setting for the file - * with the specified project-relative path + * @deprecated Deprecated as of CDT 8.1. This method returns settings supplied by MBS only. + * For most cases, more generic Language Settings Providers mechanism should be used instead. * + * Convenience method to return a language setting for the file with the specified project-relative path. + * * @param path - file project relative path * @return ICLanguageSetting or null if not found */ + @Deprecated ICLanguageSetting getLanguageSettingForFile(IPath path, boolean ignoreExludeStatus); /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 1e822641ed6..d5fb7509e71 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -1513,7 +1513,7 @@ public class LanguageSettingsProvidersSerializer { for (ICLanguageSettingEntry entry : providerEntries) { if (entry != null) { String entryName = entry.getName(); - boolean isRightKind = checkBit(entry.getKind(), kind); + boolean isRightKind = checkBit(kind, entry.getKind()); // Only first entry is considered // Entry flagged as "UNDEFINED" prevents adding entry with the same name down the line if (isRightKind && !alreadyAdded.contains(entryName)) {