From 00a246114022d2a457623716d855b633f687c658 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 10 Sep 2008 22:40:19 +0000 Subject: [PATCH] Bug 108489. --- .../eclipse/cdt/core/ErrorParserManager.java | 71 +++++++++---------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java index 2664f950c5c..ea3419f6d33 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java @@ -31,6 +31,7 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceProxy; import org.eclipse.core.resources.IResourceProxyVisitor; import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -211,7 +212,7 @@ public class ErrorParserManager extends OutputStream { parserIDs[i] = items.next(); } - for (int i = 0; i = 0); } /** * Returns the project file with the given name if that file can be uniquely identified. * Otherwise returns null. */ - public IFile findFileName(String fileName) { + public IFile findFileName(String fileName) { IPath path = new Path(fileName); Object obj = fFilesInProject.get(path.lastSegment()); - if (obj == null || obj instanceof IFile) { - return (IFile) obj; + if (obj == null) { + return null; } - Collection files = (Collection) obj; - IFile matchingFile = null; - for (Object name : files) { - IFile file = (IFile) name; - IPath location = file.getLocation(); - boolean match = false; - if (path.isAbsolute()) { - match = path.equals(location); - } else { - int prefixLen = location.segmentCount() - path.segmentCount(); - match = prefixLen >= 0 && location.removeFirstSegments(prefixLen).equals(path); + if (obj instanceof IFile) { + IFile file = (IFile) obj; + if (isPossibleMatch(path, file.getLocation())) { + return file; } - if (match) { + return null; + } + IFile matchingFile = null; + @SuppressWarnings("unchecked") + Collection files = (Collection) obj; + for (IFile file : files) { + if (isPossibleMatch(path, file.getLocation())) { if (matchingFile != null) { return null; // Ambiguous match } @@ -275,6 +253,23 @@ public class ErrorParserManager extends OutputStream { return matchingFile; } + /** + * Checks if a file system path {@code location} may point to the same + * file as an absolute file system path {@code absoluteLocation}. + * @param location an absolute or relative file system path. + * @param absoluteLocation an absolute file system path. + * @return {@code true} if + */ + private boolean isPossibleMatch(IPath location, IPath absoluteLocation) { + Assert.isLegal(absoluteLocation.isAbsolute()); + if (location.isAbsolute()) { + return location.equals(absoluteLocation); + } else { + int prefixLen = absoluteLocation.segmentCount() - location.segmentCount(); + return prefixLen >= 0 && absoluteLocation.removeFirstSegments(prefixLen).equals(location); + } + } + protected IFile findFileInWorkspace(IPath path) { IFile file = null; if (path.isAbsolute()) {