1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fixed NPE.

This commit is contained in:
Sergey Prigogin 2011-02-28 01:53:06 +00:00
parent 62c3a2bf32
commit 86f5038595
2 changed files with 45 additions and 48 deletions

View file

@ -1,13 +1,14 @@
/*******************************************************************************
* Copyright (c) 2007, 2011 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
* Copyright (c) 2007, 2011 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
* James Blackburn (Broadcom Corp.)
* Contributors:
* IBM Corporation - Initial API and implementation
* James Blackburn (Broadcom Corp.)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.language;
@ -53,21 +54,13 @@ import org.xml.sax.SAXException;
*/
public class LanguageMappingStore {
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 WORKSPACE_MAPPINGS = "workspace-mappings"; //$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 ATTRIBUTE_PATH = "path"; //$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_CONFIGURATION = "configuration"; //$NON-NLS-1$
public LanguageMappingStore() {
@ -76,16 +69,16 @@ public class LanguageMappingStore {
public ProjectLanguageConfiguration decodeMappings(IProject project) throws CoreException {
ProjectLanguageConfiguration config = new ProjectLanguageConfiguration();
ICProjectDescription descriptor = getProjectDescription(project, false);
ICStorageElement rootElement = descriptor.getStorage(LANGUAGE_MAPPING_ID, false);
if (rootElement == null) {
return config;
}
ICStorageElement[] mappingElements = rootElement.getChildrenByName(PROJECT_MAPPINGS);
if (mappingElements.length > 0) {
ICStorageElement element = mappingElements[0];
config.setContentTypeMappings(decodeProjectContentTypeMappings(element));
config.setFileMappings(decodeFileMappings(element));
if (descriptor != null) {
ICStorageElement rootElement = descriptor.getStorage(LANGUAGE_MAPPING_ID, false);
if (rootElement != null) {
ICStorageElement[] mappingElements = rootElement.getChildrenByName(PROJECT_MAPPINGS);
if (mappingElements.length > 0) {
ICStorageElement element = mappingElements[0];
config.setContentTypeMappings(decodeProjectContentTypeMappings(element));
config.setFileMappings(decodeFileMappings(element));
}
}
}
return config;
}
@ -195,7 +188,7 @@ public class LanguageMappingStore {
serializer.transform(source, result);
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.flush();
} catch (ParserConfigurationException e) {
@ -208,8 +201,8 @@ public class LanguageMappingStore {
}
public WorkspaceLanguageConfiguration decodeWorkspaceMappings() throws CoreException {
IEclipsePreferences node = new InstanceScope().getNode(CCorePlugin.PLUGIN_ID);
IEclipsePreferences defaultNode = new DefaultScope().getNode(CCorePlugin.PLUGIN_ID);
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
IEclipsePreferences defaultNode = DefaultScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
String encodedMappings = defaultNode.get(CCorePreferenceConstants.WORKSPACE_LANGUAGE_MAPPINGS, null);
if (encodedMappings == 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();
Iterator<Entry<String, String>> entries = mappings.entrySet().iterator();
while (entries.hasNext()) {

View file

@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Andrew Ferguson (Symbian) - Initial implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.doctools;
@ -72,13 +73,13 @@ class ProjectMap {
*/
public String getOwnerID(IResource resource) {
String id= null;
if(resource!=null) {
for(IPath p= resource.getProjectRelativePath(); ; p= p.removeLastSegments(1)) {
if(fMap.containsKey(p)) {
if (resource != null) {
for (IPath p= resource.getProjectRelativePath(); ; p= p.removeLastSegments(1)) {
if (fMap.containsKey(p)) {
id= fMap.get(p);
break;
}
if(p.isEmpty())
if (p.isEmpty())
break;
}
}
@ -94,9 +95,9 @@ class ProjectMap {
*/
public void setCommentOwner(IResource resource, IDocCommentOwner owner) {
Assert.isNotNull(resource);
if(ResourcesPlugin.getWorkspace().getRoot().equals(resource))
if (ResourcesPlugin.getWorkspace().getRoot().equals(resource))
throw new IllegalStateException();
if(owner!=null) {
if (owner != null) {
fMap.put(resource.getProjectRelativePath(), owner.getID());
} else {
fMap.remove(resource.getProjectRelativePath());
@ -115,15 +116,17 @@ class ProjectMap {
private static Map<IPath, String> load(IProject project) throws CoreException {
Map<IPath, String> result= new HashMap<IPath, String>();
ICProjectDescription pd= CCorePlugin.getDefault().getProjectDescription(project, false);
ICStorageElement e = pd.getStorage(ATTRVAL_STORAGEID, false);
if (e != null) {
for (ICStorageElement node : e.getChildrenByName(ELEMENT_DOC_COMMENT_OWNER)) {
String commentOwnerID = node.getAttribute(ATTRKEY_DCO_ID);
if(commentOwnerID != null) {
for (ICStorageElement path : node.getChildrenByName(ELEMENT_PATH)) {
String pathValue= path.getAttribute(ATTRKEY_PATH_VALUE);
if(pathValue != null) {
result.put(Path.fromPortableString(pathValue), commentOwnerID);
if (pd != null) {
ICStorageElement element = pd.getStorage(ATTRVAL_STORAGEID, false);
if (element != null) {
for (ICStorageElement node : element.getChildrenByName(ELEMENT_DOC_COMMENT_OWNER)) {
String commentOwnerID = node.getAttribute(ATTRKEY_DCO_ID);
if (commentOwnerID != null) {
for (ICStorageElement path : node.getChildrenByName(ELEMENT_PATH)) {
String pathValue= path.getAttribute(ATTRKEY_PATH_VALUE);
if(pathValue != null) {
result.put(Path.fromPortableString(pathValue), commentOwnerID);
}
}
}
}
@ -144,11 +147,11 @@ class ProjectMap {
data.removeChild(child);
// 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();
ICStorageElement commentNode = data.createChild(ELEMENT_DOC_COMMENT_OWNER);
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();
String ccid= fMap.get(path);
if(cid.equals(ccid)) {