1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 09:16:02 +02:00

Fix for 193088 by Gerhard Schaber, NPE using workspace-root as include entry.

This commit is contained in:
Markus Schorn 2007-06-18 13:34:12 +00:00
parent e9f535bcfa
commit 2912b67a36
2 changed files with 14 additions and 9 deletions

View file

@ -402,26 +402,28 @@ public class CCommandDSC {
} }
private static IResource findResource(IProject project, IPath path) { private static IResource findResource(IProject project, IPath path) {
IResource resource = project.findMember(path, true); IResource resource = project.findMember(path, false);
if (resource == null) { if (resource == null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
resource = root.findMember(path, true); resource = root.findMember(path, false);
if (resource == null) { if (resource == null) {
IResource[] resources = root.findFilesForLocation(path); IResource[] resources = root.findFilesForLocation(path);
if (resources != null) { if (project != null) {
for (int i = 0; i < resources.length; i++) { for (int i = 0; i < resources.length; i++) {
if (resources[i].getProject() == project) { final IProject myProject = resources[i].getProject();
// resource could be root, then myProject is null.
if (myProject != null && myProject.equals(project)) {
resource = resources[i]; resource = resources[i];
break; break;
} }
} }
}
// make a relative path to another project (better than an absolute path) // make a relative path to another project (better than an absolute path)
if (resource == null && resources.length > 0) { if (resource == null && resources.length > 0) {
resource = resources[0]; resource = resources[0];
} }
} }
} }
}
return resource; return resource;
} }

View file

@ -13,6 +13,7 @@
package org.eclipse.cdt.internal.ui.cview; package org.eclipse.cdt.internal.ui.cview;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
@ -52,7 +53,9 @@ public class CViewLabelProvider extends AppearanceAwareLabelProvider {
if (prj != null) { if (prj != null) {
for (int i = 0; i < containers.length; i++) { for (int i = 0; i < containers.length; i++) {
final IContainer container = containers[i]; final IContainer container = containers[i];
if (container.getProject().equals(prj.getProject())) { final IProject project = container.getProject();
// in case the path is empty, the container is the workspace root and project is null.
if (project != null && project.equals(prj.getProject())) {
return container.getFullPath().makeRelative().toString(); return container.getFullPath().makeRelative().toString();
} }
} }