use of org.eclipse.cdt.core.model.ISourceRoot in project linuxtools by eclipse.
the class STLink2SourceSupport method getFileForPathImpl.
private static IFile getFileForPathImpl(IPath path, IProject project) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
if (path.isAbsolute()) {
return root.getFileForLocation(path);
}
if (project != null && project.exists()) {
ICProject cproject = CoreModel.getDefault().create(project);
if (cproject != null) {
try {
ISourceRoot[] roots = cproject.getAllSourceRoots();
for (ISourceRoot sourceRoot : roots) {
IContainer r = sourceRoot.getResource();
IResource res = r.findMember(path);
if (res != null && res.exists() && res instanceof IFile) {
return (IFile) res;
}
}
IOutputEntry[] entries = cproject.getOutputEntries();
for (IOutputEntry pathEntry : entries) {
IPath p = pathEntry.getPath();
IResource r = root.findMember(p);
if (r instanceof IContainer) {
IContainer parent = (IContainer) r;
IResource res = parent.findMember(path);
if (res != null && res.exists() && res instanceof IFile) {
return (IFile) res;
}
}
}
} catch (CModelException e) {
Activator.getDefault().getLog().log(e.getStatus());
}
}
}
// no match found...try and see if we are dealing with a link
IPath realPath = project.getLocation().append(path).makeAbsolute();
URI realURI = URIUtil.toURI(realPath.toString());
try {
FindLinkedResourceVisitor visitor = new STLink2SourceSupport.FindLinkedResourceVisitor(realURI);
project.accept(visitor, IResource.DEPTH_INFINITE);
// If we find a match, make note of the target and the real C project.
if (visitor.foundElement()) {
return (IFile) visitor.getResource();
}
} catch (CoreException e) {
}
return null;
}
Aggregations