Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Ferguson2007-02-26 13:56:11 +0000
committerAndrew Ferguson2007-02-26 13:56:11 +0000
commita2982222d3552f5e3379b5c2e576aa829517ad60 (patch)
tree9f35dfa95e65b244992e8ca6c36136386d5d0f41
parentbf88a24e9c9ed5fba50f9fe068e837ba61c4a059 (diff)
downloadorg.eclipse.cdt-a2982222d3552f5e3379b5c2e576aa829517ad60.tar.gz
org.eclipse.cdt-a2982222d3552f5e3379b5c2e576aa829517ad60.tar.xz
org.eclipse.cdt-a2982222d3552f5e3379b5c2e576aa829517ad60.zip
add location converters plus tests
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EnclosingNamesTest.java3
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java2
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java2
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java2
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java93
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java3
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMLocationTests.java66
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java1
-rw-r--r--core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/ProjectRelativeLocationConverter.java63
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/URIRelativeLocationConverter.java48
11 files changed, 274 insertions, 14 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EnclosingNamesTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EnclosingNamesTest.java
index 737ead8c376..b3f1ab23717 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EnclosingNamesTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EnclosingNamesTest.java
@@ -32,12 +32,9 @@ import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
public class EnclosingNamesTest extends BaseTestCase {
- private static final IProgressMonitor NPM = new NullProgressMonitor();
private ICProject fCProject;
protected IIndex fIndex;
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java
index e4d889b39de..b32d062a16a 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java
@@ -58,13 +58,11 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
public class IndexBugsTests extends BaseTestCase {
private static final int INDEX_WAIT_TIME = 8000;
- private static final IProgressMonitor NPM = new NullProgressMonitor();
private ICProject fCProject;
protected IIndex fIndex;
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java
index 84180ef745e..a3fe73361e9 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java
@@ -37,11 +37,9 @@ import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
public class IndexIncludeTest extends IndexTestBase {
- private static final IProgressMonitor NPM= new NullProgressMonitor();
public static TestSuite suite() {
TestSuite suite= suite(IndexIncludeTest.class, "_");
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java
index 17a09d0c47a..807fcf4dff8 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java
@@ -28,11 +28,9 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
public class IndexListenerTest extends BaseTestCase {
- private static final IProgressMonitor NPM = new NullProgressMonitor();
private ICProject fProject1;
private ICProject fProject2;
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 ea1e20930fd..6f69a5b3fc8 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
@@ -22,14 +22,20 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
+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.URIRelativeLocationConverter;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.filesystem.URIUtil;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -39,7 +45,7 @@ import org.eclipse.core.runtime.Path;
import org.osgi.framework.Bundle;
public class IndexLocationTest extends BaseTestCase {
- ICProject cproject;
+ ICProject cproject, emptyCProject;
File movedLocation;
File externalHeader;
@@ -49,7 +55,8 @@ public class IndexLocationTest extends BaseTestCase {
protected void setUp() throws Exception {
cproject= CProjectHelper.createCProject("LocationTests", "bin", IPDOMManager.ID_NO_INDEXER);
-
+ emptyCProject= CProjectHelper.createCProject("Empty", "bin", IPDOMManager.ID_NO_INDEXER);
+
Bundle b = CTestPlugin.getDefault().getBundle();
StringBuffer[] testData = TestSourceReader.getContentsForTest(b, "parser", getClass(), getName(), 3);
@@ -77,6 +84,9 @@ public class IndexLocationTest extends BaseTestCase {
if (cproject != null) {
cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor());
}
+ if (emptyCProject != null) {
+ emptyCProject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor());
+ }
movedLocation.delete();
externalHeader.delete();
externalHeader.getParentFile().delete();
@@ -146,4 +156,83 @@ public class IndexLocationTest extends BaseTestCase {
index.releaseReadLock();
}
}
+
+ public void testProjectRelativeLocationConverter() 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);
+ String r1= prlc1.toInternalFormat(ifl1);
+ assertNotNull(r1);
+ ProjectRelativeLocationConverter prlc2= new ProjectRelativeLocationConverter(emptyCProject);
+ IIndexFileLocation ifl2= prlc2.fromInternalFormat(r1);
+ assertNotNull(ifl2);
+ assertEquals(
+ new Path(ifl1.getFullPath()).removeFirstSegments(1),
+ new Path(ifl2.getFullPath()).removeFirstSegments(1)
+ );
+ }
+ }
+
+ public void testURLC_PRLC_Interaction1() throws Exception {
+ String[] paths = new String[] {
+ "c:/foo/bar/baz.cpp",
+ "c:\\foo\\bar\\a b c\\baz.cpp",
+ "c:/foo/bar/a b/baz.cpp",
+ "c:\\foo\\bar\\a b c\\a b/baz.cpp"
+ };
+ String[] expectedFullPaths = new String[] {
+ "/"+cproject.getProject().getName()+"/baz.cpp",
+ "/"+cproject.getProject().getName()+"/a b c/baz.cpp",
+ "/"+cproject.getProject().getName()+"/a b/baz.cpp",
+ "/"+cproject.getProject().getName()+"/a b c/a b/baz.cpp"
+ };
+ IContainer root= ResourcesPlugin.getWorkspace().getRoot();
+ // loc -uri-> raw -project-> loc
+ for(int i=0; i<paths.length; i++) {
+ URI base = URIUtil.toURI("c:/foo/bar/");
+ IIndexFileLocation ifl1 = IndexLocationFactory.getExternalIFL(paths[i]);
+ URIRelativeLocationConverter urlc = new URIRelativeLocationConverter(base);
+ String r1 = urlc.toInternalFormat(ifl1);
+ assertNotNull(r1);
+ ProjectRelativeLocationConverter prlc= new ProjectRelativeLocationConverter(cproject);
+ IIndexFileLocation ifl2= prlc.fromInternalFormat(r1);
+ String r2= prlc.toInternalFormat(ifl2);
+ assertNotNull(r2);
+ assertNull(ifl1.getFullPath());
+ assertEquals(expectedFullPaths[i], ifl2.getFullPath());
+ assertEquals(URIUtil.toURI(paths[i]).normalize(), ifl1.getURI());
+ assertEquals(root.getFile(new Path(expectedFullPaths[i])).getLocationURI(), ifl2.getURI());
+ }
+ }
+
+ public void testURLC_PRLC_Interaction2() throws Exception {
+ String[] paths = new String[] {
+ "a b c/d/e f/g.h",
+ "a \\b /c.d",
+ "/a b c/d-e/f.g"
+ };
+ String[] expectedFullPaths = new String[] {
+ "/"+cproject.getProject().getName()+"/a b c/d/e f/g.h",
+ "/"+cproject.getProject().getName()+"/a /b /c.d",
+ "/"+cproject.getProject().getName()+"/a b c/d-e/f.g"
+ };
+ // loc -project-> raw -uri-> loc
+ 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);
+ String r1= prlc.toInternalFormat(ifl1);
+ assertNotNull(r1);
+ URI base = URIUtil.toURI("c:/foo/bar/");
+ URIRelativeLocationConverter c1 = new URIRelativeLocationConverter(base);
+ IIndexFileLocation ifl2= c1.fromInternalFormat(r1);
+ assertNotNull(ifl2);
+ assertEquals(expectedFullPaths[i], ifl1.getFullPath());
+ assertNull(ifl2.getFullPath());
+ assertEquals(cproject.getProject().getFile(paths[i]).getLocationURI(), ifl1.getURI());
+ assertEquals(URIUtil.toURI("c:/foo/bar/"+paths[i]).normalize(), ifl2.getURI());
+ }
+ }
} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java
index dfe7ba66a7a..d6ef8e5ea62 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java
@@ -36,13 +36,10 @@ import org.eclipse.cdt.internal.core.index.CIndex;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
public class IndexSearchTest extends IndexTestBase {
private static final IndexFilter INDEX_FILTER = new IndexFilter();
- private static final IProgressMonitor NPM= new NullProgressMonitor();
public static TestSuite suite() {
TestSuite suite= suite(IndexSearchTest.class, "_");
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMLocationTests.java
new file mode 100644
index 00000000000..5496d05b001
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMLocationTests.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Symbian Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Ferguson (Symbian) - Initial implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.pdom.tests;
+
+import org.eclipse.cdt.core.dom.IPDOMManager;
+import org.eclipse.cdt.core.index.IIndexFileLocation;
+import org.eclipse.cdt.core.index.IndexLocationFactory;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.testplugin.CProjectHelper;
+import org.eclipse.cdt.core.testplugin.CTestPlugin;
+import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
+import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMProjectIndexLocationConverter;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.osgi.framework.Bundle;
+
+/**
+ * Tests behaviour related to location representation in the PDOM
+ */
+public class PDOMLocationTests extends BaseTestCase {
+ ICProject cproject;
+
+ protected void setUp() throws Exception {
+ cproject= CProjectHelper.createCCProject("PDOMLocationTests"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
+
+ Bundle b = CTestPlugin.getDefault().getBundle();
+ StringBuffer[] testData = TestSourceReader.getContentsForTest(b, "parser", getClass(), getName(), 3);
+
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ if (cproject != null) {
+ cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor());
+ }
+ super.tearDown();
+ }
+
+ public void testLocationConverter() {
+ PDOMProjectIndexLocationConverter converter = new PDOMProjectIndexLocationConverter(cproject.getProject());
+ String[] externals = new String[] {
+ "c:/a/b/c/d.foo",
+ "c:\\a\\b\\c\\d\\e.foo",
+ "d:/foo.bar",
+ "d:\\Documents and Settings\\JDoe\\Eclipse Workspaces\\ProjectX\\foo.bar",
+ "/home/jdoe/eclipse workspaces/projectx/foo.bar"
+ };
+ for(int i=0; i<externals.length; i++) {
+ IIndexFileLocation loc = IndexLocationFactory.getExternalIFL(externals[i]);
+ String raw = converter.toInternalFormat(loc);
+ IIndexFileLocation roundtrip = converter.fromInternalFormat(raw);
+ assertTrue(roundtrip!=null);
+ assertEquals(roundtrip.getFullPath(), loc.getFullPath());
+ assertEquals(roundtrip.getURI(), loc.getURI());
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java
index c0be73fa120..5182c0d8ed3 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java
@@ -25,6 +25,7 @@ public class PDOMTests extends TestSuite {
suite.addTest(DBTest.suite());
suite.addTest(PDOMSearchTest.suite());
+ suite.addTestSuite(PDOMLocationTests.class);
suite.addTestSuite(EnumerationTests.class);
suite.addTestSuite(ClassTests.class);
suite.addTestSuite(TypesTests.class);
diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java
index c6645b09718..a4fbdcaece7 100644
--- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java
@@ -15,6 +15,9 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Vector;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -23,6 +26,8 @@ import junit.framework.TestResult;
import junit.framework.TestSuite;
public class BaseTestCase extends TestCase {
+ protected static final IProgressMonitor NPM= new NullProgressMonitor();
+
private boolean fExpectFailure= false;
private int fBugnumber= 0;
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/ProjectRelativeLocationConverter.java
new file mode 100644
index 00000000000..b9c4d43175e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/ProjectRelativeLocationConverter.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Symbian Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Ferguson (Symbian) - Initial implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.index;
+
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.internal.core.index.IndexFileLocation;
+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;
+
+/**
+ * A location converter for converting project resource locations to be project relative. Resources outside of
+ * the associated project will be ignored.
+ * <br>
+ * This location converter is internal-representation-compatible with URIRelativeLocationConverter
+ */
+ /*
+ * Internal representation is project relative path
+ */
+public class ProjectRelativeLocationConverter implements IIndexLocationConverter {
+ protected IWorkspaceRoot root;
+ protected String cprojectName;
+
+ /**
+ * @param cproject the CDT project to convert relative to
+ */
+ public ProjectRelativeLocationConverter(ICProject cproject) {
+ this.cprojectName = cproject.getProject().getName();
+ 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$
+ 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();
+ }
+ 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
new file mode 100644
index 00000000000..eb0edd3849f
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/URIRelativeLocationConverter.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Symbian Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Ferguson (Symbian) - Initial implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.index;
+
+import java.net.URI;
+
+import org.eclipse.cdt.internal.core.index.IndexFileLocation;
+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
+ */
+/*
+ * Internal representation is uri relative path (non encoded form)
+ */
+public class URIRelativeLocationConverter implements IIndexLocationConverter {
+ private URI baseURI;
+
+ /**
+ * Constructs an URIRelativeLocationConverter which will relative paths
+ * by prefixing the supplied base URI
+ * @param baseURI
+ */
+ public URIRelativeLocationConverter(URI baseURI) {
+ this.baseURI = baseURI;
+ }
+
+ public IIndexFileLocation fromInternalFormat(String raw) {
+ URI uri= baseURI.resolve(URIUtil.toURI(raw).getRawPath().substring(1));
+ return new IndexFileLocation(uri, null);
+ }
+
+ public String toInternalFormat(IIndexFileLocation location) {
+ URI relative = baseURI.relativize(location.getURI());
+ return relative.isAbsolute() ? null : relative.getPath();
+ }
+}

Back to the top