mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
add location converters plus tests
This commit is contained in:
parent
bf88a24e9c
commit
a2982222d3
11 changed files with 274 additions and 14 deletions
|
@ -32,12 +32,9 @@ import org.eclipse.core.resources.IContainer;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
public class EnclosingNamesTest extends BaseTestCase {
|
public class EnclosingNamesTest extends BaseTestCase {
|
||||||
private static final IProgressMonitor NPM = new NullProgressMonitor();
|
|
||||||
private ICProject fCProject;
|
private ICProject fCProject;
|
||||||
protected IIndex fIndex;
|
protected IIndex fIndex;
|
||||||
|
|
||||||
|
|
|
@ -58,13 +58,11 @@ import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IProjectDescription;
|
import org.eclipse.core.resources.IProjectDescription;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
public class IndexBugsTests extends BaseTestCase {
|
public class IndexBugsTests extends BaseTestCase {
|
||||||
private static final int INDEX_WAIT_TIME = 8000;
|
private static final int INDEX_WAIT_TIME = 8000;
|
||||||
private static final IProgressMonitor NPM = new NullProgressMonitor();
|
|
||||||
private ICProject fCProject;
|
private ICProject fCProject;
|
||||||
protected IIndex fIndex;
|
protected IIndex fIndex;
|
||||||
|
|
||||||
|
|
|
@ -37,11 +37,9 @@ import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
public class IndexIncludeTest extends IndexTestBase {
|
public class IndexIncludeTest extends IndexTestBase {
|
||||||
private static final IProgressMonitor NPM= new NullProgressMonitor();
|
|
||||||
|
|
||||||
public static TestSuite suite() {
|
public static TestSuite suite() {
|
||||||
TestSuite suite= suite(IndexIncludeTest.class, "_");
|
TestSuite suite= suite(IndexIncludeTest.class, "_");
|
||||||
|
|
|
@ -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.BaseTestCase;
|
||||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
|
||||||
public class IndexListenerTest extends BaseTestCase {
|
public class IndexListenerTest extends BaseTestCase {
|
||||||
private static final IProgressMonitor NPM = new NullProgressMonitor();
|
|
||||||
private ICProject fProject1;
|
private ICProject fProject1;
|
||||||
private ICProject fProject2;
|
private ICProject fProject2;
|
||||||
|
|
||||||
|
|
|
@ -22,14 +22,20 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
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.IIndexName;
|
||||||
import org.eclipse.cdt.core.index.IndexFilter;
|
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.model.ICProject;
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||||
import org.eclipse.core.commands.ExecutionException;
|
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.IFile;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
@ -39,7 +45,7 @@ import org.eclipse.core.runtime.Path;
|
||||||
import org.osgi.framework.Bundle;
|
import org.osgi.framework.Bundle;
|
||||||
|
|
||||||
public class IndexLocationTest extends BaseTestCase {
|
public class IndexLocationTest extends BaseTestCase {
|
||||||
ICProject cproject;
|
ICProject cproject, emptyCProject;
|
||||||
File movedLocation;
|
File movedLocation;
|
||||||
File externalHeader;
|
File externalHeader;
|
||||||
|
|
||||||
|
@ -49,6 +55,7 @@ public class IndexLocationTest extends BaseTestCase {
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
cproject= CProjectHelper.createCProject("LocationTests", "bin", IPDOMManager.ID_NO_INDEXER);
|
cproject= CProjectHelper.createCProject("LocationTests", "bin", IPDOMManager.ID_NO_INDEXER);
|
||||||
|
emptyCProject= CProjectHelper.createCProject("Empty", "bin", IPDOMManager.ID_NO_INDEXER);
|
||||||
|
|
||||||
Bundle b = CTestPlugin.getDefault().getBundle();
|
Bundle b = CTestPlugin.getDefault().getBundle();
|
||||||
StringBuffer[] testData = TestSourceReader.getContentsForTest(b, "parser", getClass(), getName(), 3);
|
StringBuffer[] testData = TestSourceReader.getContentsForTest(b, "parser", getClass(), getName(), 3);
|
||||||
|
@ -77,6 +84,9 @@ public class IndexLocationTest extends BaseTestCase {
|
||||||
if (cproject != null) {
|
if (cproject != null) {
|
||||||
cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor());
|
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();
|
movedLocation.delete();
|
||||||
externalHeader.delete();
|
externalHeader.delete();
|
||||||
externalHeader.getParentFile().delete();
|
externalHeader.getParentFile().delete();
|
||||||
|
@ -146,4 +156,83 @@ public class IndexLocationTest extends BaseTestCase {
|
||||||
index.releaseReadLock();
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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.PDOM;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
||||||
|
|
||||||
public class IndexSearchTest extends IndexTestBase {
|
public class IndexSearchTest extends IndexTestBase {
|
||||||
|
|
||||||
private static final IndexFilter INDEX_FILTER = new IndexFilter();
|
private static final IndexFilter INDEX_FILTER = new IndexFilter();
|
||||||
private static final IProgressMonitor NPM= new NullProgressMonitor();
|
|
||||||
|
|
||||||
public static TestSuite suite() {
|
public static TestSuite suite() {
|
||||||
TestSuite suite= suite(IndexSearchTest.class, "_");
|
TestSuite suite= suite(IndexSearchTest.class, "_");
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,7 @@ public class PDOMTests extends TestSuite {
|
||||||
|
|
||||||
suite.addTest(DBTest.suite());
|
suite.addTest(DBTest.suite());
|
||||||
suite.addTest(PDOMSearchTest.suite());
|
suite.addTest(PDOMSearchTest.suite());
|
||||||
|
suite.addTestSuite(PDOMLocationTests.class);
|
||||||
suite.addTestSuite(EnumerationTests.class);
|
suite.addTestSuite(EnumerationTests.class);
|
||||||
suite.addTestSuite(ClassTests.class);
|
suite.addTestSuite(ClassTests.class);
|
||||||
suite.addTestSuite(TypesTests.class);
|
suite.addTestSuite(TypesTests.class);
|
||||||
|
|
|
@ -15,6 +15,9 @@ import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
@ -23,6 +26,8 @@ import junit.framework.TestResult;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
public class BaseTestCase extends TestCase {
|
public class BaseTestCase extends TestCase {
|
||||||
|
protected static final IProgressMonitor NPM= new NullProgressMonitor();
|
||||||
|
|
||||||
private boolean fExpectFailure= false;
|
private boolean fExpectFailure= false;
|
||||||
private int fBugnumber= 0;
|
private int fBugnumber= 0;
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue