From 2764a28f649b37ede73d12a521d247a619342005 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 30 Apr 2013 10:32:59 -0400 Subject: [PATCH] bug 403405: Fix for failing test case BackwardCompatibilityTests.testPathEntriesForNewStyle() --- .../model/BackwardCompatibilityTests.java | 18 ++--- .../model/util/PathEntryTranslator.java | 65 +++++++++++++++++-- 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/BackwardCompatibilityTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/BackwardCompatibilityTests.java index 4b364173ba8..74c440d53b1 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/BackwardCompatibilityTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/BackwardCompatibilityTests.java @@ -76,14 +76,16 @@ public class BackwardCompatibilityTests extends BaseTestCase { checkEntriesMatch(expectedRawEntries, entries); IPathEntry[] expectedResolvedEntries = new IPathEntry[]{ - CoreModel.newSourceEntry(project.getFullPath()), - CoreModel.newOutputEntry(project.getFullPath()), - CoreModel.newMacroEntry(project.getFullPath(), "a", "b"), - CoreModel.newMacroEntry(project.getFullPath(), "c", ""), - CoreModel.newIncludeEntry(project.getFullPath(), null, project.getLocation().append("a/b/c")), - CoreModel.newIncludeEntry(project.getFullPath(), null, new Path("/d/e/f")), - CoreModel.newIncludeEntry(project.getFullPath(), project.getFullPath().makeRelative(), new Path("g/h/i")), - CoreModel.newIncludeEntry(project.getFullPath(), new Path("j"), new Path("k/l")), + CoreModel.newSourceEntry(project.getFullPath()), + CoreModel.newOutputEntry(project.getFullPath()), + CoreModel.newIncludeEntry(project.getFullPath(), null, project.getLocation().append("a/b/c")), + CoreModel.newIncludeEntry(project.getFullPath(), null, new Path("/d/e/f")), + // Relative path with VALUE_WORKSPACE_PATH generates 2 entries, see MBSLanguageSettingsProvider + CoreModel.newIncludeEntry(project.getFullPath(), null, project.getLocation().append("g/h/i")), + CoreModel.newIncludeEntry(project.getFullPath(), project.getFullPath().makeRelative(), new Path("g/h/i")), + CoreModel.newIncludeEntry(project.getFullPath(), new Path("j"), new Path("k/l")), + CoreModel.newMacroEntry(project.getFullPath(), "a", "b"), + CoreModel.newMacroEntry(project.getFullPath(), "c", ""), }; checkEntriesMatch(expectedResolvedEntries, resolvedentries); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java index aa2ec77c8a2..db86d0ab695 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java @@ -26,6 +26,8 @@ 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.ILanguageSettingsProvider; +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; @@ -64,7 +66,6 @@ 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; @@ -2034,6 +2035,54 @@ public class PathEntryTranslator { return collector; } + /** + * 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 + * combined list for all providers. + * This list does not include settings of parent folder. + * + * @param cfgDescription - configuration description. + * @param rc - resource such as file or folder. + * @param languageId - language id. + * @param kind - kind of language settings entries, such as {@link ICSettingEntry#INCLUDE_PATH} etc. + * + * @return the list of setting entries found. + */ + private static List getSettingEntriesByKind(ICConfigurationDescription cfgDescription, + IResource rc, String languageId, int kind) { + + if (!(cfgDescription instanceof ILanguageSettingsProvidersKeeper)) { + return null; + } + + List entries = new ArrayList(); + List alreadyAdded = new ArrayList(); + + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + for (ILanguageSettingsProvider provider: providers) { + List providerEntries = provider.getSettingEntries(cfgDescription, rc, languageId); + if (providerEntries != null) { + for (ICLanguageSettingEntry entry : providerEntries) { + if (entry != null) { + String entryName = entry.getName(); + boolean isRightKind = (entry.getKind() & kind) == kind; + // Only first entry is considered + // Entry flagged as "UNDEFINED" prevents adding entry with the same name down the line + if (isRightKind && !alreadyAdded.contains(entryName)) { + int flags = entry.getFlags(); + if ((flags & ICSettingEntry.UNDEFINED) != ICSettingEntry.UNDEFINED) { + entries.add(entry); + } + alreadyAdded.add(entryName); + } + } + } + } + } + + return entries; + } + private static boolean collectResourceDataEntries(ICConfigurationDescription cfgDescription, int kind, CResourceData rcData, Set list) { CLanguageData[] lDatas = null; if (rcData instanceof CFolderData) { @@ -2054,12 +2103,16 @@ public class PathEntryTranslator { 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)); - } + if (rc == null) { + // If resource does not exist make a handle to be able to supply the path. + // This does not create actual resource. + // Gotta be a folder so language settings provider won't filter out languages. + rc = project.getFolder(rcData.getPath()); } - return list.size()>0; + for (CLanguageData lData : lDatas) { + list.addAll(getSettingEntriesByKind(cfgDescription, rc, lData.getLanguageId(), kind)); + } + return list.size() > 0; } // Legacy logic (before Language Settings Providers)