diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java index 5c35b4dac98..fc800c84be7 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/AbstractLanguageSettingsOutputScanner.java @@ -26,9 +26,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.cdt.core.ErrorParserManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; 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.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; @@ -243,13 +242,12 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett public boolean processLine(String line, ErrorParserManager epm) { errorParserManager = epm; parsedResourceName = parseForResourceName(line); + currentResource = findResource(parsedResourceName); - currentLanguageId = determineLanguage(parsedResourceName); + currentLanguageId = determineLanguage(); if (!isLanguageInScope(currentLanguageId)) return false; - currentResource = findResource(parsedResourceName); - /** * URI of directory where the build is happening. This URI could point to a remote filesystem * for remote builds. Most often it is the same filesystem as for currentResource but @@ -316,21 +314,22 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett MakeCorePlugin.log(status); } - protected String determineLanguage(String parsedResourceName) { - if (parsedResourceName==null) + protected String determineLanguage() { + IResource rc = currentResource; + if (rc == null && currentProject != null && parsedResourceName != null) { + String fileName = new Path(parsedResourceName).lastSegment().toString(); + // use handle; resource does not need to exist + rc = currentProject.getFile("__" + fileName); + } + + if (rc == null) return null; - String fileName = new Path(parsedResourceName).lastSegment().toString(); - IContentTypeManager manager = Platform.getContentTypeManager(); - IContentType contentType = manager.findContentTypeFor(fileName); - if (contentType==null) + List languageIds = LanguageSettingsManager.getLanguages(rc, currentCfgDescription); + if (languageIds.isEmpty()) return null; - - ILanguage lang = LanguageManager.getInstance().getLanguage(contentType); - if (lang==null) - return null; - - return lang.getId(); + + return languageIds.get(0); } protected boolean isLanguageInScope(String languageId) { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index 296753806cd..337801b1342 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -60,8 +60,6 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICFolderDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICMultiConfigDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; @@ -4813,13 +4811,9 @@ public class ManagedBuildManager extends AbstractCExtension { static public void runBuiltinSpecsDetectors(ICConfigurationDescription cfgDescription, IPath workingDirectory, String[] env, IProgressMonitor monitor) { IProject project = cfgDescription.getProjectDescription().getProject(); - ICFolderDescription rootFolderDescription = cfgDescription.getRootFolderDescription(); - List languageIds = new ArrayList(); - for (ICLanguageSetting languageSetting : rootFolderDescription.getLanguageSettings()) { - String id = languageSetting.getLanguageId(); - if (id!=null) { - languageIds.add(id); - } + List languageIds = LanguageSettingsManager.getLanguages(project, cfgDescription); + if (languageIds.isEmpty()) { + return; } for (ILanguageSettingsProvider provider : cfgDescription.getLanguageSettingProviders()) { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java index 72f6413f8b2..586a7200c25 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -148,7 +148,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } @Override - protected String determineLanguage(String parsedResourceName) { + protected String determineLanguage() { // language id is supposed to be set by run(), just return it return currentLanguageId; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java index 38cb0717062..6463f01a146 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager.java @@ -1,30 +1,37 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 Andrew Gvozdev 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: - * Andrew Gvozdev (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.language.settings.providers; +import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.core.CCorePlugin; +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.ICFileDescription; +import org.eclipse.cdt.core.settings.model.ICFolderDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; -import org.eclipse.cdt.internal.core.LocalProjectScope; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.osgi.service.prefs.Preferences; +import org.eclipse.core.runtime.IPath; /** * A collection of utility methods to manage language settings providers. @@ -167,4 +174,82 @@ public class LanguageSettingsManager { return provider; } + /** + * Find language IDs for the resource represented by resource description. + * Under the hood build component is inquired and the language IDs would + * commonly come from the input type(s). + * + * @param rcDescription - resource description + * @return list of language IDs for the resource. + * Never returns {@code null} but empty list if no languages can be found. + * + */ + public static List getLanguages(ICResourceDescription rcDescription) { + ICLanguageSetting[] languageSettings = null; + if (rcDescription instanceof ICFileDescription) { + ICLanguageSetting languageSetting = ((ICFileDescription)rcDescription).getLanguageSetting(); + if (languageSetting != null) { + languageSettings = new ICLanguageSetting[] {languageSetting}; + } + } else if (rcDescription instanceof ICFolderDescription) { + languageSettings = ((ICFolderDescription)rcDescription).getLanguageSettings(); + } + + List languageIds = new ArrayList(); + if (languageSettings != null) { + for (ICLanguageSetting languageSetting : languageSettings) { + if (languageSetting!=null) { + String languageId = languageSetting.getLanguageId(); + if (languageId != null && !languageId.isEmpty()) { + languageIds.add(languageId); + } + } + } + } + + return languageIds; + } + + /** + * Find language IDs for the resource in given build configuration. + * Under the hood build component is inquired and the language IDs would + * commonly come from the input type(s). + * + * @param resource - the resource to find languages for. + * @param cfgDescription + * @return list of language IDs for the resource. + * Never returns {@code null} but empty list if no languages can be found. + */ + public static List getLanguages(IResource resource, ICConfigurationDescription cfgDescription) { + List languageIds = new ArrayList(); + IPath prjRelPath = resource.getProjectRelativePath(); + if (resource instanceof IFile) { + String langId = null; + if (cfgDescription != null) { + ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(prjRelPath, true); + if (ls != null) { + langId = ls.getLanguageId(); + } + } else { + try { + ILanguage lang = LanguageManager.getInstance().getLanguageForFile((IFile) resource, null); + langId = lang.getId(); + } catch (CoreException e) { + CCorePlugin.log(e); + } + } + if (langId != null) { + languageIds.add(langId); + } + } else { + ICResourceDescription rcDes = cfgDescription.getResourceDescription(prjRelPath, false); + if (rcDes == null) { + rcDes = cfgDescription.getRootFolderDescription(); + } + languageIds = getLanguages(rcDes); + } + + return languageIds; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java index b92da74a593..efb8bdd8958 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsManager_TBD.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2009, 2011 Andrew Gvozdev 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: - * Andrew Gvozdev (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.language.settings.providers; @@ -15,11 +15,7 @@ import java.util.List; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICFileDescription; -import org.eclipse.cdt.core.settings.model.ICFolderDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; @@ -28,29 +24,13 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; /** - * TODO - * This layer of language settings in TODO - * - * Duplicate entries are filtered where only first entry is preserved. - * + * This temporary class keeps the utility methods being looking for better home */ public class LanguageSettingsManager_TBD { public static final String PROVIDER_UNKNOWN = "org.eclipse.cdt.projectmodel.4.0.0"; public static final String PROVIDER_UI_USER = "org.eclipse.cdt.ui.user.LanguageSettingsProvider"; public static final char PROVIDER_DELIMITER = LanguageSettingsProvidersSerializer.PROVIDER_DELIMITER; - private static ICLanguageSetting[] getLanguageIds(ICResourceDescription rcDescription) { - if (rcDescription instanceof ICFileDescription) { - ICFileDescription fileDescription = (ICFileDescription)rcDescription; - return new ICLanguageSetting[] {fileDescription.getLanguageSetting()}; - } else if (rcDescription instanceof ICFolderDescription) { - ICFolderDescription folderDescription = (ICFolderDescription)rcDescription; - return folderDescription.getLanguageSettings(); - } - - return null; - } - public static boolean isCustomizedResource(ICConfigurationDescription cfgDescription, IResource rc) { if (rc instanceof IProject) return false; @@ -59,16 +39,13 @@ public class LanguageSettingsManager_TBD { // FIXME // if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { if (provider instanceof ILanguageSettingsEditableProvider || provider instanceof LanguageSettingsSerializable) { - ICResourceDescription rcDescription = cfgDescription.getResourceDescription(rc.getProjectRelativePath(), false); - for (ICLanguageSetting languageSetting : getLanguageIds(rcDescription)) { - String languageId = languageSetting.getLanguageId(); - if (languageId!=null) { - List list = provider.getSettingEntries(cfgDescription, rc, languageId); - if (list!=null) { - List listDefault = provider.getSettingEntries(null, null, languageId); - if (!list.equals(listDefault)) - return true; - } + for (String languageId : LanguageSettingsManager.getLanguages(rc, cfgDescription)) { + List list = provider.getSettingEntries(cfgDescription, rc, languageId); + if (list!=null) { + List listDefault = provider.getSettingEntries(null, null, languageId); + // != is OK here due as the equal lists will have the same reference in WeakHashSet + if (list != listDefault) + return true; } } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java index 0b6f4b8a1c5..ed3960a11bf 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2010, 2010 Andrew Gvozdev (Quoin Inc.) and others. + * Copyright (c) 2010, 2011 Andrew Gvozdev 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: - * Andrew Gvozdev (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.language.settings.providers; @@ -20,24 +20,18 @@ import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.cdtvariables.CdtVariableException; import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager; -import org.eclipse.cdt.core.model.ILanguage; -import org.eclipse.cdt.core.model.LanguageManager; +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.parser.ExtendedScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.settings.model.ACPathEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICFolderDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.core.settings.model.ICLanguageSettingPathEntry; import org.eclipse.cdt.core.settings.model.ICMacroEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -72,8 +66,10 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider if (cfgDescription==null) return DUMMY_SCANNER_INFO; - List languageIds = getLanguageIds(cfgDescription, rc); - if (languageIds==null || languageIds.size()==0) { + List languageIds = LanguageSettingsManager.getLanguages(rc, cfgDescription); + if (languageIds.isEmpty()) { + String msg = NLS.bind(SettingsModelMessages.getString("LanguageSettingsScannerInfoProvider.UnableToDetermineLanguage"), rc.toString()); //$NON-NLS-1$ + CCorePlugin.log(new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg))); return DUMMY_SCANNER_INFO; } @@ -121,66 +117,6 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider return new ExtendedScannerInfo(definedMacros, includePaths, macroFiles, includeFiles, includePathsLocal); } - private List getLanguageIds(ICConfigurationDescription cfgDescription, IResource resource) { - List languageIds = null; - if (resource instanceof IFile) { - String langId = getLanguageIdForFile(cfgDescription, resource); - if (langId!=null) { - languageIds = new ArrayList(1); - languageIds.add(langId); - } - } else if (resource instanceof IContainer) { // IResource can be either IFile or IContainer - languageIds = getLanguageIdsForFolder(cfgDescription, (IContainer) resource); - } - if (languageIds==null || languageIds.size()==0) { - String msg = NLS.bind(SettingsModelMessages.getString("LanguageSettingsScannerInfoProvider.UnableToDetermineLanguage"), resource.toString()); //$NON-NLS-1$ - CCorePlugin.log(new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg))); - } - return languageIds; - } - - private String getLanguageIdForFile(ICConfigurationDescription cfgDescription, IResource resource) { - // For files using LanguageManager - try { - ILanguage language = LanguageManager.getInstance().getLanguageForFile((IFile) resource, cfgDescription); - if (language!=null) { - return language.getId(); - } - } catch (CoreException e) { - CCorePlugin.log(e); - } - return null; - } - - private List getLanguageIdsForFolder(ICConfigurationDescription cfgDescription, IContainer resource) { - // Using MBS for folders. That will take language ID from input type of applicable tools in the toolchain. - List languageIds = new ArrayList(); - - ICFolderDescription rcDes = null; - ICLanguageSetting[] langSettings = null; - if (resource.getType() == IResource.FOLDER) { // but not IResource.PROJECT - IPath rcPath = resource.getProjectRelativePath(); - rcDes = (ICFolderDescription) cfgDescription.getResourceDescription(rcPath, false); - langSettings = rcDes.getLanguageSettings(); - } - if (langSettings==null || langSettings.length==0) { - // not found or IResource.PROJECT - ICFolderDescription rootDes = cfgDescription.getRootFolderDescription(); - langSettings = rootDes.getLanguageSettings(); - } - - if (langSettings!=null) { - for (ICLanguageSetting ls : langSettings) { - String langId = ls.getLanguageId(); - if (langId!=null && !languageIds.contains(langId)) { - languageIds.add(langId); - } - } - } - - return languageIds; - } - private IPath expandVariables(IPath path, ICConfigurationDescription cfgDescription) { ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager(); String pathStr = path.toString(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index 04331a7ae4c..7be2531e347 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.ui.language.settings.providers; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -51,16 +50,10 @@ import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_ import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.ILanguage; -import org.eclipse.cdt.core.model.ILanguageDescriptor; import org.eclipse.cdt.core.model.LanguageManager; -import org.eclipse.cdt.core.model.util.CDTListComparator; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICFileDescription; -import org.eclipse.cdt.core.settings.model.ICFolderDescription; -import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICResourceDescription; -import org.eclipse.cdt.core.settings.model.ICSettingBase; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.ui.CDTSharedImages; @@ -68,7 +61,6 @@ import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; import org.eclipse.cdt.ui.newui.CDTPrefUtil; - import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; import org.eclipse.cdt.internal.ui.newui.Messages; import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; @@ -89,7 +81,6 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { private Tree treeEntries; private TreeViewer treeEntriesViewer; private String currentLanguageId = null; - private ICLanguageSetting[] allLanguages; private Button builtInCheckBox; private Button enableProvidersCheckBox; @@ -320,12 +311,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { public void widgetSelected(SelectionEvent e) { TreeItem[] items = treeLanguages.getSelection(); if (items.length > 0) { - ICLanguageSetting langSetting = (ICLanguageSetting) items[0].getData(); - if (langSetting != null) { - currentLanguageId = langSetting.getLanguageId(); - updateTreeEntries(); - updateButtons(); - } + currentLanguageId = (String) items[0].getData(); + updateTreeEntries(); + updateButtons(); } } }); @@ -887,58 +875,38 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { updateButtons(); } - private ICLanguageSetting[] getLangSettings(ICResourceDescription rcDes) { - switch (rcDes.getType()) { - case ICSettingBase.SETTING_PROJECT: - case ICSettingBase.SETTING_CONFIGURATION: - case ICSettingBase.SETTING_FOLDER: - ICFolderDescription foDes = (ICFolderDescription) rcDes; - return foDes.getLanguageSettings(); - case ICSettingBase.SETTING_FILE: - ICFileDescription fiDes = (ICFileDescription) rcDes; - ICLanguageSetting langSetting = fiDes.getLanguageSetting(); - return (langSetting != null) ? new ICLanguageSetting[] { langSetting } : null; - } - return null; - } - private void updateTreeLanguages(ICResourceDescription rcDes) { treeLanguages.removeAll(); TreeItem selectedLanguageItem = null; - allLanguages = getLangSettings(rcDes); - if (allLanguages != null) { - Arrays.sort(allLanguages, CDTListComparator.getInstance()); - for (ICLanguageSetting langSetting : allLanguages) { - String langId = langSetting.getLanguageId(); - if (langId==null || langId.length()==0) - continue; - ILanguage language = LanguageManager.getInstance().getLanguage(langId); - if (language == null) - continue; + List languageIds = LanguageSettingsManager.getLanguages(rcDes); + Collections.sort(languageIds); + for (String langId : languageIds) { + ILanguage language = LanguageManager.getInstance().getLanguage(langId); + if (language == null) + continue; - langId = language.getName(); - if (langId == null || langId.length()==0) - continue; + String langName = language.getName(); + if (langName == null || langName.length()==0) + continue; - TreeItem t = new TreeItem(treeLanguages, SWT.NONE); - t.setText(0, langId); - t.setData(langSetting); - if (selectedLanguageItem == null) { - if (currentLanguageId!=null) { - if (currentLanguageId.equals(langSetting.getLanguageId())) { - selectedLanguageItem = t; - } - } else { + TreeItem t = new TreeItem(treeLanguages, SWT.NONE); + t.setText(0, langName); + t.setData(langId); + if (selectedLanguageItem == null) { + if (currentLanguageId!=null) { + if (currentLanguageId.equals(langId)) { selectedLanguageItem = t; - currentLanguageId = langSetting.getLanguageId(); } + } else { + selectedLanguageItem = t; + currentLanguageId = langId; } } + } - if (selectedLanguageItem != null) { - treeLanguages.setSelection(selectedLanguageItem); - } + if (selectedLanguageItem != null) { + treeLanguages.setSelection(selectedLanguageItem); } } @@ -988,24 +956,20 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { providers: for (ILanguageSettingsProvider provider : providers) { ILanguageSettingsEditableProvider writableProvider = null; if (provider instanceof ILanguageSettingsEditableProvider) { - TreeItem[] tisLang = treeLanguages.getItems(); - for (TreeItem tiLang : tisLang) { - Object item = tiLang.getData(); - if (item instanceof ICLanguageSetting) { - String languageId = ((ICLanguageSetting)item).getLanguageId(); - if (languageId!=null) { - if (provider.getSettingEntries(cfgDescription, rc, languageId)!=null) { - try { - // clone providers to be able to "Cancel" in UI - if (writableProvider==null) { - writableProvider = ((ILanguageSettingsEditableProvider) provider).clone(); - } - writableProvider.setSettingEntries(cfgDescription, rc, languageId, null); - changed = true; - } catch (CloneNotSupportedException e) { - CUIPlugin.log("Internal Error: cannot clone provider "+provider.getId(), e); - continue providers; + for (TreeItem langItems : treeLanguages.getItems()) { + String langId = (String)langItems.getData(); + if (langId!=null) { + if (provider.getSettingEntries(cfgDescription, rc, langId)!=null) { + try { + // clone providers to be able to "Cancel" in UI + if (writableProvider==null) { + writableProvider = ((ILanguageSettingsEditableProvider) provider).clone(); } + writableProvider.setSettingEntries(cfgDescription, rc, langId, null); + changed = true; + } catch (CloneNotSupportedException e) { + CUIPlugin.log("Internal Error: cannot clone provider "+provider.getId(), e); + continue providers; } } } @@ -1073,23 +1037,15 @@ providers: for (ILanguageSettingsProvider provider : providers) { if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS)) return false; - //filter out files not associated with any languages + //filter out files not associated with any languages such as *.o if (page.isForFile()) { - ICLanguageSetting [] langSettings = getLangSettings(getResDesc()); - if (langSettings == null) - return false; - - // files like *.o may have langSettings but no associated language - for (ICLanguageSetting langSetting : langSettings) { - String langId = langSetting.getLanguageId(); - if (langId!=null && langId.length()>0) { - LanguageManager langManager = LanguageManager.getInstance(); - ILanguageDescriptor langDes = langManager.getLanguageDescriptor(langId); - if (langDes != null) - return true; - } + List languageIds = LanguageSettingsManager.getLanguages(getResDesc()); + for (String langId : languageIds) { + LanguageManager langManager = LanguageManager.getInstance(); + ILanguage language = langManager.getLanguage(langId); + if (language != null) + return true; } - return false; }