mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixed NPE.
This commit is contained in:
parent
62c3a2bf32
commit
86f5038595
2 changed files with 45 additions and 48 deletions
|
@ -1,13 +1,14 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007, 2011 IBM Corporation and others.
|
* Copyright (c) 2007, 2011 IBM Corporation 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:
|
||||||
* IBM Corporation - Initial API and implementation
|
* IBM Corporation - Initial API and implementation
|
||||||
* James Blackburn (Broadcom Corp.)
|
* James Blackburn (Broadcom Corp.)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.language;
|
package org.eclipse.cdt.internal.core.language;
|
||||||
|
|
||||||
|
@ -53,21 +54,13 @@ import org.xml.sax.SAXException;
|
||||||
*/
|
*/
|
||||||
public class LanguageMappingStore {
|
public class LanguageMappingStore {
|
||||||
private static final String LANGUAGE_MAPPING_ID = "org.eclipse.cdt.core.language.mapping"; //$NON-NLS-1$
|
private static final String LANGUAGE_MAPPING_ID = "org.eclipse.cdt.core.language.mapping"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String PROJECT_MAPPINGS = "project-mappings"; //$NON-NLS-1$
|
private static final String PROJECT_MAPPINGS = "project-mappings"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String WORKSPACE_MAPPINGS = "workspace-mappings"; //$NON-NLS-1$
|
private static final String WORKSPACE_MAPPINGS = "workspace-mappings"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String CONTENT_TYPE_MAPPING = "content-type-mapping"; //$NON-NLS-1$
|
private static final String CONTENT_TYPE_MAPPING = "content-type-mapping"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String FILE_MAPPING = "file-mapping"; //$NON-NLS-1$
|
private static final String FILE_MAPPING = "file-mapping"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String ATTRIBUTE_PATH = "path"; //$NON-NLS-1$
|
private static final String ATTRIBUTE_PATH = "path"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String ATTRIBUTE_CONTENT_TYPE = "content-type"; //$NON-NLS-1$
|
private static final String ATTRIBUTE_CONTENT_TYPE = "content-type"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String ATTRIBUTE_LANGUAGE = "language"; //$NON-NLS-1$
|
private static final String ATTRIBUTE_LANGUAGE = "language"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String ATTRIBUTE_CONFIGURATION = "configuration"; //$NON-NLS-1$
|
private static final String ATTRIBUTE_CONFIGURATION = "configuration"; //$NON-NLS-1$
|
||||||
|
|
||||||
public LanguageMappingStore() {
|
public LanguageMappingStore() {
|
||||||
|
@ -76,16 +69,16 @@ public class LanguageMappingStore {
|
||||||
public ProjectLanguageConfiguration decodeMappings(IProject project) throws CoreException {
|
public ProjectLanguageConfiguration decodeMappings(IProject project) throws CoreException {
|
||||||
ProjectLanguageConfiguration config = new ProjectLanguageConfiguration();
|
ProjectLanguageConfiguration config = new ProjectLanguageConfiguration();
|
||||||
ICProjectDescription descriptor = getProjectDescription(project, false);
|
ICProjectDescription descriptor = getProjectDescription(project, false);
|
||||||
ICStorageElement rootElement = descriptor.getStorage(LANGUAGE_MAPPING_ID, false);
|
if (descriptor != null) {
|
||||||
if (rootElement == null) {
|
ICStorageElement rootElement = descriptor.getStorage(LANGUAGE_MAPPING_ID, false);
|
||||||
return config;
|
if (rootElement != null) {
|
||||||
}
|
ICStorageElement[] mappingElements = rootElement.getChildrenByName(PROJECT_MAPPINGS);
|
||||||
|
if (mappingElements.length > 0) {
|
||||||
ICStorageElement[] mappingElements = rootElement.getChildrenByName(PROJECT_MAPPINGS);
|
ICStorageElement element = mappingElements[0];
|
||||||
if (mappingElements.length > 0) {
|
config.setContentTypeMappings(decodeProjectContentTypeMappings(element));
|
||||||
ICStorageElement element = mappingElements[0];
|
config.setFileMappings(decodeFileMappings(element));
|
||||||
config.setContentTypeMappings(decodeProjectContentTypeMappings(element));
|
}
|
||||||
config.setFileMappings(decodeFileMappings(element));
|
}
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
@ -195,7 +188,7 @@ public class LanguageMappingStore {
|
||||||
serializer.transform(source, result);
|
serializer.transform(source, result);
|
||||||
String encodedMappings = buffer.getBuffer().toString();
|
String encodedMappings = buffer.getBuffer().toString();
|
||||||
|
|
||||||
IEclipsePreferences node = new InstanceScope().getNode(CCorePlugin.PLUGIN_ID);
|
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
|
||||||
node.put(CCorePreferenceConstants.WORKSPACE_LANGUAGE_MAPPINGS, encodedMappings);
|
node.put(CCorePreferenceConstants.WORKSPACE_LANGUAGE_MAPPINGS, encodedMappings);
|
||||||
node.flush();
|
node.flush();
|
||||||
} catch (ParserConfigurationException e) {
|
} catch (ParserConfigurationException e) {
|
||||||
|
@ -208,8 +201,8 @@ public class LanguageMappingStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorkspaceLanguageConfiguration decodeWorkspaceMappings() throws CoreException {
|
public WorkspaceLanguageConfiguration decodeWorkspaceMappings() throws CoreException {
|
||||||
IEclipsePreferences node = new InstanceScope().getNode(CCorePlugin.PLUGIN_ID);
|
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
|
||||||
IEclipsePreferences defaultNode = new DefaultScope().getNode(CCorePlugin.PLUGIN_ID);
|
IEclipsePreferences defaultNode = DefaultScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
|
||||||
String encodedMappings = defaultNode.get(CCorePreferenceConstants.WORKSPACE_LANGUAGE_MAPPINGS, null);
|
String encodedMappings = defaultNode.get(CCorePreferenceConstants.WORKSPACE_LANGUAGE_MAPPINGS, null);
|
||||||
if (encodedMappings == null) {
|
if (encodedMappings == null) {
|
||||||
encodedMappings = node.get(CCorePreferenceConstants.WORKSPACE_LANGUAGE_MAPPINGS, null);
|
encodedMappings = node.get(CCorePreferenceConstants.WORKSPACE_LANGUAGE_MAPPINGS, null);
|
||||||
|
@ -245,7 +238,8 @@ public class LanguageMappingStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMappings(Map<String, String> mappings, Element rootElement, String category, String keyName, String valueName) {
|
private void addMappings(Map<String, String> mappings, Element rootElement, String category,
|
||||||
|
String keyName, String valueName) {
|
||||||
Document document = rootElement.getOwnerDocument();
|
Document document = rootElement.getOwnerDocument();
|
||||||
Iterator<Entry<String, String>> entries = mappings.entrySet().iterator();
|
Iterator<Entry<String, String>> entries = mappings.entrySet().iterator();
|
||||||
while (entries.hasNext()) {
|
while (entries.hasNext()) {
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Andrew Ferguson (Symbian) - Initial implementation
|
* Andrew Ferguson (Symbian) - Initial implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.text.doctools;
|
package org.eclipse.cdt.internal.ui.text.doctools;
|
||||||
|
|
||||||
|
@ -72,13 +73,13 @@ class ProjectMap {
|
||||||
*/
|
*/
|
||||||
public String getOwnerID(IResource resource) {
|
public String getOwnerID(IResource resource) {
|
||||||
String id= null;
|
String id= null;
|
||||||
if(resource!=null) {
|
if (resource != null) {
|
||||||
for(IPath p= resource.getProjectRelativePath(); ; p= p.removeLastSegments(1)) {
|
for (IPath p= resource.getProjectRelativePath(); ; p= p.removeLastSegments(1)) {
|
||||||
if(fMap.containsKey(p)) {
|
if (fMap.containsKey(p)) {
|
||||||
id= fMap.get(p);
|
id= fMap.get(p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(p.isEmpty())
|
if (p.isEmpty())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,9 +95,9 @@ class ProjectMap {
|
||||||
*/
|
*/
|
||||||
public void setCommentOwner(IResource resource, IDocCommentOwner owner) {
|
public void setCommentOwner(IResource resource, IDocCommentOwner owner) {
|
||||||
Assert.isNotNull(resource);
|
Assert.isNotNull(resource);
|
||||||
if(ResourcesPlugin.getWorkspace().getRoot().equals(resource))
|
if (ResourcesPlugin.getWorkspace().getRoot().equals(resource))
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
if(owner!=null) {
|
if (owner != null) {
|
||||||
fMap.put(resource.getProjectRelativePath(), owner.getID());
|
fMap.put(resource.getProjectRelativePath(), owner.getID());
|
||||||
} else {
|
} else {
|
||||||
fMap.remove(resource.getProjectRelativePath());
|
fMap.remove(resource.getProjectRelativePath());
|
||||||
|
@ -115,15 +116,17 @@ class ProjectMap {
|
||||||
private static Map<IPath, String> load(IProject project) throws CoreException {
|
private static Map<IPath, String> load(IProject project) throws CoreException {
|
||||||
Map<IPath, String> result= new HashMap<IPath, String>();
|
Map<IPath, String> result= new HashMap<IPath, String>();
|
||||||
ICProjectDescription pd= CCorePlugin.getDefault().getProjectDescription(project, false);
|
ICProjectDescription pd= CCorePlugin.getDefault().getProjectDescription(project, false);
|
||||||
ICStorageElement e = pd.getStorage(ATTRVAL_STORAGEID, false);
|
if (pd != null) {
|
||||||
if (e != null) {
|
ICStorageElement element = pd.getStorage(ATTRVAL_STORAGEID, false);
|
||||||
for (ICStorageElement node : e.getChildrenByName(ELEMENT_DOC_COMMENT_OWNER)) {
|
if (element != null) {
|
||||||
String commentOwnerID = node.getAttribute(ATTRKEY_DCO_ID);
|
for (ICStorageElement node : element.getChildrenByName(ELEMENT_DOC_COMMENT_OWNER)) {
|
||||||
if(commentOwnerID != null) {
|
String commentOwnerID = node.getAttribute(ATTRKEY_DCO_ID);
|
||||||
for (ICStorageElement path : node.getChildrenByName(ELEMENT_PATH)) {
|
if (commentOwnerID != null) {
|
||||||
String pathValue= path.getAttribute(ATTRKEY_PATH_VALUE);
|
for (ICStorageElement path : node.getChildrenByName(ELEMENT_PATH)) {
|
||||||
if(pathValue != null) {
|
String pathValue= path.getAttribute(ATTRKEY_PATH_VALUE);
|
||||||
result.put(Path.fromPortableString(pathValue), commentOwnerID);
|
if(pathValue != null) {
|
||||||
|
result.put(Path.fromPortableString(pathValue), commentOwnerID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,11 +147,11 @@ class ProjectMap {
|
||||||
data.removeChild(child);
|
data.removeChild(child);
|
||||||
|
|
||||||
// invert and persist associations
|
// invert and persist associations
|
||||||
for(Iterator<String> i= fMap.values().iterator(); i.hasNext();) {
|
for (Iterator<String> i= fMap.values().iterator(); i.hasNext();) {
|
||||||
String cid= i.next();
|
String cid= i.next();
|
||||||
ICStorageElement commentNode = data.createChild(ELEMENT_DOC_COMMENT_OWNER);
|
ICStorageElement commentNode = data.createChild(ELEMENT_DOC_COMMENT_OWNER);
|
||||||
commentNode.setAttribute(ATTRKEY_DCO_ID, cid);
|
commentNode.setAttribute(ATTRKEY_DCO_ID, cid);
|
||||||
for(Iterator<IPath> j= fMap.keySet().iterator(); j.hasNext(); ) {
|
for (Iterator<IPath> j= fMap.keySet().iterator(); j.hasNext(); ) {
|
||||||
IPath path= j.next();
|
IPath path= j.next();
|
||||||
String ccid= fMap.get(path);
|
String ccid= fMap.get(path);
|
||||||
if(cid.equals(ccid)) {
|
if(cid.equals(ccid)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue