mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 356632: Project specific language mappings
This commit is contained in:
parent
aa6c2c50d0
commit
36e3d3ad11
2 changed files with 53 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2005, 2009 QNX Software Systems and others.
|
* Copyright (c) 2005, 2011 QNX Software Systems 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
|
||||||
|
@ -118,8 +118,7 @@ public class LanguageManager {
|
||||||
HashMap<String, ILanguageDescriptor[]> map = new HashMap<String, ILanguageDescriptor[]>();
|
HashMap<String, ILanguageDescriptor[]> map = new HashMap<String, ILanguageDescriptor[]>();
|
||||||
Map<String, List<ILanguageDescriptor>> cache = getContentTypeToDescriptorCache();
|
Map<String, List<ILanguageDescriptor>> cache = getContentTypeToDescriptorCache();
|
||||||
|
|
||||||
for (Iterator<Entry<String, List<ILanguageDescriptor>>> iter = cache.entrySet().iterator(); iter.hasNext();) {
|
for (Entry<String, List<ILanguageDescriptor>> entry : cache.entrySet()) {
|
||||||
Entry<String, List<ILanguageDescriptor>> entry = iter.next();
|
|
||||||
List<ILanguageDescriptor> list = entry.getValue();
|
List<ILanguageDescriptor> list = entry.getValue();
|
||||||
if (list.size() > 0) {
|
if (list.size() > 0) {
|
||||||
ILanguageDescriptor[] dess = list.toArray(new ILanguageDescriptor[list.size()]);
|
ILanguageDescriptor[] dess = list.toArray(new ILanguageDescriptor[list.size()]);
|
||||||
|
@ -136,13 +135,10 @@ public class LanguageManager {
|
||||||
Map<String, ILanguageDescriptor> dc = getDescriptorCache();
|
Map<String, ILanguageDescriptor> dc = getDescriptorCache();
|
||||||
|
|
||||||
List<ILanguageDescriptor> list;
|
List<ILanguageDescriptor> list;
|
||||||
IContentType type;
|
|
||||||
String id;
|
String id;
|
||||||
for (Iterator<ILanguageDescriptor> iter = dc.values().iterator(); iter.hasNext();) {
|
for (ILanguageDescriptor des : dc.values()) {
|
||||||
ILanguageDescriptor des = iter.next();
|
|
||||||
IContentType types[] = des.getContentTypes();
|
IContentType types[] = des.getContentTypes();
|
||||||
for (int i = 0; i < types.length; i++) {
|
for (IContentType type : types) {
|
||||||
type = types[i];
|
|
||||||
id = type.getId();
|
id = type.getId();
|
||||||
list = map.get(id);
|
list = map.get(id);
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
|
@ -326,8 +322,7 @@ public class LanguageManager {
|
||||||
|
|
||||||
// read configuration
|
// read configuration
|
||||||
IConfigurationElement[] configs= Platform.getExtensionRegistry().getConfigurationElementsFor(LANGUAGE_EXTENSION_POINT_ID);
|
IConfigurationElement[] configs= Platform.getExtensionRegistry().getConfigurationElementsFor(LANGUAGE_EXTENSION_POINT_ID);
|
||||||
for (int i = 0; i < configs.length; i++) {
|
for (final IConfigurationElement element : configs) {
|
||||||
final IConfigurationElement element = configs[i];
|
|
||||||
if (ELEMENT_PDOM_LINKAGE_FACTORY.equals(element.getName())) {
|
if (ELEMENT_PDOM_LINKAGE_FACTORY.equals(element.getName())) {
|
||||||
SafeRunner.run(new ISafeRunnable() {
|
SafeRunner.run(new ISafeRunnable() {
|
||||||
public void handleException(Throwable exception) {
|
public void handleException(Throwable exception) {
|
||||||
|
@ -609,8 +604,8 @@ public class LanguageManager {
|
||||||
public void notifyLanguageChangeListeners(ILanguageMappingChangeEvent event) {
|
public void notifyLanguageChangeListeners(ILanguageMappingChangeEvent event) {
|
||||||
Object[] listeners = fLanguageChangeListeners.getListeners();
|
Object[] listeners = fLanguageChangeListeners.getListeners();
|
||||||
|
|
||||||
for (int i= 0; i < listeners.length; i++) {
|
for (Object obj : listeners) {
|
||||||
ILanguageMappingChangeListener listener = (ILanguageMappingChangeListener) listeners[i];
|
ILanguageMappingChangeListener listener = (ILanguageMappingChangeListener) obj;
|
||||||
listener.handleLanguageMappingChangeEvent(event);
|
listener.handleLanguageMappingChangeEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -638,4 +633,47 @@ public class LanguageManager {
|
||||||
event.setFile(file);
|
event.setFile(file);
|
||||||
notifyLanguageChangeListeners(event);
|
notifyLanguageChangeListeners(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns language binding to a particular content type for given project.
|
||||||
|
* This method will check project settings, workspace settings and default
|
||||||
|
* bindings (in that order)
|
||||||
|
*
|
||||||
|
* @param contentType content type of the file
|
||||||
|
* @param project C/C++ workspace project
|
||||||
|
* @return CDT language object
|
||||||
|
* @since 5.4
|
||||||
|
*/
|
||||||
|
public ILanguage getLanguage(IContentType contentType, IProject project) {
|
||||||
|
return getLanguage(contentType, project, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns language binding to a particular content type for given project.
|
||||||
|
* This method will check project settings, workspace settings and default
|
||||||
|
* bindings (in that order)
|
||||||
|
*
|
||||||
|
* @param contentType content type of the file
|
||||||
|
* @param project C/C++ workspace project
|
||||||
|
* @param configurationDescription build configuration or <code>null</code>
|
||||||
|
* @return CDT language object
|
||||||
|
* @since 5.4
|
||||||
|
*/
|
||||||
|
public ILanguage getLanguage(IContentType contentType,
|
||||||
|
IProject project, ICConfigurationDescription configurationDescription) {
|
||||||
|
try {
|
||||||
|
final ProjectLanguageConfiguration projectConfig = getLanguageConfiguration(project);
|
||||||
|
final String contentTypeId = contentType.getId();
|
||||||
|
String langId = projectConfig.getLanguageForContentType(configurationDescription,
|
||||||
|
contentTypeId);
|
||||||
|
if (langId == null) {
|
||||||
|
WorkspaceLanguageConfiguration wsConfig = getWorkspaceLanguageConfiguration();
|
||||||
|
langId = wsConfig.getLanguageForContentType(contentTypeId);
|
||||||
|
}
|
||||||
|
return langId != null ? getLanguage(langId) : getLanguage(contentType);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
// Fall through to default language mapping
|
||||||
|
}
|
||||||
|
return getLanguage(contentType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,9 +166,10 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractLanguage[] getLanguages(String filename) {
|
protected AbstractLanguage[] getLanguages(String filename) {
|
||||||
IContentType ct= CCorePlugin.getContentType(getProject().getProject(), filename);
|
IProject project = getProject().getProject();
|
||||||
|
IContentType ct= CCorePlugin.getContentType(project, filename);
|
||||||
if (ct != null) {
|
if (ct != null) {
|
||||||
ILanguage l = LanguageManager.getInstance().getLanguage(ct);
|
ILanguage l = LanguageManager.getInstance().getLanguage(ct, project);
|
||||||
if (l instanceof AbstractLanguage) {
|
if (l instanceof AbstractLanguage) {
|
||||||
if (filename.indexOf('.') >= 0 && ct.getId().equals(CCorePlugin.CONTENT_TYPE_CXXHEADER) &&
|
if (filename.indexOf('.') >= 0 && ct.getId().equals(CCorePlugin.CONTENT_TYPE_CXXHEADER) &&
|
||||||
l.getLinkageID() == ILinkage.CPP_LINKAGE_ID) {
|
l.getLinkageID() == ILinkage.CPP_LINKAGE_ID) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue