Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Ferguson2007-02-27 08:54:51 +0000
committerAndrew Ferguson2007-02-27 08:54:51 +0000
commit7028cddf94514c156a20c07bdc1f12319cf7347e (patch)
treef71ef0a26d1d1540bad5d791ab0fa92d7a2e528c
parent30d2f050b446f84a27485f0dffca1de16939b6fe (diff)
downloadorg.eclipse.cdt-7028cddf94514c156a20c07bdc1f12319cf7347e.tar.gz
org.eclipse.cdt-7028cddf94514c156a20c07bdc1f12319cf7347e.tar.xz
org.eclipse.cdt-7028cddf94514c156a20c07bdc1f12319cf7347e.zip
generalize ProjectRelativeLocationConverter
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java16
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/ResourceContainerRelativeLocationConverter.java (renamed from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/ProjectRelativeLocationConverter.java)46
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/URIRelativeLocationConverter.java2
3 files changed, 31 insertions, 33 deletions
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<paths.length; i++) {
IFile file= cproject.getProject().getFile(paths[i]);
IIndexFileLocation ifl1= IndexLocationFactory.getWorkspaceIFL(file);
- ProjectRelativeLocationConverter prlc1= new ProjectRelativeLocationConverter(cproject);
+ ResourceContainerRelativeLocationConverter prlc1= new ResourceContainerRelativeLocationConverter(cproject.getProject());
String r1= prlc1.toInternalFormat(ifl1);
assertNotNull(r1);
- ProjectRelativeLocationConverter prlc2= new ProjectRelativeLocationConverter(emptyCProject);
+ ResourceContainerRelativeLocationConverter prlc2= new ResourceContainerRelativeLocationConverter(emptyCProject.getProject());
IIndexFileLocation ifl2= prlc2.fromInternalFormat(r1);
assertNotNull(ifl2);
assertEquals(
@@ -175,7 +175,7 @@ public class IndexLocationTest extends BaseTestCase {
}
}
- public void testURLC_PRLC_Interaction1() throws Exception {
+ public void testURLC_RCRLC_Interaction1() throws Exception {
String[] paths = new String[] {
"c:/foo/bar/baz.cpp",
"c:\\foo\\bar\\a b c\\baz.cpp",
@@ -196,7 +196,7 @@ public class IndexLocationTest extends BaseTestCase {
URIRelativeLocationConverter urlc = new URIRelativeLocationConverter(base);
String r1 = urlc.toInternalFormat(ifl1);
assertNotNull(r1);
- ProjectRelativeLocationConverter prlc= new ProjectRelativeLocationConverter(cproject);
+ ResourceContainerRelativeLocationConverter prlc= new ResourceContainerRelativeLocationConverter(cproject.getProject());
IIndexFileLocation ifl2= prlc.fromInternalFormat(r1);
String r2= prlc.toInternalFormat(ifl2);
assertNotNull(r2);
@@ -207,7 +207,7 @@ public class IndexLocationTest extends BaseTestCase {
}
}
- public void testURLC_PRLC_Interaction2() throws Exception {
+ public void testURLC_RCRLC_Interaction2() throws Exception {
String[] paths = new String[] {
"a b c/d/e f/g.h",
"a \\b /c.d",
@@ -222,7 +222,7 @@ public class IndexLocationTest extends BaseTestCase {
for(int i=0; i<paths.length; i++) {
IFile file= cproject.getProject().getFile(paths[i]);
IIndexFileLocation ifl1= IndexLocationFactory.getWorkspaceIFL(file);
- ProjectRelativeLocationConverter prlc= new ProjectRelativeLocationConverter(cproject);
+ ResourceContainerRelativeLocationConverter prlc= new ResourceContainerRelativeLocationConverter(cproject.getProject());
String r1= prlc.toInternalFormat(ifl1);
assertNotNull(r1);
URI base = URIUtil.toURI("c:/foo/bar/");
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/ProjectRelativeLocationConverter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/ResourceContainerRelativeLocationConverter.java
index b9c4d43175e..3b01556ebce 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/ProjectRelativeLocationConverter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/ResourceContainerRelativeLocationConverter.java
@@ -7,57 +7,55 @@
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
- *******************************************************************************/
-package org.eclipse.cdt.core.index;
-
-import org.eclipse.cdt.core.model.ICProject;
+ *******************************************************************************/
+package org.eclipse.cdt.core.index;
import org.eclipse.cdt.internal.core.index.IndexFileLocation;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
+import org.eclipse.core.runtime.Path;
/**
- * A location converter for converting project resource locations to be project relative. Resources outside of
- * the associated project will be ignored.
+ * A location converter for converting project resource locations to be relative to a specified container.
+ * Resources outside of the associated project will not be converted (ignored).
* <br>
* 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
* <br>
- * 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)

Back to the top