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

getFileForLocation() does not work well when dealing

with resources. use findFilesForLocation().
This commit is contained in:
Alain Magloire 2003-10-28 19:59:17 +00:00
parent f4b6b6e53e
commit 47c2045527

View file

@ -20,6 +20,7 @@ import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
@ -208,6 +209,28 @@ public class ErrorParserManager extends OutputStream {
return (IFile) fFilesInProject.get(path.lastSegment()); return (IFile) fFilesInProject.get(path.lastSegment());
} }
protected IFile findFileInWorkspace(IPath path) {
IFile file = null;
if (path.isAbsolute()) {
IWorkspaceRoot root = fProject.getWorkspace().getRoot();
file = root.getFileForLocation(path);
// It may be a link resource so we must check it also.
if (file == null) {
IFile[] files = root.findFilesForLocation(path);
for (int i = 0; i < files.length; i++) {
if (files[i].getProject().equals(fProject)) {
file = files[i];
break;
}
}
}
} else {
file = fProject.getFile(path);
}
return file;
}
/** /**
* Called by the error parsers. * Called by the error parsers.
*/ */
@ -235,9 +258,9 @@ public class ErrorParserManager extends OutputStream {
IFile file = null; IFile file = null;
// The workspace may throw an IllegalArgumentException // The workspace may throw an IllegalArgumentException
// Catch it and the parser will fallback to scan the entire project. // Catch it and the parser should fallback to scan the entire project.
try { try {
file = (path.isAbsolute()) ? fProject.getWorkspace().getRoot().getFileForLocation(path) : fProject.getFile(path); file = findFileInWorkspace(path);
} catch (Exception e) { } catch (Exception e) {
} }
@ -248,11 +271,9 @@ public class ErrorParserManager extends OutputStream {
try { try {
String canon = f.getCanonicalPath(); String canon = f.getCanonicalPath();
path = new Path(canon); path = new Path(canon);
file = (path.isAbsolute()) ? fProject.getWorkspace().getRoot().getFileForLocation(path) : fProject.getFile(path); file = findFileInWorkspace(path);
} catch (IOException e1) { } catch (IOException e1) {
} }
} else {
return file;
} }
return (file != null && file.exists()) ? file : null; return (file != null && file.exists()) ? file : null;
} }