1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 19:35:36 +02:00

utility function to get languages from ICResourceDescription

This commit is contained in:
Andrew Gvozdev 2011-09-09 12:51:23 -04:00
parent d192508e91
commit e5fb5bf1c0
7 changed files with 171 additions and 224 deletions

View file

@ -26,9 +26,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.eclipse.cdt.core.ErrorParserManager; 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.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;
@ -243,13 +242,12 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
public boolean processLine(String line, ErrorParserManager epm) { public boolean processLine(String line, ErrorParserManager epm) {
errorParserManager = epm; errorParserManager = epm;
parsedResourceName = parseForResourceName(line); parsedResourceName = parseForResourceName(line);
currentResource = findResource(parsedResourceName);
currentLanguageId = determineLanguage(parsedResourceName); currentLanguageId = determineLanguage();
if (!isLanguageInScope(currentLanguageId)) if (!isLanguageInScope(currentLanguageId))
return false; return false;
currentResource = findResource(parsedResourceName);
/** /**
* URI of directory where the build is happening. This URI could point to a remote filesystem * 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 * 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); MakeCorePlugin.log(status);
} }
protected String determineLanguage(String parsedResourceName) { protected String determineLanguage() {
if (parsedResourceName==null) IResource rc = currentResource;
return null; if (rc == null && currentProject != null && parsedResourceName != null) {
String fileName = new Path(parsedResourceName).lastSegment().toString(); String fileName = new Path(parsedResourceName).lastSegment().toString();
IContentTypeManager manager = Platform.getContentTypeManager(); // use handle; resource does not need to exist
IContentType contentType = manager.findContentTypeFor(fileName); rc = currentProject.getFile("__" + fileName);
if (contentType==null) }
if (rc == null)
return null; return null;
ILanguage lang = LanguageManager.getInstance().getLanguage(contentType); List<String> languageIds = LanguageSettingsManager.getLanguages(rc, currentCfgDescription);
if (lang==null) if (languageIds.isEmpty())
return null; return null;
return lang.getId(); return languageIds.get(0);
} }
protected boolean isLanguageInScope(String languageId) { protected boolean isLanguageInScope(String languageId) {

View file

@ -60,8 +60,6 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; 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.ICMultiConfigDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; 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, static public void runBuiltinSpecsDetectors(ICConfigurationDescription cfgDescription, IPath workingDirectory,
String[] env, IProgressMonitor monitor) { String[] env, IProgressMonitor monitor) {
IProject project = cfgDescription.getProjectDescription().getProject(); IProject project = cfgDescription.getProjectDescription().getProject();
ICFolderDescription rootFolderDescription = cfgDescription.getRootFolderDescription(); List<String> languageIds = LanguageSettingsManager.getLanguages(project, cfgDescription);
List<String> languageIds = new ArrayList<String>(); if (languageIds.isEmpty()) {
for (ICLanguageSetting languageSetting : rootFolderDescription.getLanguageSettings()) { return;
String id = languageSetting.getLanguageId();
if (id!=null) {
languageIds.add(id);
}
} }
for (ILanguageSettingsProvider provider : cfgDescription.getLanguageSettingProviders()) { for (ILanguageSettingsProvider provider : cfgDescription.getLanguageSettingProviders()) {

View file

@ -148,7 +148,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
} }
@Override @Override
protected String determineLanguage(String parsedResourceName) { protected String determineLanguage() {
// language id is supposed to be set by run(), just return it // language id is supposed to be set by run(), just return it
return currentLanguageId; return currentLanguageId;
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation * Andrew Gvozdev - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.language.settings.providers; package org.eclipse.cdt.core.language.settings.providers;
import java.util.ArrayList;
import java.util.List; 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.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.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
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.internal.core.LocalProjectScope;
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager;
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; 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.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.core.runtime.IPath;
import org.osgi.service.prefs.Preferences;
/** /**
* A collection of utility methods to manage language settings providers. * A collection of utility methods to manage language settings providers.
@ -167,4 +174,82 @@ public class LanguageSettingsManager {
return provider; 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<String> 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<String> languageIds = new ArrayList<String>();
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<String> getLanguages(IResource resource, ICConfigurationDescription cfgDescription) {
List<String> languageIds = new ArrayList<String>();
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;
}
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation * Andrew Gvozdev - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.language.settings.providers; 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.CCorePlugin;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; 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.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; 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.LanguageSettingsExtensionManager;
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer; 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; import org.eclipse.core.runtime.CoreException;
/** /**
* TODO * This temporary class keeps the utility methods being looking for better home
* This layer of language settings in TODO
*
* Duplicate entries are filtered where only first entry is preserved.
*
*/ */
public class LanguageSettingsManager_TBD { public class LanguageSettingsManager_TBD {
public static final String PROVIDER_UNKNOWN = "org.eclipse.cdt.projectmodel.4.0.0"; 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 String PROVIDER_UI_USER = "org.eclipse.cdt.ui.user.LanguageSettingsProvider";
public static final char PROVIDER_DELIMITER = LanguageSettingsProvidersSerializer.PROVIDER_DELIMITER; 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) { public static boolean isCustomizedResource(ICConfigurationDescription cfgDescription, IResource rc) {
if (rc instanceof IProject) if (rc instanceof IProject)
return false; return false;
@ -59,20 +39,17 @@ public class LanguageSettingsManager_TBD {
// FIXME // FIXME
// if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { // if (!LanguageSettingsManager.isWorkspaceProvider(provider)) {
if (provider instanceof ILanguageSettingsEditableProvider || provider instanceof LanguageSettingsSerializable) { if (provider instanceof ILanguageSettingsEditableProvider || provider instanceof LanguageSettingsSerializable) {
ICResourceDescription rcDescription = cfgDescription.getResourceDescription(rc.getProjectRelativePath(), false); for (String languageId : LanguageSettingsManager.getLanguages(rc, cfgDescription)) {
for (ICLanguageSetting languageSetting : getLanguageIds(rcDescription)) {
String languageId = languageSetting.getLanguageId();
if (languageId!=null) {
List<ICLanguageSettingEntry> list = provider.getSettingEntries(cfgDescription, rc, languageId); List<ICLanguageSettingEntry> list = provider.getSettingEntries(cfgDescription, rc, languageId);
if (list!=null) { if (list!=null) {
List<ICLanguageSettingEntry> listDefault = provider.getSettingEntries(null, null, languageId); List<ICLanguageSettingEntry> listDefault = provider.getSettingEntries(null, null, languageId);
if (!list.equals(listDefault)) // != is OK here due as the equal lists will have the same reference in WeakHashSet
if (list != listDefault)
return true; return true;
} }
} }
} }
} }
}
return false; return false;
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation * Andrew Gvozdev - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.language.settings.providers; 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.CCorePlugin;
import org.eclipse.cdt.core.cdtvariables.CdtVariableException; import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager; import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.core.parser.ExtendedScannerInfo; import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.settings.model.ACPathEntry; import org.eclipse.cdt.core.settings.model.ACPathEntry;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; 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.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingPathEntry;
import org.eclipse.cdt.core.settings.model.ICMacroEntry; import org.eclipse.cdt.core.settings.model.ICMacroEntry;
import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICSettingEntry; 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.CProjectDescriptionManager;
import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages; 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.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -72,8 +66,10 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider
if (cfgDescription==null) if (cfgDescription==null)
return DUMMY_SCANNER_INFO; return DUMMY_SCANNER_INFO;
List<String> languageIds = getLanguageIds(cfgDescription, rc); List<String> languageIds = LanguageSettingsManager.getLanguages(rc, cfgDescription);
if (languageIds==null || languageIds.size()==0) { 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; return DUMMY_SCANNER_INFO;
} }
@ -121,66 +117,6 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider
return new ExtendedScannerInfo(definedMacros, includePaths, macroFiles, includeFiles, includePathsLocal); return new ExtendedScannerInfo(definedMacros, includePaths, macroFiles, includeFiles, includePathsLocal);
} }
private List<String> getLanguageIds(ICConfigurationDescription cfgDescription, IResource resource) {
List<String> languageIds = null;
if (resource instanceof IFile) {
String langId = getLanguageIdForFile(cfgDescription, resource);
if (langId!=null) {
languageIds = new ArrayList<String>(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<String> getLanguageIdsForFolder(ICConfigurationDescription cfgDescription, IContainer resource) {
// Using MBS for folders. That will take language ID from input type of applicable tools in the toolchain.
List<String> languageIds = new ArrayList<String>();
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) { private IPath expandVariables(IPath path, ICConfigurationDescription cfgDescription) {
ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager(); ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager();
String pathStr = path.toString(); String pathStr = path.toString();

View file

@ -12,7 +12,6 @@
package org.eclipse.cdt.internal.ui.language.settings.providers; package org.eclipse.cdt.internal.ui.language.settings.providers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; 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.LanguageSettingsSerializable;
import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport;
import org.eclipse.cdt.core.model.ILanguage; 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.LanguageManager;
import org.eclipse.cdt.core.model.util.CDTListComparator;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; 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.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICResourceDescription; 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.ICSettingEntry;
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider; import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
import org.eclipse.cdt.ui.CDTSharedImages; 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.AbstractCPropertyTab;
import org.eclipse.cdt.ui.newui.CDTPrefUtil; import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages;
import org.eclipse.cdt.internal.ui.newui.Messages; import org.eclipse.cdt.internal.ui.newui.Messages;
import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; import org.eclipse.cdt.internal.ui.newui.StatusMessageLine;
@ -89,7 +81,6 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
private Tree treeEntries; private Tree treeEntries;
private TreeViewer treeEntriesViewer; private TreeViewer treeEntriesViewer;
private String currentLanguageId = null; private String currentLanguageId = null;
private ICLanguageSetting[] allLanguages;
private Button builtInCheckBox; private Button builtInCheckBox;
private Button enableProvidersCheckBox; private Button enableProvidersCheckBox;
@ -320,14 +311,11 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
TreeItem[] items = treeLanguages.getSelection(); TreeItem[] items = treeLanguages.getSelection();
if (items.length > 0) { if (items.length > 0) {
ICLanguageSetting langSetting = (ICLanguageSetting) items[0].getData(); currentLanguageId = (String) items[0].getData();
if (langSetting != null) {
currentLanguageId = langSetting.getLanguageId();
updateTreeEntries(); updateTreeEntries();
updateButtons(); updateButtons();
} }
} }
}
}); });
final TreeColumn columnLanguages = new TreeColumn(treeLanguages, SWT.NONE); final TreeColumn columnLanguages = new TreeColumn(treeLanguages, SWT.NONE);
@ -887,51 +875,32 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
updateButtons(); 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) { private void updateTreeLanguages(ICResourceDescription rcDes) {
treeLanguages.removeAll(); treeLanguages.removeAll();
TreeItem selectedLanguageItem = null; 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;
List<String> languageIds = LanguageSettingsManager.getLanguages(rcDes);
Collections.sort(languageIds);
for (String langId : languageIds) {
ILanguage language = LanguageManager.getInstance().getLanguage(langId); ILanguage language = LanguageManager.getInstance().getLanguage(langId);
if (language == null) if (language == null)
continue; continue;
langId = language.getName(); String langName = language.getName();
if (langId == null || langId.length()==0) if (langName == null || langName.length()==0)
continue; continue;
TreeItem t = new TreeItem(treeLanguages, SWT.NONE); TreeItem t = new TreeItem(treeLanguages, SWT.NONE);
t.setText(0, langId); t.setText(0, langName);
t.setData(langSetting); t.setData(langId);
if (selectedLanguageItem == null) { if (selectedLanguageItem == null) {
if (currentLanguageId!=null) { if (currentLanguageId!=null) {
if (currentLanguageId.equals(langSetting.getLanguageId())) { if (currentLanguageId.equals(langId)) {
selectedLanguageItem = t; selectedLanguageItem = t;
} }
} else { } else {
selectedLanguageItem = t; selectedLanguageItem = t;
currentLanguageId = langSetting.getLanguageId(); currentLanguageId = langId;
} }
} }
} }
@ -940,7 +909,6 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
treeLanguages.setSelection(selectedLanguageItem); treeLanguages.setSelection(selectedLanguageItem);
} }
} }
}
/** /**
* Called when configuration changed Refreshes languages list entries tree. * Called when configuration changed Refreshes languages list entries tree.
@ -988,19 +956,16 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
providers: for (ILanguageSettingsProvider provider : providers) { providers: for (ILanguageSettingsProvider provider : providers) {
ILanguageSettingsEditableProvider writableProvider = null; ILanguageSettingsEditableProvider writableProvider = null;
if (provider instanceof ILanguageSettingsEditableProvider) { if (provider instanceof ILanguageSettingsEditableProvider) {
TreeItem[] tisLang = treeLanguages.getItems(); for (TreeItem langItems : treeLanguages.getItems()) {
for (TreeItem tiLang : tisLang) { String langId = (String)langItems.getData();
Object item = tiLang.getData(); if (langId!=null) {
if (item instanceof ICLanguageSetting) { if (provider.getSettingEntries(cfgDescription, rc, langId)!=null) {
String languageId = ((ICLanguageSetting)item).getLanguageId();
if (languageId!=null) {
if (provider.getSettingEntries(cfgDescription, rc, languageId)!=null) {
try { try {
// clone providers to be able to "Cancel" in UI // clone providers to be able to "Cancel" in UI
if (writableProvider==null) { if (writableProvider==null) {
writableProvider = ((ILanguageSettingsEditableProvider) provider).clone(); writableProvider = ((ILanguageSettingsEditableProvider) provider).clone();
} }
writableProvider.setSettingEntries(cfgDescription, rc, languageId, null); writableProvider.setSettingEntries(cfgDescription, rc, langId, null);
changed = true; changed = true;
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
CUIPlugin.log("Internal Error: cannot clone provider "+provider.getId(), e); CUIPlugin.log("Internal Error: cannot clone provider "+provider.getId(), e);
@ -1010,7 +975,6 @@ providers: for (ILanguageSettingsProvider provider : providers) {
} }
} }
} }
}
if (writableProvider!=null) if (writableProvider!=null)
writableProviders.add(writableProvider); writableProviders.add(writableProvider);
else else
@ -1073,23 +1037,15 @@ providers: for (ILanguageSettingsProvider provider : providers) {
if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS)) if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS))
return false; return false;
//filter out files not associated with any languages //filter out files not associated with any languages such as *.o
if (page.isForFile()) { if (page.isForFile()) {
ICLanguageSetting [] langSettings = getLangSettings(getResDesc()); List<String> languageIds = LanguageSettingsManager.getLanguages(getResDesc());
if (langSettings == null) for (String langId : languageIds) {
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(); LanguageManager langManager = LanguageManager.getInstance();
ILanguageDescriptor langDes = langManager.getLanguageDescriptor(langId); ILanguage language = langManager.getLanguage(langId);
if (langDes != null) if (language != null)
return true; return true;
} }
}
return false; return false;
} }