mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 04:45:38 +02:00
Fix for 179098: Make LanguageMappingConfiguration API
This commit is contained in:
parent
86e275f960
commit
6aa3d375f2
6 changed files with 88 additions and 49 deletions
|
@ -24,6 +24,7 @@ Export-Package: org.eclipse.cdt.core,
|
|||
org.eclipse.cdt.core.index,
|
||||
org.eclipse.cdt.core.index.export,
|
||||
org.eclipse.cdt.core.index.provider,
|
||||
org.eclipse.cdt.core.language,
|
||||
org.eclipse.cdt.core.model,
|
||||
org.eclipse.cdt.core.model.util,
|
||||
org.eclipse.cdt.core.parser,
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.language;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* Provides programmatic access to language mappings for a project.
|
||||
*
|
||||
* <p>
|
||||
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
|
||||
* part of a work in progress. There is no guarantee that this API will work or
|
||||
* that it will remain the same. Please do not use this API without consulting
|
||||
* with the CDT team.
|
||||
* </p>
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class LanguageMappingConfiguration {
|
||||
|
||||
/**
|
||||
* Project-wide mappings.
|
||||
*/
|
||||
private Map fProjectMappings;
|
||||
|
||||
/**
|
||||
* Creates a new <code>LanguageMappingConfiguration</code> with no
|
||||
* mappings defined.
|
||||
*/
|
||||
public LanguageMappingConfiguration() {
|
||||
fProjectMappings = new TreeMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a read-only copy of the project-wide language mappings.
|
||||
* @return a read-only copy of the project-wide language mappings.
|
||||
*/
|
||||
public Map getProjectMappings() {
|
||||
return Collections.unmodifiableMap(fProjectMappings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the existing language mappings with the given
|
||||
* mappings. The given mappings should be between content type ids
|
||||
* (<code>String</code>) and language ids (<code>String</code>)
|
||||
* @param projectMappings
|
||||
*/
|
||||
public void setProjectMappings(Map/*<String, String>*/ projectMappings) {
|
||||
fProjectMappings = new TreeMap(projectMappings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a content type id to a language id.
|
||||
* @param contentType
|
||||
* @param language
|
||||
*/
|
||||
public void addProjectMapping(String contentType, String language) {
|
||||
fProjectMappings.put(contentType, language);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given content type mapping (if it exists).
|
||||
* @param contentType
|
||||
*/
|
||||
public void removeProjectMapping(String contentType) {
|
||||
fProjectMappings.remove(contentType);
|
||||
}
|
||||
}
|
|
@ -22,8 +22,8 @@ import java.util.Set;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.language.LanguageMappingConfiguration;
|
||||
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.LanguageDescriptor;
|
||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
|
@ -385,7 +385,7 @@ public class LanguageManager {
|
|||
*/
|
||||
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)");
|
||||
throw new IllegalArgumentException("project must not be null in call to LanguageManager.getLanguageForFile(String, IProject)"); //$NON-NLS-1$
|
||||
|
||||
IContentType contentType = CContentTypes.getContentType(project, fullPathToFile);
|
||||
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -17,6 +17,7 @@ import java.util.Map.Entry;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ICDescriptor;
|
||||
import org.eclipse.cdt.core.language.LanguageMappingConfiguration;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.w3c.dom.Document;
|
||||
|
@ -25,15 +26,15 @@ 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 LANGUAGE_MAPPING_ID = "org.eclipse.cdt.core.language.mapping"; //$NON-NLS-1$
|
||||
|
||||
private static final String PROJECT_MAPPINGS = "project-mappings";
|
||||
private static final String PROJECT_MAPPINGS = "project-mappings"; //$NON-NLS-1$
|
||||
|
||||
private static final String PROJECT_MAPPING = "project-mapping";
|
||||
private static final String PROJECT_MAPPING = "project-mapping"; //$NON-NLS-1$
|
||||
|
||||
private static final String ATTRIBUTE_CONTENT_TYPE = "content-type";
|
||||
private static final String ATTRIBUTE_CONTENT_TYPE = "content-type"; //$NON-NLS-1$
|
||||
|
||||
private static final String ATTRIBUTE_LANGUAGE = "language";
|
||||
private static final String ATTRIBUTE_LANGUAGE = "language"; //$NON-NLS-1$
|
||||
|
||||
private IProject fProject;
|
||||
|
||||
|
|
|
@ -36,9 +36,9 @@ import org.eclipse.swt.widgets.TableItem;
|
|||
import org.eclipse.ui.dialogs.PropertyPage;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.language.LanguageMappingConfiguration;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
|
||||
import org.eclipse.cdt.internal.core.language.LanguageMappingConfiguration;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.preferences.PreferencesMessages;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue