summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Ostroukhov2011-09-07 06:31:09 (EDT)
committerMarkus Schorn2011-09-19 08:10:18 (EDT)
commit36e3d3ad1109729bb5cf9631bfc36ce3fbd511f1 (patch)
treea514c54f3ab9241e27dbbbcacb7a25ac5cb4b8d7
parentaa6c2c50d0a58928d81a576e29a3fae50d2c3e5f (diff)
downloadorg.eclipse.cdt-36e3d3ad1109729bb5cf9631bfc36ce3fbd511f1.zip
org.eclipse.cdt-36e3d3ad1109729bb5cf9631bfc36ce3fbd511f1.tar.gz
org.eclipse.cdt-36e3d3ad1109729bb5cf9631bfc36ce3fbd511f1.tar.bz2
Bug 356632: Project specific language mappings
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java62
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java5
2 files changed, 53 insertions, 14 deletions
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java
index c6acb69..63fe230 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java
@@ -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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -118,8 +118,7 @@ public class LanguageManager {
HashMap<String, ILanguageDescriptor[]> map = new HashMap<String, ILanguageDescriptor[]>();
Map<String, List<ILanguageDescriptor>> cache = getContentTypeToDescriptorCache();
- for (Iterator<Entry<String, List<ILanguageDescriptor>>> iter = cache.entrySet().iterator(); iter.hasNext();) {
- Entry<String, List<ILanguageDescriptor>> entry = iter.next();
+ for (Entry<String, List<ILanguageDescriptor>> entry : cache.entrySet()) {
List<ILanguageDescriptor> list = entry.getValue();
if (list.size() > 0) {
ILanguageDescriptor[] dess = list.toArray(new ILanguageDescriptor[list.size()]);
@@ -136,13 +135,10 @@ public class LanguageManager {
Map<String, ILanguageDescriptor> dc = getDescriptorCache();
List<ILanguageDescriptor> list;
- IContentType type;
String id;
- for (Iterator<ILanguageDescriptor> iter = dc.values().iterator(); iter.hasNext();) {
- ILanguageDescriptor des = iter.next();
+ for (ILanguageDescriptor des : dc.values()) {
IContentType types[] = des.getContentTypes();
- for (int i = 0; i < types.length; i++) {
- type = types[i];
+ for (IContentType type : types) {
id = type.getId();
list = map.get(id);
if (list == null) {
@@ -326,8 +322,7 @@ public class LanguageManager {
// read configuration
IConfigurationElement[] configs= Platform.getExtensionRegistry().getConfigurationElementsFor(LANGUAGE_EXTENSION_POINT_ID);
- for (int i = 0; i < configs.length; i++) {
- final IConfigurationElement element = configs[i];
+ for (final IConfigurationElement element : configs) {
if (ELEMENT_PDOM_LINKAGE_FACTORY.equals(element.getName())) {
SafeRunner.run(new ISafeRunnable() {
public void handleException(Throwable exception) {
@@ -609,8 +604,8 @@ public class LanguageManager {
public void notifyLanguageChangeListeners(ILanguageMappingChangeEvent event) {
Object[] listeners = fLanguageChangeListeners.getListeners();
- for (int i= 0; i < listeners.length; i++) {
- ILanguageMappingChangeListener listener = (ILanguageMappingChangeListener) listeners[i];
+ for (Object obj : listeners) {
+ ILanguageMappingChangeListener listener = (ILanguageMappingChangeListener) obj;
listener.handleLanguageMappingChangeEvent(event);
}
}
@@ -638,4 +633,47 @@ public class LanguageManager {
event.setFile(file);
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);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java
index bd116b0..66844f2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java
@@ -166,9 +166,10 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
@Override
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) {
- ILanguage l = LanguageManager.getInstance().getLanguage(ct);
+ ILanguage l = LanguageManager.getInstance().getLanguage(ct, project);
if (l instanceof AbstractLanguage) {
if (filename.indexOf('.') >= 0 && ct.getId().equals(CCorePlugin.CONTENT_TYPE_CXXHEADER) &&
l.getLinkageID() == ILinkage.CPP_LINKAGE_ID) {