Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorChris Recoskie2007-02-06 21:57:39 +0000
committerChris Recoskie2007-02-06 21:57:39 +0000
commitcc7e0a31f78bddf155115ba51eaa2cf833f7ee72 (patch)
tree97739c515d3c7b89a912721c0d6c5ab7a517c2ba /core
parent167425f50a5f1a2f3677a118ff65b0aca5b6ddae (diff)
downloadorg.eclipse.cdt-cc7e0a31f78bddf155115ba51eaa2cf833f7ee72.tar.gz
org.eclipse.cdt-cc7e0a31f78bddf155115ba51eaa2cf833f7ee72.tar.xz
org.eclipse.cdt-cc7e0a31f78bddf155115ba51eaa2cf833f7ee72.zip
initial checkin as a part of work for 151850 (allow user to specify which parser/language to parse a given content type with)
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java31
-rw-r--r--core/org.eclipse.cdt.core/META-INF/MANIFEST.MF1
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java8
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java180
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/LanguageMappingConfiguration.java41
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/LanguageMappingStore.java104
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/Messages.java22
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/messages.properties2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java4
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java18
-rw-r--r--core/org.eclipse.cdt.ui/plugin.properties2
-rw-r--r--core/org.eclipse.cdt.ui/plugin.xml11
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/ContentTypeMappingDialog.java172
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/ProjectLanguageMappingPropertyPage.java209
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java9
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties10
23 files changed, 828 insertions, 37 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java
index a0a593e22b4..a5160441b6d 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Symbian Software Systems and others.
+ * Copyright (c) 2006, 2007 Symbian 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
+ * IBM Corporation
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
@@ -27,12 +28,15 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.osgi.framework.Bundle;
@@ -82,7 +86,18 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase {
}
protected IBinding getBindingFromASTName(String section, int len) {
- IASTName[] names= ast.getLanguage().getSelectedNames(ast, testData[1].indexOf(section), len);
+ // get the language from the language manager
+ ILanguage language = null;
+ try {
+ language = LanguageManager.getInstance().getLanguageForFile(ast.getFilePath(), cproject.getProject());
+ } catch (CoreException e) {
+ fail("Unexpected exception while getting language for file.");
+ }
+
+
+ assertNotNull("No language for file " + ast.getFilePath().toString(), language);
+
+ IASTName[] names= language.getSelectedNames(ast, testData[1].indexOf(section), len);
assertEquals("<>1 name found for \""+section+"\"", 1, names.length);
IBinding binding = names[0].resolveBinding();
assertNotNull("No binding for "+names[0].getRawSignature(), binding);
@@ -91,7 +106,17 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase {
}
protected IBinding getProblemFromASTName(String section, int len) {
- IASTName[] names= ast.getLanguage().getSelectedNames(ast, testData[1].indexOf(section), len);
+ // get the language from the language manager
+ ILanguage language = null;
+ try {
+ language = LanguageManager.getInstance().getLanguageForFile(ast.getFilePath(), cproject.getProject());
+ } catch (CoreException e) {
+ fail("Unexpected exception while getting language for file.");
+ }
+
+ assertNotNull("No language for file " + ast.getFilePath().toString(), language);
+
+ IASTName[] names= language.getSelectedNames(ast, testData[1].indexOf(section), len);
assertEquals("<>1 name found for \""+section+"\"", 1, names.length);
IBinding binding = names[0].resolveBinding();
assertNotNull("No binding for "+names[0].getRawSignature(), binding);
diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
index 650bde99d4f..0cee4029aad 100644
--- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
@@ -32,6 +32,7 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.internal.core.dom.parser.c;x-friends:="org.eclipse.cdt.refactoring",
org.eclipse.cdt.internal.core.dom.parser.cpp;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
org.eclipse.cdt.internal.core.index;x-internal:=true,
+ org.eclipse.cdt.internal.core.language;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.parser;x-internal:=true,
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java
index eccf990af24..95f0f35d69a 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 QNX Software Systems and others.
+ * Copyright (c) 2005, 2007 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
@@ -63,6 +63,12 @@ public interface ILanguage extends IAdaptable {
public String getId();
/**
+ * @return the human readable name corresponding to this language, suitable for display.
+ * @since 4.0
+ */
+ public String getName();
+
+ /**
* @deprecated use {@link ITranslationUnit#getAST()}.
*/
public IASTTranslationUnit getASTTranslationUnit(
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 ec922927c1a..07d6dc11fe0 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, 2006 QNX Software Systems and others.
+ * Copyright (c) 2005, 2007 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
@@ -15,15 +15,24 @@ package org.eclipse.cdt.core.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
+import org.eclipse.cdt.internal.core.CContentTypes;
+import org.eclipse.cdt.internal.core.language.LanguageMappingConfiguration;
+import org.eclipse.cdt.internal.core.language.LanguageMappingStore;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SafeRunner;
@@ -47,6 +56,8 @@ public class LanguageManager {
private Map fLanguageCache = new HashMap();
private Map fPDOMLinkageFactoryCache= new HashMap();
private Map fContentTypeToLanguageCache= new HashMap();
+ private Map fLanguageConfigurationCache = new HashMap();
+ private boolean fIsFullyCached;
public static LanguageManager getInstance() {
if (instance == null)
@@ -95,6 +106,8 @@ public class LanguageManager {
}
private ILanguage getLanguageForContentTypeID(String contentTypeID) {
+ cacheAllLanguages();
+
ILanguage language = (ILanguage)fContentTypeToLanguageCache.get(contentTypeID);
if (language != null || fContentTypeToLanguageCache.containsKey(contentTypeID))
return language;
@@ -224,4 +237,169 @@ public class LanguageManager {
}
return result[0];
}
+
+ public ILanguage[] getRegisteredLanguages() {
+ cacheAllLanguages();
+ ILanguage[] languages = new ILanguage[fLanguageCache.size()];
+ Iterator values = fLanguageCache.values().iterator();
+ for (int i = 0; values.hasNext(); i++) {
+ languages[i] = (ILanguage) values.next();
+ }
+ return languages;
+ }
+
+ private void cacheAllLanguages() {
+ if (fIsFullyCached) {
+ return;
+ }
+ IConfigurationElement[] configs= Platform.getExtensionRegistry().getConfigurationElementsFor(LANGUAGE_EXTENSION_POINT_ID);
+ for (int j = 0; j < configs.length; ++j) {
+ final IConfigurationElement languageElem = configs[j];
+ if (ELEMENT_LANGUAGE.equals(languageElem.getName())) {
+ String langId = getLanguageID(languageElem);
+ final ILanguage[] result= new ILanguage[]{null};
+ SafeRunner.run(new ISafeRunnable(){
+ public void handleException(Throwable exception) {
+ CCorePlugin.log(exception);
+ }
+
+ public void run() throws Exception {
+ result[0]= (ILanguage)languageElem.createExecutableExtension(ATTRIBUTE_CLASS);
+ }
+ });
+ if (result[0] != null) {
+ fLanguageCache.put(langId, result[0]);
+ }
+ }
+ }
+ fIsFullyCached = true;
+ }
+
+ public LanguageMappingConfiguration getLanguageMappingConfiguration(IProject project) throws CoreException {
+ LanguageMappingConfiguration mappings = (LanguageMappingConfiguration) fLanguageConfigurationCache.get(project);
+ if (mappings != null) {
+ return mappings;
+ }
+
+ LanguageMappingStore store = new LanguageMappingStore(project);
+ mappings = store.decodeMappings();
+ fLanguageConfigurationCache.put(project, mappings);
+ return mappings;
+ }
+
+ public void storeLanguageMappingConfiguration(IProject project) throws CoreException {
+ LanguageMappingConfiguration mappings = (LanguageMappingConfiguration) fLanguageConfigurationCache.get(project);
+ LanguageMappingStore store = new LanguageMappingStore(project);
+ store.storeMappings(mappings);
+ }
+
+ /**
+ * @since 4.0
+ * @return an ILanguage representing the language to be used for the given file
+ * @param fullPathToFile the full path to the file for which the language is requested
+ * @param project the IProject that this file is in the context of. This field cannot be null.
+ * @throws CoreException
+ * TODO: implement other mapping levels besides project level and content type level
+ */
+ public ILanguage getLanguageForFile(String fullPathToFile, IProject project) throws CoreException {
+
+ if(project == null)
+ throw new IllegalArgumentException("project must not be null in call to LanguageManager.getLanguageForFile(String, IProject)");
+
+ IContentType contentType = CContentTypes.getContentType(project, fullPathToFile);
+
+ if(contentType == null)
+ {
+ return null;
+ }
+
+ String contentTypeID = contentType.getId();
+
+ // TODO: other mappings would go here
+
+ // Project-level mappings
+ LanguageMappingConfiguration mappings = getLanguageMappingConfiguration(project);
+ if (mappings != null) {
+ String id = (String) mappings.getProjectMappings().get(contentType);
+ if (id != null) {
+ return getLanguage(id);
+ }
+ }
+
+ // Content type mappings
+ return getLanguageForContentTypeID(contentTypeID);
+ }
+
+ /**
+ * @since 4.0
+ * @return an ILanguage representing the language to be used for the given file
+ * @param pathToFile the path to the file for which the language is requested.
+ * The path can be either workspace or project relative.
+ * @param project the project that this file should be parsed in context of. This field is optional and may
+ * be set to null. If the project is null then this method tries to determine the project context via workspace APIs.
+ * @throws CoreException
+ * * TODO: implement other mapping levels besides project level and content type level
+ */
+ public ILanguage getLanguageForFile(IPath pathToFile, IProject project) throws CoreException {
+ IResource resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(pathToFile);
+
+
+ IContentType contentType = CContentTypes.getContentType(project, pathToFile.toString());
+
+ if(contentType == null)
+ {
+ return null;
+ }
+
+ String contentTypeID = contentType.getId();
+
+ // if we don't have a project but have an IResource then we can infer the project
+ if (project == null && resource != null) {
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(
+ pathToFile.segment(0));
+
+ }
+
+ // TODO: other mappings would go here
+
+ // Project-level mappings
+ LanguageMappingConfiguration mappings = getLanguageMappingConfiguration(project);
+ if (mappings != null) {
+ String id = (String) mappings.getProjectMappings().get(contentType);
+ if (id != null) {
+ return getLanguage(id);
+ }
+ }
+
+ // Content type mappings
+ return getLanguageForContentTypeID(contentTypeID);
+ }
+
+ /**
+ * @since 4.0
+ * @return an ILanguage representing the language to be used for the given file
+ * @param file the file for which the language is requested
+ * @throws CoreException
+ * TODO: implement other mapping levels besides project level and content type level
+ */
+ public ILanguage getLanguageForFile(IFile file) throws CoreException {
+ IProject project = file.getProject();
+
+ IContentType contentType = CContentTypes.getContentType(project, file.getLocation().toString());
+
+ // TODO: other mappings would go here
+
+ // Project-level mappings
+ LanguageMappingConfiguration mappings = getLanguageMappingConfiguration(project);
+ if (mappings != null) {
+ String id = (String) mappings.getProjectMappings().get(contentType.getId());
+ if (id != null) {
+ return getLanguage(id);
+ }
+ }
+
+ // Content type mappings
+ return getLanguageForContentTypeID(contentType.getId());
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/LanguageMappingConfiguration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/LanguageMappingConfiguration.java
new file mode 100644
index 00000000000..70a5349cb73
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/LanguageMappingConfiguration.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation 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:
+ * IBM Corporation - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.language;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeMap;
+
+public class LanguageMappingConfiguration {
+
+ private Map fProjectMappings;
+
+ public LanguageMappingConfiguration() {
+ fProjectMappings = new TreeMap();
+ }
+
+ public Map getProjectMappings() {
+ return Collections.unmodifiableMap(fProjectMappings);
+ }
+
+ public void setProjectMappings(Map projectMappings) {
+ fProjectMappings = projectMappings;
+ }
+
+ public void addProjectMapping(String contentType, String language) {
+ fProjectMappings.put(contentType, language);
+ }
+
+ public void removeProjectMapping(String contentType) {
+ fProjectMappings.remove(contentType);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/LanguageMappingStore.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/LanguageMappingStore.java
new file mode 100644
index 00000000000..9c4c3f0d35e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/LanguageMappingStore.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation 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:
+ * IBM Corporation - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.language;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Map.Entry;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class LanguageMappingStore {
+ private static final String LANGUAGE_MAPPING_ID = "org.eclipse.cdt.core.language.mapping";
+
+ private static final String PROJECT_MAPPINGS = "project-mappings";
+
+ private static final String PROJECT_MAPPING = "project-mapping";
+
+ private static final String ATTRIBUTE_CONTENT_TYPE = "content-type";
+
+ private static final String ATTRIBUTE_LANGUAGE = "language";
+
+ private IProject fProject;
+
+ public LanguageMappingStore(IProject project) {
+ fProject = project;
+ }
+
+ public LanguageMappingConfiguration decodeMappings() throws CoreException {
+ LanguageMappingConfiguration config = new LanguageMappingConfiguration();
+ ICDescriptor descriptor = getProjectDescription();
+ Element rootElement = descriptor.getProjectData(LANGUAGE_MAPPING_ID);
+ if (rootElement == null) {
+ return config;
+ }
+ config.setProjectMappings(decodeProjectMappings(rootElement));
+ return config;
+ }
+
+ protected ICDescriptor getProjectDescription() throws CoreException {
+ return CCorePlugin.getDefault().getCProjectDescription(fProject, true);
+ }
+
+ private Map decodeProjectMappings(Element rootElement) throws CoreException {
+ Map decodedMappings = new TreeMap();
+ NodeList elements = rootElement.getElementsByTagName(PROJECT_MAPPINGS);
+ for (int i = 0; i < elements.getLength(); i++) {
+ Element projectMappings = (Element) elements.item(i);
+ NodeList mappingElements = projectMappings.getElementsByTagName(PROJECT_MAPPING);
+ for (int j = 0; j < mappingElements.getLength(); j++) {
+ Element mapping = (Element) mappingElements.item(j);
+ String contentType = mapping.getAttribute(ATTRIBUTE_CONTENT_TYPE);
+ String language = mapping.getAttribute(ATTRIBUTE_LANGUAGE);
+ decodedMappings.put(contentType, language);
+ }
+ }
+ return decodedMappings;
+ }
+
+ public void storeMappings(LanguageMappingConfiguration config) throws CoreException {
+ ICDescriptor descriptor = getProjectDescription();
+ Element rootElement = descriptor.getProjectData(LANGUAGE_MAPPING_ID);
+ clearChildren(rootElement);
+ addProjectMappings(config.getProjectMappings(), rootElement);
+ descriptor.saveProjectData();
+ }
+
+ private void clearChildren(Element element) {
+ Node child = element.getFirstChild();
+ while (child != null) {
+ element.removeChild(child);
+ child = element.getFirstChild();
+ }
+ }
+
+ private void addProjectMappings(Map mappings, Element rootElement) {
+ Document document = rootElement.getOwnerDocument();
+ Element projectMappings = document.createElement(PROJECT_MAPPINGS);
+ Iterator entries = mappings.entrySet().iterator();
+ while (entries.hasNext()) {
+ Entry entry = (Entry) entries.next();
+ Element mapping = document.createElement(PROJECT_MAPPING);
+ mapping.setAttribute(ATTRIBUTE_CONTENT_TYPE, (String) entry.getKey());
+ mapping.setAttribute(ATTRIBUTE_LANGUAGE, (String) entry.getValue());
+ projectMappings.appendChild(mapping);
+ }
+ rootElement.appendChild(projectMappings);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
index a80c59de790..a120ee6b002 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
@@ -683,10 +683,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
}
public ILanguage getLanguage() throws CoreException {
- if (language == null) {
- language = computeLanguage(contentTypeId);
- }
-
+ ILanguage language = LanguageManager.getInstance().getLanguageForFile(getFile());
return language;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java
index df65c4a96b9..37bb269c24c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java
@@ -235,12 +235,5 @@ public interface IASTTranslationUnit extends IASTNode {
* @param index
*/
public void setIndex(IIndex index);
-
- /**
- * Returns the language for this translation unit.
- *
- * @return language for this translation unit
- */
- public ILanguage getLanguage();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/Messages.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/Messages.java
new file mode 100644
index 00000000000..81988e7f238
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/Messages.java
@@ -0,0 +1,22 @@
+package org.eclipse.cdt.core.dom.ast.gnu;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+ private static final String BUNDLE_NAME = "org.eclipse.cdt.core.dom.ast.gnu.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ private Messages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java
index b9121f83ddc..0c21d886669 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java
@@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
+import org.eclipse.cdt.core.dom.ast.gnu.Messages;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.AbstractLanguage;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
@@ -65,6 +66,10 @@ public class GCCLanguage extends AbstractLanguage {
return ID;
}
+ public String getName() {
+ return new String(Messages.getString("GCCLanguage.name")); //$NON-NLS-1$
+ }
+
public Object getAdapter(Class adapter) {
if (adapter == IPDOMLinkageFactory.class)
return new PDOMCLinkageFactory();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java
index b7c3b102fda..9eae2d58025 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java
@@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.gnu.Messages;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.AbstractLanguage;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
@@ -64,6 +65,10 @@ public class GPPLanguage extends AbstractLanguage {
return ID;
}
+ public String getName() {
+ return new String(Messages.getString("GPPLanguage.name")); //$NON-NLS-1$
+ }
+
public Object getAdapter(Class adapter) {
if (adapter == IPDOMLinkageFactory.class)
return new PDOMCPPLinkageFactory();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/messages.properties b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/messages.properties
new file mode 100644
index 00000000000..3edab4464a0
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/messages.properties
@@ -0,0 +1,2 @@
+GPPLanguage.name=C++ for G++ compiler
+GCCLanguage.name=C for GCC compiler
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java
index 6c9084ee9b9..8ef0ac4a401 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java
@@ -43,6 +43,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
@@ -573,13 +574,9 @@ public class CASTTranslationUnit extends CASTNode implements
}
public ParserLanguage getParserLanguage() {
- return ParserLanguage.C;
+ return ParserLanguage.C;
}
- public ILanguage getLanguage() {
- // Assuming gnu C for now.
- return new GCCLanguage();
- }
public IIndex getIndex() {
return index;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
index de587c1d6cc..35fd26b535e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
@@ -57,6 +57,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
@@ -620,11 +621,6 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
return ParserLanguage.CPP;
}
- public ILanguage getLanguage() {
- // Assuming gnu C++ for now.
- return new GPPLanguage();
- }
-
public IIndex getIndex() {
return index;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java
index d4175881233..fb50dac0b58 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 QNX Software Systems and others.
+ * Copyright (c) 2006, 2007 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
@@ -76,10 +76,6 @@ class PDOMCLinkage extends PDOMLinkage {
public static final int CPARAMETER = PDOMLinkage.LAST_NODE_TYPE + 8;
public static final int CBASICTYPE = PDOMLinkage.LAST_NODE_TYPE + 9;
- public ILanguage getLanguage() {
- return new GCCLanguage();
- }
-
public PDOMBinding addBinding(IBinding binding) throws CoreException {
PDOMBinding pdomBinding = adaptBinding(binding);
try {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
index 149409ad688..fec234ea1cd 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
@@ -96,10 +96,6 @@ class PDOMCPPLinkage extends PDOMLinkage {
public static final int CPP_CONSTRUCTOR= PDOMLinkage.LAST_NODE_TYPE + 14;
public static final int CPP_REFERENCE_TYPE= PDOMLinkage.LAST_NODE_TYPE + 15;
- public ILanguage getLanguage() {
- return new GPPLanguage();
- }
-
public PDOMBinding addBinding(IASTName name) throws CoreException {
if (name == null || name instanceof ICPPASTQualifiedName)
return null;
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java
index 89b631a5671..d1e4a97a81e 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/ResolveBindingTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2007 Wind River Systems, Inc. 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
+ * IBM Corporation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.selection;
@@ -15,6 +16,7 @@ import junit.framework.Test;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.cdt.core.CCorePlugin;
@@ -27,6 +29,8 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
@@ -58,7 +62,17 @@ public class ResolveBindingTests extends BaseUITestCase {
}
private IASTName getSelectedName(IASTTranslationUnit astTU, int offset, int len) {
- IASTName[] names= astTU.getLanguage().getSelectedNames(astTU, offset, len);
+ // get the language from the language manager
+ ILanguage language = null;
+ try {
+ language = LanguageManager.getInstance().getLanguageForFile(astTU.getFilePath(), fCProject.getProject());
+ } catch (CoreException e) {
+ fail("Unexpected exception while getting language for file.");
+ }
+
+ assertNotNull("No language for file " + astTU.getFilePath().toString(), language);
+
+ IASTName[] names= language.getSelectedNames(astTU, offset, len);
assertEquals(1, names.length);
return names[0];
}
diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties
index 532d106057f..07425ad44ce 100644
--- a/core/org.eclipse.cdt.ui/plugin.properties
+++ b/core/org.eclipse.cdt.ui/plugin.properties
@@ -257,6 +257,8 @@ CDTHelpProperty.name=C/C++ Documentation
CDTFileTypesProperty.name=C/C++ File Types
+CDTLanguagesProperty.name=Language Mappings
+
cDocumentFactory=C Document Factory
cDocumentSetupParticipant=C Document Setup Participant
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index 174ebbf0a7c..858b334cd2f 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -1388,6 +1388,17 @@
</adapt>
</enabledWhen>
</page>
+ <page
+ adaptable="true"
+ class="org.eclipse.cdt.internal.ui.language.ProjectLanguageMappingPropertyPage"
+ id="org.eclipse.cdt.ui.projectLanguageMappings"
+ name="%CDTLanguagesProperty.name"
+ objectClass="org.eclipse.core.resources.IProject">
+ <filter
+ name="nature"
+ value="org.eclipse.cdt.core.cnature">
+ </filter>
+ </page>
</extension>
<extension
point="org.eclipse.cdt.ui.PathContainerPage">
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/ContentTypeMappingDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/ContentTypeMappingDialog.java
new file mode 100644
index 00000000000..158a37419f4
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/ContentTypeMappingDialog.java
@@ -0,0 +1,172 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.internal.ui.language;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.content.IContentTypeManager;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.model.LanguageManager;
+
+import org.eclipse.cdt.internal.ui.preferences.PreferencesMessages;
+
+public class ContentTypeMappingDialog extends Dialog {
+
+ Combo fContentType;
+ Combo fLanguage;
+ String fSelectedContentTypeName;
+ String fSelectedContentTypeID;
+ String fSelectedLanguageName;
+ String fSelectedLanguageID;
+ private Set fFilteredContentTypes;
+ private HashMap fContentTypeNamesToIDsMap;
+ private HashMap fLanguageNamesToIDsMap;
+
+ public ContentTypeMappingDialog(Shell parentShell) {
+ super(parentShell);
+ fFilteredContentTypes = Collections.EMPTY_SET;
+ fContentTypeNamesToIDsMap = new HashMap();
+ fLanguageNamesToIDsMap = new HashMap();
+ }
+
+ public String getSelectedContentTypeName() {
+ return fSelectedContentTypeName;
+ }
+
+ public String getContentTypeID() {
+ return fSelectedContentTypeID;
+ }
+
+ public String getSelectedLanguageName() {
+ return fSelectedLanguageName;
+ }
+
+ public String getLanguageID() {
+ return fSelectedLanguageID;
+ }
+
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText(PreferencesMessages.ContentTypeMappingsDialog_title);
+ }
+
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
+ true);
+ createButton(parent, IDialogConstants.CANCEL_ID,
+ IDialogConstants.CANCEL_LABEL, false);
+
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ }
+
+ private boolean isValidSelection() {
+ return fContentType.getSelectionIndex() != -1
+ && fLanguage.getSelectionIndex() != -1;
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite area = new Composite(parent, SWT.NONE);
+ area.setLayout(new GridLayout(2, false));
+
+ Label contentTypeLabel = new Label(area, SWT.TRAIL);
+ contentTypeLabel
+ .setText(PreferencesMessages.ContentTypeMappingsDialog_contentType);
+
+ fContentType = new Combo(area, SWT.DROP_DOWN | SWT.READ_ONLY);
+ fContentType
+ .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ configureContentTypes(fContentType);
+ fContentType.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ fSelectedContentTypeName = fContentType.getText();
+ fSelectedContentTypeID = (String) fContentTypeNamesToIDsMap
+ .get(fSelectedContentTypeName);
+ getButton(IDialogConstants.OK_ID)
+ .setEnabled(isValidSelection());
+ }
+ });
+
+ Label languageLabel = new Label(area, SWT.TRAIL);
+ languageLabel
+ .setText(PreferencesMessages.ContentTypeMappingsDialog_language);
+
+ fLanguage = new Combo(area, SWT.DROP_DOWN | SWT.READ_ONLY);
+ fLanguage.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ fLanguage.setItems(getLanguages());
+ fLanguage.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ fSelectedLanguageName = fLanguage.getText();
+ fSelectedLanguageID = (String) fLanguageNamesToIDsMap
+ .get(fSelectedLanguageName);
+ getButton(IDialogConstants.OK_ID)
+ .setEnabled(isValidSelection());
+ }
+ });
+
+ return area;
+ }
+
+ private void configureContentTypes(Combo combo) {
+ combo.removeAll();
+ String[] contentTypesIDs = LanguageManager.getInstance()
+ .getRegisteredContentTypeIds();
+
+ IContentTypeManager contentTypeManager = Platform
+ .getContentTypeManager();
+
+ for (int i = 0; i < contentTypesIDs.length; i++) {
+ if (!fFilteredContentTypes.contains(contentTypesIDs[i])) {
+
+ String name = contentTypeManager.getContentType(
+ contentTypesIDs[i]).getName();
+
+ combo.add(name);
+
+ // keep track of what ID this name corresponds to so that when
+ // we setup the mapping
+ // later based upon user selection, we'll know what ID to use
+ fContentTypeNamesToIDsMap.put(name, contentTypesIDs[i]);
+ }
+ }
+ }
+
+ private String[] getLanguages() {
+ ILanguage[] languages = LanguageManager.getInstance()
+ .getRegisteredLanguages();
+ String[] descriptions = new String[languages.length];
+ for (int i = 0; i < descriptions.length; i++) {
+ descriptions[i] = languages[i].getName();
+ fLanguageNamesToIDsMap.put(descriptions[i], languages[i].getId());
+ }
+ return descriptions;
+ }
+
+ public void setContentTypeFilter(Set contentTypes) {
+ fFilteredContentTypes = contentTypes;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/ProjectLanguageMappingPropertyPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/ProjectLanguageMappingPropertyPage.java
new file mode 100644
index 00000000000..9113d3abecf
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/ProjectLanguageMappingPropertyPage.java
@@ -0,0 +1,209 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation 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:
+ * IBM Corporation - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.language;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.content.IContentTypeManager;
+import org.eclipse.jface.layout.TableColumnAdapter;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.LanguageManager;
+
+import org.eclipse.cdt.internal.core.language.LanguageMappingConfiguration;
+
+import org.eclipse.cdt.internal.ui.preferences.PreferencesMessages;
+
+public class ProjectLanguageMappingPropertyPage extends PropertyPage {
+
+ private static final int MINIMUM_COLUMN_WIDTH = 150;
+ private LanguageMappingConfiguration fMappings;
+ private Table fTable;
+ private HashMap fContentTypeNamesToIDsMap;
+
+ public ProjectLanguageMappingPropertyPage() {
+ super();
+
+ // keep a mapping of all registered content types and their names
+ fContentTypeNamesToIDsMap = new HashMap();
+ String[] contentTypesIDs = LanguageManager.getInstance()
+ .getRegisteredContentTypeIds();
+
+ IContentTypeManager contentTypeManager = Platform
+ .getContentTypeManager();
+
+ for (int i = 0; i < contentTypesIDs.length; i++) {
+
+ String name = contentTypeManager.getContentType(contentTypesIDs[i])
+ .getName();
+
+ // keep track of what ID this name corresponds to so that when we
+ // setup the mapping
+ // later based upon user selection, we'll know what ID to use
+ fContentTypeNamesToIDsMap.put(name, contentTypesIDs[i]);
+
+ }
+ }
+
+ /**
+ * @see PreferencePage#createContents(Composite)
+ */
+ protected Control createContents(Composite parent) {
+ fetchMappings();
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite
+ .setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
+ composite.setLayout(new GridLayout(2, false));
+
+ Composite tableParent = new Composite(composite, SWT.NONE);
+ tableParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ tableParent.setLayout(new FillLayout());
+
+ fTable = new Table(tableParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
+ fTable.setHeaderVisible(true);
+ fTable.setLinesVisible(true);
+
+ TableColumn contentTypeColumn = new TableColumn(fTable, SWT.LEAD);
+ contentTypeColumn
+ .setText(PreferencesMessages.ProjectLanguagesPropertyPage_contentTypeColumn);
+
+ TableColumn languageColumn = new TableColumn(fTable, SWT.LEAD);
+ languageColumn
+ .setText(PreferencesMessages.ProjectLanguagesPropertyPage_languageColumn);
+
+ TableColumnAdapter columnAdapter = new TableColumnAdapter(fTable);
+ columnAdapter.addColumnData(new ColumnWeightData(1,
+ MINIMUM_COLUMN_WIDTH, true));
+ columnAdapter.addColumnData(new ColumnWeightData(1,
+ MINIMUM_COLUMN_WIDTH, true));
+ tableParent.addControlListener(columnAdapter);
+
+ Composite buttons = new Composite(composite, SWT.NONE);
+ buttons.setLayout(new GridLayout());
+ buttons.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false,
+ false));
+
+ Button addButton = new Button(buttons, SWT.PUSH);
+ addButton
+ .setText(PreferencesMessages.ProjectLanguagesPropertyPage_addMappingButton);
+ addButton.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ ContentTypeMappingDialog dialog = new ContentTypeMappingDialog(
+ getShell());
+ dialog.setContentTypeFilter(fMappings.getProjectMappings()
+ .keySet());
+ dialog.setBlockOnOpen(true);
+
+ if (dialog.open() == Window.OK) {
+ String contentType = dialog.getContentTypeID();
+ String language = dialog.getLanguageID();
+ fMappings.addProjectMapping(contentType, language);
+ refreshMappings();
+ }
+ }
+ });
+
+ Button removeButton = new Button(buttons, SWT.PUSH);
+ removeButton
+ .setText(PreferencesMessages.ProjectLanguagesPropertyPage_removeMappingButton);
+ removeButton.addListener(SWT.Selection, new Listener() {
+
+ public void handleEvent(Event event) {
+ TableItem[] selection = fTable.getSelection();
+
+ for (int i = 0; i < selection.length; i++) {
+ fMappings
+ .removeProjectMapping((String) fContentTypeNamesToIDsMap
+ .get(selection[i].getText(0)));
+ }
+
+ refreshMappings();
+ }
+ });
+
+ refreshMappings();
+ return composite;
+ }
+
+ private void refreshMappings() {
+ fTable.removeAll();
+ Iterator mappings = fMappings.getProjectMappings().entrySet()
+ .iterator();
+
+ IContentTypeManager contentTypeManager = Platform
+ .getContentTypeManager();
+
+ while (mappings.hasNext()) {
+ Entry entry = (Entry) mappings.next();
+
+ TableItem item = new TableItem(fTable, SWT.NONE);
+
+ String contentTypeName = contentTypeManager.getContentType(
+ (String) entry.getKey()).getName();
+ String languageName = LanguageManager.getInstance().getLanguage(
+ (String) entry.getValue()).getName();
+
+ item.setText(0, contentTypeName);
+ item.setText(1, languageName);
+ }
+ }
+
+ private void fetchMappings() {
+ try {
+ fMappings = LanguageManager.getInstance()
+ .getLanguageMappingConfiguration(getProject());
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ }
+ }
+
+ protected void performDefaults() {
+ fMappings = new LanguageMappingConfiguration();
+ }
+
+ public boolean performOk() {
+ try {
+ LanguageManager.getInstance().storeLanguageMappingConfiguration(
+ getProject());
+ return true;
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ return false;
+ }
+ }
+
+ private IProject getProject() {
+ return (IProject) getElement().getAdapter(IProject.class);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java
index 217f174e122..dcd3e12d4ec 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java
@@ -193,6 +193,15 @@ public final class PreferencesMessages extends NLS {
public static String CodeFormatterPreferencePage_title;
public static String CodeFormatterPreferencePage_description;
+ public static String ProjectLanguagesPropertyPage_contentTypeColumn;
+ public static String ProjectLanguagesPropertyPage_languageColumn;
+ public static String ProjectLanguagesPropertyPage_addMappingButton;
+ public static String ProjectLanguagesPropertyPage_removeMappingButton;
+
+ public static String ContentTypeMappingsDialog_title;
+ public static String ContentTypeMappingsDialog_contentType;
+ public static String ContentTypeMappingsDialog_language;
+
static {
NLS.initializeMessages(BUNDLE_NAME, PreferencesMessages.class);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties
index c6a45af57be..98c4c0fdf14 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties
@@ -227,5 +227,15 @@ PathEntryVariablesBlock_removeVariableButton = &Remove
#Indexer
IndexerPrefs_description=Sets default Indexer Options for new Projects
+# Language settings
+ProjectLanguagesPropertyPage_contentTypeColumn = Content Type
+ProjectLanguagesPropertyPage_languageColumn = Language
+ProjectLanguagesPropertyPage_addMappingButton = &Add...
+ProjectLanguagesPropertyPage_removeMappingButton = &Remove
+
+ContentTypeMappingsDialog_title = Add Mapping
+ContentTypeMappingsDialog_contentType = Content type
+ContentTypeMappingsDialog_language = Language
+
# Others
ProposalFilterPreferencesUtil_defaultFilterName=<Default Filter>

Back to the top