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 raw -project-> loc + for(int i=0; i raw -uri-> loc + for(int i=0; i + * 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 + *
+ * 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(); + } +}