From 7028cddf94514c156a20c07bdc1f12319cf7347e Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Tue, 27 Feb 2007 08:54:51 +0000 Subject: [PATCH] generalize ProjectRelativeLocationConverter --- .../index/tests/IndexLocationTest.java | 16 +++---- ...ceContainerRelativeLocationConverter.java} | 46 +++++++++---------- .../index/URIRelativeLocationConverter.java | 2 +- 3 files changed, 31 insertions(+), 33 deletions(-) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/{ProjectRelativeLocationConverter.java => ResourceContainerRelativeLocationConverter.java} (67%) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java index 6f69a5b3fc8..d777e5cf43c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java @@ -26,7 +26,7 @@ import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.index.IndexLocationFactory; -import org.eclipse.cdt.core.index.ProjectRelativeLocationConverter; +import org.eclipse.cdt.core.index.ResourceContainerRelativeLocationConverter; import org.eclipse.cdt.core.index.URIRelativeLocationConverter; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; @@ -157,15 +157,15 @@ public class IndexLocationTest extends BaseTestCase { } } - public void testProjectRelativeLocationConverter() throws Exception { + public void testResourceContainerRelativeLocationConverter() throws Exception { String[] paths = new String[] {"this.cpp", "inc/header.h", "a b c/d/e f/g.h", "a \\b /c.d"}; for(int i=0; i * This location converter is internal-representation-compatible with URIRelativeLocationConverter */ /* - * Internal representation is project relative path + * Internal representation is a relative path */ -public class ProjectRelativeLocationConverter implements IIndexLocationConverter { +public class ResourceContainerRelativeLocationConverter implements IIndexLocationConverter { protected IWorkspaceRoot root; - protected String cprojectName; + protected IPath fullPath; /** - * @param cproject the CDT project to convert relative to + * @param container the resource container to convert relative to */ - public ProjectRelativeLocationConverter(ICProject cproject) { - this.cprojectName = cproject.getProject().getName(); + public ResourceContainerRelativeLocationConverter(IContainer container) { + this.fullPath = container.getFullPath(); this.root = ResourcesPlugin.getWorkspace().getRoot(); - } - + } /* * (non-Javadoc) * @see org.eclipse.cdt.core.index.IIndexLocationConverter#fromInternalFormat(java.lang.String) */ public IIndexFileLocation fromInternalFormat(String raw) { - IResource member= root.getFile(new Path(cprojectName +"/"+ raw)); //$NON-NLS-1$ + IResource member= root.getFile(fullPath.append(raw)); return new IndexFileLocation(member.getLocationURI(), member.getFullPath().toString()); - } - + } /* * (non-Javadoc) * @see org.eclipse.cdt.core.index.IIndexLocationConverter#toInternalFormat(org.eclipse.cdt.core.index.IIndexFileLocation) */ public String toInternalFormat(IIndexFileLocation location) { - String fullPath= location.getFullPath(); - if(fullPath!=null) { - IPath path = new Path(fullPath).removeFirstSegments(1); - return path.toString(); + String sFullPath= location.getFullPath(); + if(sFullPath!=null) { + IPath path= new Path(sFullPath); + if(fullPath.isPrefixOf(path)) { + return path.removeFirstSegments(fullPath.segmentCount()).toString(); + } } return null; } -} +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/URIRelativeLocationConverter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/URIRelativeLocationConverter.java index eb0edd3849f..c45e16dab10 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/URIRelativeLocationConverter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/URIRelativeLocationConverter.java @@ -19,7 +19,7 @@ import org.eclipse.core.filesystem.URIUtil; * A IIndexLocationConverter for converting relative paths within an index, by prefixing them * with the supplied base URI *
- * This location converter is internal-representation-compatible with ProjectRelativeLocationConverter + * This location converter is internal-representation-compatible with ResourceContainerRelativeLocationConverter */ /* * Internal representation is uri relative path (non encoded form)