From 7028cddf94514c156a20c07bdc1f12319cf7347e Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Tue, 27 Feb 2007 08:54:51 +0000 Subject: generalize ProjectRelativeLocationConverter --- .../internal/index/tests/IndexLocationTest.java | 16 +++--- .../index/ProjectRelativeLocationConverter.java | 63 ---------------------- ...ResourceContainerRelativeLocationConverter.java | 61 +++++++++++++++++++++ .../core/index/URIRelativeLocationConverter.java | 2 +- 4 files changed, 70 insertions(+), 72 deletions(-) delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/ProjectRelativeLocationConverter.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/ResourceContainerRelativeLocationConverter.java 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 - */ -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/ResourceContainerRelativeLocationConverter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/ResourceContainerRelativeLocationConverter.java new file mode 100644 index 00000000000..3b01556ebce --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/ResourceContainerRelativeLocationConverter.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * 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.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; +/** + * 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). + *
+ * This location converter is internal-representation-compatible with URIRelativeLocationConverter + */ + /* + * Internal representation is a relative path + */ +public class ResourceContainerRelativeLocationConverter implements IIndexLocationConverter { + protected IWorkspaceRoot root; + protected IPath fullPath; + + /** + * @param container the resource container to convert relative to + */ + 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(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 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) -- cgit v1.2.3