1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 01:35:39 +02:00

apply patch for 162172: make PDOM relocatable

This commit is contained in:
Andrew Ferguson 2006-12-05 18:29:04 +00:00
parent ba0d37b4a8
commit d6d9ed6df0
51 changed files with 826 additions and 349 deletions

View file

@ -19,19 +19,18 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyCalculator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
/**
* @author Doug Schaefer
*/
public class PDOMDependencyCalculator implements IManagedDependencyCalculator {
@ -44,7 +43,7 @@ public class PDOMDependencyCalculator implements IManagedDependencyCalculator {
private IPath[] dependencies;
public PDOMDependencyCalculator(IPath source, IResource resource, IBuildObject buildContext, ITool tool, IPath topBuildDirectory) {
this.source = source;
this.source = source;
this.resource = resource;
this.buildContext = buildContext;
this.tool = tool;
@ -60,16 +59,16 @@ public class PDOMDependencyCalculator implements IManagedDependencyCalculator {
if (resource != null) {
ICProject project = CoreModel.getDefault().create(resource.getProject());
try {
IIndex index= CCorePlugin.getIndexManager().getIndex(project, IIndexManager.ADD_DEPENDENCIES);
IIndex index = CCorePlugin.getIndexManager().getIndex(project, IIndexManager.ADD_DEPENDENCIES);
index.acquireReadLock();
try {
IIndexFile file = index.getFile(resource.getLocation());
IIndexFile file = index.getFile(IndexLocationFactory.getWorkspaceIFL((IFile)resource));
if (file != null) {
IIndexInclude[] includes = index.findIncludes(file, IIndex.DEPTH_INFINITE);
List/*<IPath>*/ list = new ArrayList/*<IPath>*/();
for (int i = 0; i < includes.length; ++i)
list.add(new Path(includes[i].getIncludesLocation()));
list.add(IndexLocationFactory.getAbsolutePath(includes[i].getIncludesLocation()));
dependencies = (IPath[])list.toArray(new IPath[list.size()]);
} else

View file

@ -29,6 +29,7 @@ import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexMacro;
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.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
@ -195,13 +196,13 @@ public class IndexBugsTests extends BaseTestCase {
fIndex.acquireReadLock();
try {
IIndexFile ifile= fIndex.getFile(file.getLocation());
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
assertNotNull(ifile);
IIndexInclude[] includes= ifile.getIncludes();
assertEquals(1, includes.length);
IIndexInclude i= includes[0];
assertEquals(file.getLocation().toOSString(), i.getIncludedByLocation());
assertEquals(include.getLocation().toOSString(), i.getIncludesLocation());
assertEquals(file.getLocationURI(), i.getIncludedByLocation().getURI());
assertEquals(include.getLocationURI(), i.getIncludesLocation().getURI());
assertEquals(true, i.isSystemInclude());
assertEquals(0, i.getNameOffset());
assertEquals(0, i.getNameLength());
@ -225,13 +226,13 @@ public class IndexBugsTests extends BaseTestCase {
fIndex.acquireReadLock();
try {
IIndexFile ifile= fIndex.getFile(file.getLocation());
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
assertNotNull(ifile);
IIndexInclude[] includes= ifile.getIncludes();
assertEquals(1, includes.length);
IIndexInclude i= includes[0];
assertEquals(file.getLocation().toOSString(), i.getIncludedByLocation());
assertEquals(include.getLocation().toOSString(), i.getIncludesLocation());
assertEquals(file.getLocationURI(), i.getIncludedByLocation().getURI());
assertEquals(include.getLocationURI(), i.getIncludesLocation().getURI());
assertEquals(true, i.isSystemInclude());
assertEquals(0, i.getNameOffset());
assertEquals(0, i.getNameLength());
@ -257,7 +258,7 @@ public class IndexBugsTests extends BaseTestCase {
fIndex.acquireReadLock();
try {
IIndexFile ifile= fIndex.getFile(file.getLocation());
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
assertNotNull(ifile);
IIndexMacro[] macros= ifile.getMacros();
assertEquals(2, macros.length);

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IPathEntry;
@ -133,7 +134,7 @@ public class IndexIncludeTest extends IndexTestBase {
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, 4000);
fIndex.acquireReadLock();
try {
IIndexFile ifile= fIndex.getFile(file.getLocation());
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
assertNotNull("Can't find " + file.getLocation(), ifile);
assertTrue("timestamp not ok", ifile.getTimestamp() >= timestamp);
@ -160,7 +161,7 @@ public class IndexIncludeTest extends IndexTestBase {
fIndex.acquireReadLock();
try {
IIndexFile ifile= fIndex.getFile(file.getLocation());
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
assertNotNull(ifile);
IIndexInclude[] includes= ifile.getIncludes();
assertEquals(2, includes.length);
@ -190,7 +191,7 @@ public class IndexIncludeTest extends IndexTestBase {
fIndex.acquireReadLock();
try {
IIndexFile ifile= fIndex.getFile(file.getLocation());
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
assertNotNull(ifile);
IIndexInclude[] includes= ifile.getIncludes();
assertEquals(1, includes.length);
@ -205,7 +206,7 @@ public class IndexIncludeTest extends IndexTestBase {
TestScannerProvider.sIncludes= null;
}
}
private void checkInclude(IIndexInclude include, String content, String includeName, boolean isSystem) throws CoreException {
int offset= content.indexOf(includeName);
assertEquals(offset, include.getNameOffset());

View file

@ -0,0 +1,5 @@
package org.eclipse.cdt.internal.index.tests;
public class IndexLocationTests {
}

View file

@ -50,7 +50,7 @@ public class BTreeTests extends BaseTestCase {
// and invoke it multiple times per Junit test
protected void init(int degree) throws Exception {
dbFile = File.createTempFile("pdomtest", "db");
db = new Database(dbFile.getAbsolutePath());
db = new Database(dbFile);
rootRecord = Database.DATA_AREA;
comparator = new BTMockRecordComparator();
btree = new BTree(db, rootRecord, degree, comparator);

View file

@ -37,7 +37,7 @@ public class DBTest extends TestCase {
// Tests block size and simple first block
File f = getTestDir().append("test1.dat").toFile();
f.delete();
Database db = new Database(f.getCanonicalPath());
Database db = new Database(f);
assertEquals(0, db.getVersion());
final int realsize = 42;
@ -55,7 +55,7 @@ public class DBTest extends TestCase {
// Tests free block linking
File f = getTestDir().append("test2.dat").toFile();
f.delete();
Database db = new Database(f.getCanonicalPath());
Database db = new Database(f);
final int realsize = 42;
final int blocksize = (realsize / Database.MIN_SIZE + 1) * Database.MIN_SIZE;
@ -75,7 +75,7 @@ public class DBTest extends TestCase {
//
File f = getTestDir().append("test2.dat").toFile();
f.delete();
Database db = new Database(f.getCanonicalPath());
Database db = new Database(f);
int mem1 = db.malloc(42);
db.free(mem1);
@ -112,7 +112,7 @@ public class DBTest extends TestCase {
// Tests inserting and retrieving strings
File f = getTestDir().append("testStrings.dat").toFile();
f.delete();
final Database db = new Database(f.getCanonicalPath());
final Database db = new Database(f);
String[] names = {
"ARLENE",

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
@ -68,13 +69,13 @@ public class FilesOnReindexTests extends PDOMTestBase {
void performAssertions(IFile file) throws CoreException {
IIndex index = CCorePlugin.getIndexManager().getIndex(project);
assertNotNull(index.getFile(file.getLocation()));
assertNotNull(index.getFile(IndexLocationFactory.getWorkspaceIFL(file)));
IBinding[] bs = index.findBindings(Pattern.compile("C"), true, new IndexFilter(), new NullProgressMonitor());
assertEquals(1, bs.length);
PDOMBinding binding = (PDOMBinding) bs[0];
IIndexFile file2 = binding.getFirstDefinition().getFile();
assertEquals(file.getLocation().toOSString(), file2.getLocation());
assertEquals(file.getLocationURI(), file2.getLocation().getURI());
}
}

View file

@ -16,8 +16,10 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
/**
* @author Doug Schaefer
@ -26,37 +28,37 @@ import org.eclipse.core.runtime.IPath;
public class IncludesTests extends PDOMTestBase {
protected ICProject project;
protected IIndex pdom;
protected IIndex index;
public static Test suite() {
return suite(IncludesTests.class);
}
protected void setUp() throws Exception {
if (pdom == null) {
if (index == null) {
project = createProject("includesTests");
pdom = CCorePlugin.getIndexManager().getIndex(project);
index = CCorePlugin.getIndexManager().getIndex(project);
}
pdom.acquireReadLock();
index.acquireReadLock();
}
protected void tearDown() throws Exception {
pdom.releaseReadLock();
index.releaseReadLock();
}
public void testIncludedBy() throws Exception {
IPath loc = project.getProject().getLocation().append("I2.h");
IIndexFile file = pdom.getFile(loc);
IResource loc = project.getProject().findMember("I2.h");
IIndexFile file = index.getFile(IndexLocationFactory.getWorkspaceIFL((IFile)loc));
assertNotNull(file);
IIndexInclude[] allIncludedBy = pdom.findIncludedBy(file, -1);
IIndexInclude[] allIncludedBy = index.findIncludedBy(file, -1);
assertEquals(9, allIncludedBy.length); // i.e. all of them
}
public void testIncludes() throws Exception {
IPath loc = project.getProject().getLocation().append("I1.cpp");
IIndexFile file = pdom.getFile(loc);
IResource loc = project.getProject().findMember("I1.cpp");
IIndexFile file = index.getFile(IndexLocationFactory.getWorkspaceIFL((IFile)loc));
assertNotNull(file);
IIndexInclude[] allIncludesTo= pdom.findIncludes(file, -1);
IIndexInclude[] allIncludesTo= index.findIncludes(file, -1);
assertEquals(2, allIncludesTo.length); // i.e. I1.h, I2.h
}
}

View file

@ -62,8 +62,6 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase {
IFile file = TestSourceReader.createFile(cproject.getProject(), header, testData[0].toString());
CCoreInternals.getPDOMManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
/* ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); */
IFile cppfile= TestSourceReader.createFile(cproject.getProject(), references, testData[1].toString());
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));

View file

@ -77,12 +77,38 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
IBinding b7 = getBindingFromASTName("method(cp->cspp);/*2*/", 6);
}
// // header file
// class C {public: class Base {}; static Base b; };
// C::Base C::b = *(new C::Base());
// namespace N { class Base2 {}; Base2 b2; };
// // references
// void foo(C::Base b) {}
// void foo2(N::Base2 b2) {}
// class D : public C::Base {};
// class E : public N::Base2 {};
// void bar() { foo(C::b); foo2(N::b2); }
public void _testSomeMore() {
IBinding b0 = getBindingFromASTName("Base {}", 4);
IBinding b1 = getBindingFromASTName("Base2 {}", 5);
IBinding b2 = getBindingFromASTName("foo(C::Base b)", 3);
IBinding b3 = getBindingFromASTName("foo2(N::Base2 b2)", 4);
IBinding b4 = getBindingFromASTName("C::b", 1);
IBinding b5 = getBindingFromASTName("N::b2", 1);
IBinding b6 = getBindingFromASTName("b); f", 1);
IBinding b7 = getBindingFromASTName("b2); }", 2);
IBinding b8 = getBindingFromASTName("foo(C::b)", 3);
IBinding b9 = getBindingFromASTName("foo2(N::b2)", 4);
}
// // header file
// class C {}; struct S {}; union U {}; enum E {ER1,ER2,ER3};
// int var1; C var2; S *var3; void func(E); void func(C);
// namespace ns {}
// typedef int Int; typedef int *IntPtr;
// void func(int*); void func(int);
// // referencing file
// #include "header.h"
// void references() {

View file

@ -29,6 +29,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
@ -209,18 +210,19 @@ public class TestSourceReader {
final IFile result[] = new IFile[1];
ws.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
//Obtain file handle
IFile file = container.getFile(filePath);
InputStream stream = new ByteArrayInputStream(contents.getBytes());
//Create file input stream
if (file.exists()) {
file.setContents(stream, false, false, new NullProgressMonitor());
}
else {
file.create(stream, false, new NullProgressMonitor());
}
//Obtain file handle
IFile file = container.getFile(filePath);
InputStream stream = new ByteArrayInputStream(contents.getBytes());
//Create file input stream
if (file.exists()) {
file.setContents(stream, false, false, new NullProgressMonitor());
}
else {
file.create(stream, false, new NullProgressMonitor());
}
result[0]= file;
}
}
}, null);
return result[0];
}
@ -256,7 +258,7 @@ public class TestSourceReader {
Assert.assertTrue(CCorePlugin.getIndexManager().joinIndexer(timeLeft, new NullProgressMonitor()));
index.acquireReadLock();
try {
IIndexFile pfile= index.getFile(file.getLocation());
IIndexFile pfile= index.getFile(IndexLocationFactory.getWorkspaceIFL(file));
if (pfile != null && pfile.getTimestamp() >= file.getLocalTimeStamp()) {
return;
}

View file

@ -80,6 +80,7 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.text;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.variables;bundle-version="[3.1.100,4.0.0)",
org.eclipse.core.filebuffers;bundle-version="[3.2.0,4.0.0)"
org.eclipse.core.filebuffers;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.filesystem;bundle-version="[1.1.0,2.0.0)"
Eclipse-LazyStart: true
Bundle-RequiredExecutionEnvironment: J2SE-1.4

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.core.index;
@ -16,7 +17,6 @@ import java.util.regex.Pattern;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
/**
@ -125,12 +125,13 @@ public interface IIndex {
public long getLastWriteAccess();
/**
* Looks for a file with the given location. May return <code>null</code>.
* @param location absolute path of the file location
* Looks for a file with the given location. Will return <code>null</code> if there
* is no entry in the index for the given location.
* @param location an IIndexFileLocation representing the location of the file
* @return the file in the index or <code>null</code>
* @throws CoreException
*/
public IIndexFile getFile(IPath location) throws CoreException;
public IIndexFile getFile(IIndexFileLocation location) throws CoreException;
/**
* Looks for include relations originated by the given file.

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.core.index;
@ -29,13 +30,12 @@ import org.eclipse.core.runtime.CoreException;
* @since 4.0
*/
public interface IIndexFile {
/**
* Returns the absolute path of the location of the file.
* @return the absolute path of the location of the file
* Returns an IIndexFileLocation representing the location of this file
* @return an IIndexFileLocation representing the location of this file
* @throws CoreException
*/
String getLocation() throws CoreException;
IIndexFileLocation getLocation() throws CoreException;
/**
* Returns all includes found in this file.

View file

@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software Ltd. 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 API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.index;
import java.net.URI;
/**
* Files in the index are (conceptually) partitioned into workspace and non-workspace (external) files.
* Clients can obtain instances of IIndexFileLocation implementations from {@link IndexLocationFactory}
* <p>
* This interface is not intended to be implemented by clients.
* </p>
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
* </p>
*
* @since 4.0
*/
public interface IIndexFileLocation {
/**
* The URI of the indexed file
* @return the URI of the indexed file (non-null)
*/
public URI getURI();
/**
* Return the workspace relative path of the indexed file or null if the file
* is not in the workspace
* @return the workspace relative path of the file in the index, or null if the
* file is not in the workspace
*/
public String getFullPath();
}

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.core.index;
@ -38,18 +39,18 @@ public interface IIndexInclude {
IIndexFile getIncludedBy() throws CoreException;
/**
* Returns the absolute path of the location of the file that contains this directive.
* @return the absolute path of the location of the file performing the include
* Returns the IIndexFileLocation of the file that contains this directive.
* @return the IIndexFileLocation of the file performing the include
* @throws CoreException
*/
String getIncludedByLocation() throws CoreException;
IIndexFileLocation getIncludedByLocation() throws CoreException;
/**
* Returns the absolute path of the location of the file that is included by this directive.
* @return the absolute path of the location of the file that is included by this directive
* Returns the IIndexFileLocation of the file that is included by this directive.
* @return the IIndexFileLocation of the file that is included by this directive
* @throws CoreException
*/
String getIncludesLocation() throws CoreException;
IIndexFileLocation getIncludesLocation() throws CoreException;
/**
* Returns the character offset of the name of the include in its source file. The name does

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.core.index;
@ -31,11 +32,6 @@ import org.eclipse.core.runtime.CoreException;
* @since 4.0
*/
public interface IIndexName extends IName {
/**
* Returns the location of the file the name resides in.
*/
public String getFileName();
/**
* Returns the file the name belongs to.
* @throws CoreException

View file

@ -0,0 +1,98 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software Ltd. 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 API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.index.IndexFileLocation;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
* Factory for obtaining instances of IIndexFileLocation for workspace or external files, and
* some utility methods for going in the opposite direction.
*/
public class IndexLocationFactory {
/**
* Returns
* <ul>
* <li> the full path if this IIndexFileLocation if within the workspace root
* <li> the absolute path if this IIndexFileLocation is URI based and corresponds
* to a location on the local file system
* <li> otherwise, null
* </ul>
* @param location
* @return the workspace root relative path, a local file system absolute path or null
*/
public static IPath getPath(IIndexFileLocation location) {
String fp = location.getFullPath();
if(fp!=null) {
return new Path(fp);
}
return getAbsolutePath(location);
}
/**
* Returns the absolute file path of an URI or null if the
* URI is not a filesystem path.
* @param uri
* @return
*/
public static IPath getAbsolutePath(IIndexFileLocation location) {
return URIUtil.toPath(location.getURI());
}
public static IIndexFileLocation getIFLExpensive(String absolutePath) {
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(absolutePath));
if(files.length==1) {
return getWorkspaceIFL(files[0]);
}
return new IndexFileLocation(URIUtil.toURI(absolutePath), null);
}
public static IIndexFileLocation getExternalIFL(String absolutePath) {
return getExternalIFL(new Path(absolutePath));
}
public static IIndexFileLocation getExternalIFL(IPath absolutePath) {
return new IndexFileLocation(URIUtil.toURI(absolutePath), null);
}
public static IIndexFileLocation getWorkspaceIFL(IFile file) {
return new IndexFileLocation(file.getLocationURI(), file.getFullPath().toString());
}
/**
* Returns<ul>
* <li> a workspace IIndexFileLocation if the translation unit has an associated resource
* <li> an external IIndexFileLocation if the translation unit does not have an associated resource
* <li> null, in any other case
* </ul>
* @param tu
* @return
*/
public static IIndexFileLocation getIFL(ITranslationUnit tu) {
IResource res = tu.getResource();
if(res instanceof IFile) {
return getWorkspaceIFL((IFile)res);
} else {
IPath location = tu.getLocation();
if(location!=null) {
return getExternalIFL(location);
} else {
return null;
}
}
}
}

View file

@ -2005,7 +2005,7 @@ public class CPPVisitor {
}
public static String [] getQualifiedName( IBinding binding ){
IASTName [] ns = null;
IName [] ns = null;
try {
ICPPScope scope = (ICPPScope) binding.getScope();
while( scope != null ){
@ -2020,12 +2020,12 @@ public class CPPVisitor {
if( scope instanceof ICPPNamespaceScope && scope.getScopeName().toCharArray().length == 0 )
break;
ns = (IASTName[]) ArrayUtil.append( IASTName.class, ns, n );
ns = (IName[]) ArrayUtil.append( IName.class, ns, n );
scope = (ICPPScope) scope.getParent();
}
} catch ( DOMException e ) {
}
ns = (IASTName[]) ArrayUtil.trim( IASTName.class, ns );
ns = (IName[]) ArrayUtil.trim( IName.class, ns );
String [] result = new String[ ns.length + 1 ];
for( int i = ns.length - 1; i >= 0; i-- ){
result[ ns.length - i - 1 ] = ns[i].toString();

View file

@ -26,11 +26,11 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
@ -177,11 +177,10 @@ public class CIndex implements IIndex {
return findNames(binding, FIND_REFERENCES);
}
public IIndexFile getFile(IPath location) throws CoreException {
public IIndexFile getFile(IIndexFileLocation location) throws CoreException {
IIndexFile result= null;
String path= location.toOSString();
for (int i = 0; result==null && i < fPrimaryFragmentCount; i++) {
result= fFragments[i].getFile(path);
result= fFragments[i].getFile(location);
}
return result;
}
@ -195,7 +194,8 @@ public class CIndex implements IIndex {
return result;
}
}
String location= include.getIncludesLocation();
IIndexFileLocation location= include.getIncludesLocation();
for (int i = 0; i < fPrimaryFragmentCount; i++) {
IIndexFragment otherFrag = fFragments[i];
if (otherFrag != frag) {

View file

@ -18,11 +18,11 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
final public class EmptyCIndex implements IIndex {
@ -47,7 +47,7 @@ final public class EmptyCIndex implements IIndex {
return IIndexFragmentName.EMPTY_NAME_ARRAY;
}
public IIndexFile getFile(IPath location) {
public IIndexFile getFile(IIndexFileLocation location) {
return null;
}

View file

@ -16,6 +16,7 @@ import java.util.regex.Pattern;
import org.eclipse.cdt.core.dom.ast.IASTName;
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.IndexFilter;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@ -50,11 +51,11 @@ public interface IIndexFragment {
/**
* Returns the file for the given location. May return <code>null</code>, if no such file exists.
* This method may only return files that are actually managed by this fragement.
* @param location absolute path to the location of the file
* @param location the IIndexFileLocation representing the location of the file
* @return the file for the location
* @throws CoreException
*/
IIndexFragmentFile getFile(String location) throws CoreException;
IIndexFragmentFile getFile(IIndexFileLocation location) throws CoreException;
/**
* Returns all include directives that point to the given file. The input file may belong to

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
@ -15,8 +16,8 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
/**
* Interface used by the indexer to write to the index.
@ -28,13 +29,14 @@ public interface IWritableIndex extends IIndex {
/**
* Creates a file object for the given location or returns an existing one.
*/
IIndexFragmentFile addFile(IPath fileLocation) throws CoreException;
IIndexFragmentFile addFile(IIndexFileLocation fileLocation) throws CoreException;
/**
* Adds content to the given file.
*/
void setFileContent(IIndexFragmentFile sourceFile,
IASTPreprocessorIncludeStatement[] includes,
IIndexFileLocation[] includeLocations,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException;
/**

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
@ -14,6 +15,7 @@ package org.eclipse.cdt.internal.core.index;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.core.runtime.CoreException;
/**
@ -33,8 +35,11 @@ public interface IWritableIndexFragment extends IIndexFragment {
/**
* Creates a file object for the given location or returns an existing one.
* @param fileLocation an IIndexFileLocation representing the location of the file
* @return the existing IIndexFragmentFile for this location, or a newly created one
* @throws CoreException
*/
IIndexFragmentFile addFile(String fileLocation) throws CoreException;
IIndexFragmentFile addFile(IIndexFileLocation fileLocation) throws CoreException;
/**
* Adds an include to the given file.

View file

@ -8,6 +8,7 @@
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
@ -24,9 +25,10 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.ICodeReaderCache;
import org.eclipse.cdt.core.parser.IMacro;
@ -35,7 +37,6 @@ import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacro;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
/**
* @author Doug Schaefer
@ -45,12 +46,15 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
private final static boolean CASE_SENSITIVE_FILES= !new File("a").equals(new File("A")); //$NON-NLS-1$//$NON-NLS-2$
private final IIndex index;
private Map fileInfoCache = new HashMap(); // filename, fileInfo
private Map/*<IIndexFileLocation,FileInfo>*/ fileInfoCache;
private Map/*<String,IIndexFileLocation>*/ iflCache;
private List usedMacros = new ArrayList();
private static final char[] EMPTY_CHARS = new char[0];
private static class NeedToParseException extends Exception {}
private static class NeedToParseException extends Exception {
private static final long serialVersionUID = 1L;
}
public static class FileInfo {
private FileInfo() {}
public IIndexFile fFile= null;
@ -66,9 +70,14 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
}
}
public IndexBasedCodeReaderFactory(IIndex index) {
this(index, new HashMap/*<String,IIndexFileLocation>*/());
}
public IndexBasedCodeReaderFactory(IIndex index, Map iflCache) {
this.index = index;
this.fileInfoCache = new HashMap/*<IIndexFileLocation,FileInfo>*/();
this.iflCache = iflCache;
}
public int getUniqueIdentifier() {
@ -95,7 +104,8 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
}
}
try {
FileInfo info= createInfo(canonicalPath, null);
IIndexFileLocation incLocation = findLocation(canonicalPath);
FileInfo info= createInfo(incLocation, null);
// try to build macro dictionary off index
if (info.fFile != null) {
@ -133,17 +143,17 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
return ParserUtil.createReader(canonicalPath, null);
}
private FileInfo createInfo(String location, IIndexFile file) throws CoreException {
private FileInfo createInfo(IIndexFileLocation location, IIndexFile file) throws CoreException {
FileInfo info= (FileInfo) fileInfoCache.get(location);
if (info == null) {
info= new FileInfo();
info.fFile= file == null ? index.getFile(new Path(location)) : file;
info.fFile= file == null ? index.getFile(location) : file;
fileInfoCache.put(location, info);
}
return info;
}
private void getInfosForMacroDictionary(FileInfo fileInfo, LinkedHashSet target) throws CoreException, NeedToParseException {
private void getInfosForMacroDictionary(FileInfo fileInfo, LinkedHashSet/*<FileInfo>*/ target) throws CoreException, NeedToParseException {
if (!target.add(fileInfo)) {
return;
}
@ -181,11 +191,14 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
return null;
}
public FileInfo createFileInfo(String location) throws CoreException {
public FileInfo createFileInfo(IIndexFileLocation location) throws CoreException {
return createInfo(location, null);
}
public FileInfo createFileInfo(ITranslationUnit tu) throws CoreException {
return createInfo(tu.getLocation().toOSString(), null);
public IIndexFileLocation findLocation(String absolutePath) {
if(!iflCache.containsKey(absolutePath)) {
iflCache.put(absolutePath, IndexLocationFactory.getIFLExpensive(absolutePath));
}
return (IIndexFileLocation) iflCache.get(absolutePath);
}
}

View file

@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software Ltd. 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 API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
import java.net.URI;
import org.eclipse.cdt.core.index.IIndexFileLocation;
/**
* An implementation of IIndexFileLocation
*/
public class IndexFileLocation implements IIndexFileLocation {
private final URI uri;
private final String fullPath;
public IndexFileLocation(URI uri, String fullPath) {
if(uri==null)
throw new IllegalArgumentException();
this.uri = uri;
this.fullPath = fullPath;
}
/*
* (non-Javadoc)
* @see org.eclipse.cdt.core.index.IIndexFileLocation#getFullPath()
*/
public String getFullPath() {
return fullPath;
}
/*
* (non-Javadoc)
* @see org.eclipse.cdt.core.index.IIndexFileLocation#getURI()
*/
public URI getURI() {
return uri;
}
/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if(obj instanceof IIndexFileLocation) {
return uri.equals(((IIndexFileLocation)obj).getURI());
}
return false;
}
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return uri.hashCode();
}
}

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
@ -14,9 +15,8 @@ package org.eclipse.cdt.internal.core.index;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
public class WritableCIndex extends CIndex implements IWritableIndex {
@ -35,12 +35,12 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
return result;
}
public IIndexFragmentFile addFile(IPath fileLocation) throws CoreException {
public IIndexFragmentFile addFile(IIndexFileLocation fileLocation) throws CoreException {
IWritableIndexFragment frag= selectFragment(fileLocation);
return frag.addFile(fileLocation.toOSString());
return frag.addFile(fileLocation);
}
private IWritableIndexFragment selectFragment(IPath fileLocation) {
private IWritableIndexFragment selectFragment(IIndexFileLocation fileLocation) {
// todo handling of multiple writable indices
assert fWritableFragments.length == 1;
return fWritableFragments[0];
@ -57,6 +57,7 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
public void setFileContent(IIndexFragmentFile file,
IASTPreprocessorIncludeStatement[] includes,
IIndexFileLocation[] includeLocations,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException {
IIndexFragment indexFragment = file.getIndexFragment();
@ -64,8 +65,7 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
IIndexFragmentFile[] destFiles= new IIndexFragmentFile[includes.length];
for (int i = 0; i < includes.length; i++) {
IASTPreprocessorIncludeStatement statement = includes[i];
destFiles[i]= addFile(new Path(statement.getPath()));
destFiles[i]= addFile(includeLocations[i]);
}
((IWritableIndexFragment) indexFragment).addFileContent(file,
includes, destFiles, macros, names);

View file

@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom;
import java.io.File;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collection;
@ -29,8 +30,9 @@ import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
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.model.LanguageManager;
@ -42,6 +44,7 @@ import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
import org.eclipse.cdt.internal.core.index.IIndexProxyBinding;
import org.eclipse.cdt.internal.core.pdom.db.BTree;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.IIndexLocationConverter;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
@ -49,9 +52,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Finder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
@ -85,6 +86,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
// 16 - have PDOMCPPField store type information, and PDOMCPPNamespaceAlias store what it is aliasing
// 17 - use single linked list for names in file, adds a link to enclosing defintion name.
// 18 - distinction between c-unions and c-structs.
// 19 - alter representation of paths in the pdom (162172)
public static final int LINKAGES = Database.DATA_AREA;
public static final int FILE_INDEX = Database.DATA_AREA + 4;
@ -92,16 +94,23 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
// Local caches
private BTree fileIndex;
private Map fLinkageIDCache = new HashMap();
private IPath fPath;
public PDOM(IPath dbPath) throws CoreException {
private File fPath;
private IIndexLocationConverter locationConverter;
public PDOM(File dbPath, IIndexLocationConverter locationConverter) throws CoreException {
// Load up the database
fPath= dbPath;
db = new Database(dbPath.toOSString());
db = new Database(fPath);
if (db.getVersion() == VERSION) {
readLinkages();
}
this.locationConverter = locationConverter;
}
public IIndexLocationConverter getLocationConverter() {
return locationConverter;
}
public boolean versionMismatch() {
@ -155,17 +164,14 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
return fileIndex;
}
public IIndexFragmentFile getFile(String path) throws CoreException {
Finder finder = new Finder(db, path);
getFileIndex().accept(finder);
int record = finder.getRecord();
return record != 0 ? new PDOMFile(this, record) : null;
public IIndexFragmentFile getFile(IIndexFileLocation location) throws CoreException {
return PDOMFile.findFile(this, getFileIndex(), location, locationConverter);
}
protected IIndexFragmentFile addFile(String path) throws CoreException {
IIndexFragmentFile file = getFile(path);
protected IIndexFragmentFile addFile(IIndexFileLocation location) throws CoreException {
IIndexFragmentFile file = getFile(location);
if (file == null) {
PDOMFile pdomFile = new PDOMFile(this, path);
PDOMFile pdomFile = new PDOMFile(this, location);
getFileIndex().insert(pdomFile.getRecord());
file= pdomFile;
}
@ -571,7 +577,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
return (PDOMFile) getFile(file.getLocation());
}
public IPath getPath() {
public File getPath() {
return fPath;
}
}

View file

@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom;
import java.io.File;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Iterator;
@ -24,8 +25,8 @@ import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.IPDOMIndexer;
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexChangeListener;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexerStateListener;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElementDelta;
@ -37,6 +38,7 @@ import org.eclipse.cdt.internal.core.index.IndexChangeEvent;
import org.eclipse.cdt.internal.core.index.IndexFactory;
import org.eclipse.cdt.internal.core.index.IndexerStateEvent;
import org.eclipse.cdt.internal.core.pdom.PDOM.IListener;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMProjectIndexLocationConverter;
import org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceDelta;
@ -177,7 +179,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
dbPath= CCorePlugin.getDefault().getStateLocation().append(dbName);
}
pdom = new WritablePDOM(dbPath);
pdom = new WritablePDOM(new File(dbPath.toOSString()), new PDOMProjectIndexLocationConverter(rproject));
pdom.addListener(this);
}

View file

@ -11,27 +11,29 @@
package org.eclipse.cdt.internal.core.pdom;
import java.io.File;
import java.text.MessageFormat;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
import org.eclipse.cdt.internal.core.pdom.dom.IIndexLocationConverter;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
public class WritablePDOM extends PDOM implements IWritableIndexFragment {
public WritablePDOM(IPath dbPath) throws CoreException {
super(dbPath);
public WritablePDOM(File dbPath, IIndexLocationConverter locationConverter) throws CoreException {
super(dbPath, locationConverter);
}
public IIndexFragmentFile addFile(String filename) throws CoreException {
return super.addFile(filename);
public IIndexFragmentFile addFile(IIndexFileLocation location) throws CoreException {
return super.addFile(location);
}
public void addFileContent(IIndexFragmentFile sourceFile,

View file

@ -78,10 +78,10 @@ public class Database {
public static final int MAX_SIZE = CHUNK_SIZE - 4; // Room for overhead
public Database(String filename) throws CoreException {
public Database(File location) throws CoreException {
try {
location = new File(filename);
file = new RandomAccessFile(filename, "rw"); //$NON-NLS-1$
this.location = location;
this.file = new RandomAccessFile(location, "rw"); //$NON-NLS-1$
// Allocate chunk table, make sure we have at least one
long nChunks = file.length() / CHUNK_SIZE;

View file

@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software Ltd. 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 API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.index.IIndexFileLocation;
/**
* Each IIndexFragment stores file location representations in an implementation specific manner.
* External to IIndexFragment files are identified by an {@link IIndexFileLocation}
*
* Internal to IIndexFragment a mechanism for converting between the string location format used
* and the URI world is needed. This interface represents that mechanism.
*/
public interface IIndexLocationConverter {
/**
* Convert a raw string in an internal IIndexFragment implementation specific format to
* an IIndexFileLocation or null if the internal format could not be translated.
* @param raw
* @return
*/
public abstract IIndexFileLocation fromInternalFormat(String raw);
/**
* Convert a IIndexFileLocation to the internal IIndexFragment implementation specific format
* or null if the location could not be translated.
* @param location
* @return an internal representation for the location specified
*/
public abstract String toInternalFormat(IIndexFileLocation location);
}

View file

@ -0,0 +1,22 @@
package org.eclipse.cdt.internal.core.pdom.dom;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class Messages {
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.pdom.dom.messages"; //$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
.getBundle(BUNDLE_NAME);
private Messages() {
}
public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
}

View file

@ -15,9 +15,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.index.IIndexName;
@ -26,6 +28,7 @@ import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
import org.eclipse.cdt.internal.core.pdom.db.BTree;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
@ -42,75 +45,54 @@ public class PDOMFile implements IIndexFragmentFile {
private final PDOM pdom;
private final int record;
private static final int FIRST_NAME = 0;
private static final int FIRST_INCLUDE = 4;
private static final int FIRST_INCLUDED_BY = 8;
private static final int FIRST_MACRO = 12;
private static final int FILE_NAME = 16;
private static final int LOCATION_REPRESENTATION = 16;
private static final int TIME_STAMP = 20;
private static final int RECORD_SIZE = 28;
public static class Comparator implements IBTreeComparator {
private Database db;
public Comparator(Database db) {
this.db = db;
}
public int compare(int record1, int record2) throws CoreException {
IString name1 = db.getString(db.getInt(record1 + FILE_NAME));
IString name2 = db.getString(db.getInt(record2 + FILE_NAME));
IString name1 = db.getString(db.getInt(record1 + LOCATION_REPRESENTATION));
IString name2 = db.getString(db.getInt(record2 + LOCATION_REPRESENTATION));
return name1.compare(name2);
}
}
public static class Finder implements IBTreeVisitor {
private final Database db;
private final String key;
private int record;
public Finder(Database db, String key) {
this.db = db;
this.key = key;
}
public int compare(int record) throws CoreException {
IString name = db.getString(db.getInt(record + FILE_NAME));
return name.compare(key);
}
public boolean visit(int record) throws CoreException {
this.record = record;
return false;
}
public int getRecord() {
return record;
}
}
public PDOMFile(PDOM pdom, int record) {
this.pdom = pdom;
this.record = record;
}
public PDOMFile(PDOM pdom, String filename) throws CoreException {
public PDOMFile(PDOM pdom, IIndexFileLocation location) throws CoreException {
this.pdom = pdom;
Database db = pdom.getDB();
record = db.malloc(RECORD_SIZE);
db.putInt(record + FILE_NAME, db.newString(filename).getRecord());
String locationString = pdom.getLocationConverter().toInternalFormat(location);
if(locationString==null)
throw new CoreException(CCorePlugin.createStatus(Messages.getString("PDOMFile.toInternalProblem")+location.getURI())); //$NON-NLS-1$
IString locationDBString = db.newString(locationString);
db.putInt(record + LOCATION_REPRESENTATION, locationDBString.getRecord());
db.putLong(record + TIME_STAMP, 0);
setFirstName(null);
setFirstInclude(null);
setFirstIncludedBy(null);
}
public int getRecord() {
return record;
}
public boolean equals(Object obj) {
if (obj == this)
return true;
@ -120,29 +102,31 @@ public class PDOMFile implements IIndexFragmentFile {
}
return false;
}
public IString getFileName() throws CoreException {
/**
* Directly changes this record's internal location string. The format
* of this string is unspecified in general and is determined by the
* associated IIndexLocationConverter
* @param newName
* @throws CoreException
*/
public void setInternalLocation(String internalLocation) throws CoreException {
Database db = pdom.getDB();
return db.getString(db.getInt(record + FILE_NAME));
}
public void setFilename(String newName) throws CoreException {
Database db = pdom.getDB();
int oldRecord = db.getInt(record + FILE_NAME);
int oldRecord = db.getInt(record + LOCATION_REPRESENTATION);
db.free(oldRecord);
db.putInt(record + FILE_NAME, db.newString(newName).getRecord());
db.putInt(record + LOCATION_REPRESENTATION, db.newString(internalLocation).getRecord());
}
public long getTimestamp() throws CoreException {
Database db = pdom.getDB();
return db.getLong(record + TIME_STAMP);
}
public void setTimestamp(long timestamp) throws CoreException {
Database db= pdom.getDB();
db.putLong(record + TIME_STAMP, timestamp);
}
public PDOMName getFirstName() throws CoreException {
int namerec = pdom.getDB().getInt(record + FIRST_NAME);
return namerec != 0 ? new PDOMName(pdom, namerec) : null;
@ -152,27 +136,27 @@ public class PDOMFile implements IIndexFragmentFile {
int namerec = firstName != null ? firstName.getRecord() : 0;
pdom.getDB().putInt(record + FIRST_NAME, namerec);
}
public PDOMInclude getFirstInclude() throws CoreException {
int increc = pdom.getDB().getInt(record + FIRST_INCLUDE);
return increc != 0 ? new PDOMInclude(pdom, increc) : null;
}
public void setFirstInclude(PDOMInclude include) throws CoreException {
int rec = include != null ? include.getRecord() : 0;
pdom.getDB().putInt(record + FIRST_INCLUDE, rec);
}
public PDOMInclude getFirstIncludedBy() throws CoreException {
int rec = pdom.getDB().getInt(record + FIRST_INCLUDED_BY);
return rec != 0 ? new PDOMInclude(pdom, rec) : null;
}
public void setFirstIncludedBy(PDOMInclude includedBy) throws CoreException {
int rec = includedBy != null ? includedBy.getRecord() : 0;
pdom.getDB().putInt(record + FIRST_INCLUDED_BY, rec);
}
public PDOMMacro getFirstMacro() throws CoreException {
int rec = pdom.getDB().getInt(record + FIRST_MACRO);
return rec != 0 ? new PDOMMacro(pdom, rec) : null;
@ -182,10 +166,10 @@ public class PDOMFile implements IIndexFragmentFile {
int rec = macro != null ? macro.getRecord() : 0;
pdom.getDB().putInt(record + FIRST_MACRO, rec);
}
public void addMacros(IASTPreprocessorMacroDefinition[] macros) throws CoreException {
assert getFirstMacro() == null;
PDOMMacro lastMacro= null;
for (int i = 0; i < macros.length; i++) {
IASTPreprocessorMacroDefinition macro = macros[i];
@ -199,7 +183,7 @@ public class PDOMFile implements IIndexFragmentFile {
lastMacro= pdomMacro;
}
}
public void addNames(IASTName[][] names) throws CoreException {
assert getFirstName() == null;
HashMap nameCache= new HashMap();
@ -220,7 +204,7 @@ public class PDOMFile implements IIndexFragmentFile {
}
}
}
private PDOMName createPDOMName(IASTName name, PDOMName caller) throws CoreException {
PDOMName result= null;
PDOMBinding binding= ((WritablePDOM) pdom).addBinding(name);
@ -239,7 +223,7 @@ public class PDOMFile implements IIndexFragmentFile {
include = nextInclude;
}
setFirstInclude(include);
// Delete all the macros in this file
PDOMMacro macro = getFirstMacro();
while (macro != null) {
@ -248,7 +232,7 @@ public class PDOMFile implements IIndexFragmentFile {
macro = nextMacro;
}
setFirstMacro(null);
// Delete all the names in this file
PDOMName name = getFirstName();
while (name != null) {
@ -258,21 +242,21 @@ public class PDOMFile implements IIndexFragmentFile {
}
setFirstName(null);
}
public void addIncludesTo(IIndexFragmentFile[] files, IASTPreprocessorIncludeStatement[] includes) throws CoreException {
assert files.length == includes.length;
assert getFirstInclude() == null;
PDOMInclude lastInclude= null;
for (int i = 0; i < includes.length; i++) {
IASTPreprocessorIncludeStatement statement = includes[i];
PDOMFile file= (PDOMFile) files[i];
assert file.getIndexFragment() instanceof IWritableIndexFragment;
PDOMInclude pdomInclude = new PDOMInclude(pdom, statement);
pdomInclude.setIncludedBy(this);
pdomInclude.setIncludes(file);
file.addIncludedBy(pdomInclude);
if (lastInclude == null) {
setFirstInclude(pdomInclude);
@ -283,7 +267,7 @@ public class PDOMFile implements IIndexFragmentFile {
lastInclude= pdomInclude;
}
}
public void addIncludedBy(PDOMInclude include) throws CoreException {
PDOMInclude firstIncludedBy = getFirstIncludedBy();
if (firstIncludedBy != null) {
@ -292,9 +276,9 @@ public class PDOMFile implements IIndexFragmentFile {
}
setFirstIncludedBy(include);
}
public IIndexInclude[] getIncludes() throws CoreException {
List result= new ArrayList();
PDOMInclude include = getFirstInclude();
@ -305,10 +289,6 @@ public class PDOMFile implements IIndexFragmentFile {
return (IIndexInclude[]) result.toArray(new IIndexInclude[result.size()]);
}
public String getLocation() throws CoreException {
return getFileName().getString();
}
public IIndexMacro[] getMacros() throws CoreException {
List result= new ArrayList();
PDOMMacro macro = getFirstMacro();
@ -318,7 +298,7 @@ public class PDOMFile implements IIndexFragmentFile {
}
return (IIndexMacro[]) result.toArray(new IIndexMacro[result.size()]);
}
public IIndexFragment getIndexFragment() {
return pdom;
}
@ -339,8 +319,52 @@ public class PDOMFile implements IIndexFragmentFile {
break;
}
}
}
return (IIndexName[]) result.toArray(new IIndexName[result.size()]);
}
public static IIndexFragmentFile findFile(PDOM pdom, BTree btree, IIndexFileLocation location, IIndexLocationConverter strategy)
throws CoreException {
Finder finder = new Finder(pdom.getDB(), location, strategy);
btree.accept(finder);
int record = finder.getRecord();
return record != 0 ? new PDOMFile(pdom, record) : null;
}
private static class Finder implements IBTreeVisitor {
private final Database db;
private final String rawKey;
private int record;
public Finder(Database db, IIndexFileLocation location, IIndexLocationConverter strategy)
throws CoreException
{
this.db = db;
this.rawKey = strategy.toInternalFormat(location);
}
public int compare(int record) throws CoreException {
IString name = db.getString(db.getInt(record + PDOMFile.LOCATION_REPRESENTATION));
return name.compare(rawKey);
}
public boolean visit(int record) throws CoreException {
this.record = record;
return false;
}
public int getRecord() {
return record;
}
}
public IIndexFileLocation getLocation() throws CoreException {
Database db = pdom.getDB();
String raw = db.getString(db.getInt(record + LOCATION_REPRESENTATION)).getString();
IIndexFileLocation result = pdom.getLocationConverter().fromInternalFormat(raw);
if(result==null)
throw new CoreException(CCorePlugin.createStatus(Messages.getString("PDOMFile.toExternalProblem")+raw)); //$NON-NLS-1$
return result;
}
}

View file

@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IIndexFragmentInclude;
@ -139,11 +140,11 @@ public class PDOMInclude implements IIndexFragmentInclude {
pdom.getDB().putInt(record + INCLUDED_BY_PREV, rec);
}
public String getIncludedByLocation() throws CoreException {
public IIndexFileLocation getIncludedByLocation() throws CoreException {
return getIncludedBy().getLocation();
}
public String getIncludesLocation() throws CoreException {
public IIndexFileLocation getIncludesLocation() throws CoreException {
return getIncludes().getLocation();
}

View file

@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
import java.net.URI;
import java.util.ArrayList;
import org.eclipse.cdt.core.CCorePlugin;
@ -106,16 +107,16 @@ public class PDOMName implements IIndexFragmentName, IASTFileLocation {
private int getRecField(int offset) throws CoreException {
return pdom.getDB().getInt(record + offset);
}
private void setRecField(int offset, int fieldrec) throws CoreException {
pdom.getDB().putInt(record + offset, fieldrec);
}
public PDOMBinding getPDOMBinding() throws CoreException {
int bindingrec = getRecField(BINDING_REC_OFFSET);
return pdom.getBinding(bindingrec);
}
public void setBinding(PDOMBinding binding) throws CoreException {
int bindingrec = binding != null ? binding.getRecord() : 0;
setRecField(BINDING_REC_OFFSET, bindingrec);
@ -125,16 +126,16 @@ public class PDOMName implements IIndexFragmentName, IASTFileLocation {
int namerec = getRecField(offset);
return namerec != 0 ? new PDOMName(pdom, namerec) : null;
}
private void setNameField(int offset, PDOMName name) throws CoreException {
int namerec = name != null ? name.getRecord() : 0;
setRecField(offset, namerec);
}
public PDOMName getPrevInBinding() throws CoreException {
return getNameField(BINDING_PREV_OFFSET);
}
public void setPrevInBinding(PDOMName name) throws CoreException {
setNameField(BINDING_PREV_OFFSET, name);
}
@ -194,7 +195,7 @@ public class PDOMName implements IIndexFragmentName, IASTFileLocation {
private byte getFlags() throws CoreException {
return pdom.getDB().getByte(record + FLAGS);
}
public boolean isDeclaration() {
try {
byte flags = getFlags();
@ -232,11 +233,20 @@ public class PDOMName implements IIndexFragmentName, IASTFileLocation {
public String getFileName() {
try {
PDOMFile file = (PDOMFile) getFile();
return file != null ? file.getFileName().getString() : null;
if(file!=null) {
/*
* We need to spec. what this method can return to know
* how to implement this. Existing implmentations return
* the absolute path, so here we attempt to do the same.
*/
URI uri = file.getLocation().getURI();
if ("file".equals(uri.getScheme())) //$NON-NLS-1$
return uri.getSchemeSpecificPart();
}
} catch (CoreException e) {
CCorePlugin.log(e);
return null;
}
return null;
}
public int getStartingLineNumber() {
@ -288,10 +298,10 @@ public class PDOMName implements IIndexFragmentName, IASTFileLocation {
break;
}
}
if (nextName != null)
nextName.setPrevInBinding(prevName);
// Delete our record
pdom.getDB().free(record);
}
@ -299,7 +309,7 @@ public class PDOMName implements IIndexFragmentName, IASTFileLocation {
public IIndexFragment getIndexFragment() {
return pdom;
}
public IIndexProxyBinding getBinding() throws CoreException {
return getPDOMBinding();
}

View file

@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2006 Symbian Software Ltd. 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 API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.internal.core.index.IndexFileLocation;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
/**
* The standard location converter used by the per-project PDOM
*/
public class PDOMProjectIndexLocationConverter implements IIndexLocationConverter {
IProject project;
IWorkspaceRoot root;
private static final String EXTERNAL = "<EXT>"; //$NON-NLS-1$
public PDOMProjectIndexLocationConverter(IProject project) {
this.project = project;
this.root = ResourcesPlugin.getWorkspace().getRoot();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.pdom.dom.IIndexLocationConverter#fromInternalFormat(java.lang.String)
*/
public IIndexFileLocation fromInternalFormat(String raw) {
String fullPath = null;
URI uri;
if(raw.startsWith(EXTERNAL)) {
try {
uri = new URI(raw.substring(EXTERNAL.length()));
} catch(URISyntaxException use) {
uri = null;
}
} else {
uri = project.findMember(raw).getLocationURI();
}
return new IndexFileLocation(uri, fullPath);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.pdom.dom.IIndexLocationConverter#toRaw(java.net.URI)
*/
public String toInternalFormat(IIndexFileLocation location) {
String result;
if(location.getFullPath()!=null) {
result = new Path(location.getFullPath()).removeFirstSegments(1).toString();
} else {
result = EXTERNAL+location.getURI().toString();
}
return result;
}
}

View file

@ -0,0 +1,2 @@
PDOMFile.toInternalProblem=Unable to translate location to internal format:
PDOMFile.toExternalProblem=Unable to translate from internal format for

View file

@ -31,7 +31,9 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ICContainer;
@ -42,12 +44,12 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndex;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
@ -89,7 +91,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
protected volatile int fTotalSourcesEstimate= 0;
protected volatile int fCompletedSources= 0;
protected volatile int fCompletedHeaders= 0;
protected Map fContextMap= new HashMap();
protected Map/*<IIndexFileLocation, Object>*/ fContextMap = new HashMap/*<IIndexFileLocation, Object>*/();
protected volatile String fMessage;
private boolean fTrace;
@ -105,7 +107,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
protected PDOMIndexerTask() {
fTrace= checkDebugOption("indexer", "true"); //$NON-NLS-1$//$NON-NLS-2$
fShowStatistics= checkDebugOption("pdomtimings", "true"); //$NON-NLS-1$//$NON-NLS-2$
}
}
private boolean checkDebugOption(String option, String value) {
String trace = Platform.getDebugOption(CCorePlugin.PLUGIN_ID + "/debug/" + option); //$NON-NLS-1$
@ -168,8 +170,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
protected void removeTU(IWritableIndex index, ITranslationUnit tu) throws CoreException, InterruptedException {
index.acquireWriteLock(0);
try {
IPath path = ((IFile)tu.getResource()).getLocation();
IIndexFragmentFile file = (IIndexFragmentFile) index.getFile(path);
IIndexFragmentFile file = (IIndexFragmentFile) index.getFile(getIndexFileLocation(tu));
if (file != null)
index.clearFile(file);
} finally {
@ -179,29 +180,26 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
protected void parseTUs(Collection sources, Collection headers, IProgressMonitor monitor) throws CoreException, InterruptedException {
// sources first
Iterator iter;
for (iter = sources.iterator(); iter.hasNext();) {
for (Iterator iter = sources.iterator(); iter.hasNext();) {
if (monitor.isCanceled())
return;
ITranslationUnit tu = (ITranslationUnit) iter.next();
String path = tu.getLocation().toOSString();
if (needToUpdate(path)) {
if (needToUpdate(getIndexFileLocation(tu))) {
parseTU(tu, monitor);
}
}
// headers with context
for (iter = headers.iterator(); iter.hasNext();) {
for (Iterator iter = headers.iterator(); iter.hasNext();) {
if (monitor.isCanceled())
return;
ITranslationUnit tu = (ITranslationUnit) iter.next();
String path = tu.getLocation().toOSString();
if (!needToUpdate(path)) {
IIndexFileLocation location = getIndexFileLocation(tu);
if (!needToUpdate(location)) {
iter.remove();
}
else {
ITranslationUnit context= findContext(getIndex(), path);
if (context != null) {
} else {
ITranslationUnit context= findContext(getIndex(), location);
if (context != null) {
parseTU(context, monitor);
}
}
@ -209,12 +207,11 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
// headers without context
if (getIndexAllFiles()) {
for (iter = headers.iterator(); iter.hasNext();) {
for (Iterator iter = headers.iterator(); iter.hasNext();) {
if (monitor.isCanceled())
return;
ITranslationUnit tu = (ITranslationUnit) iter.next();
String path = tu.getLocation().toOSString();
if (!needToUpdate(path)) {
if (!needToUpdate(getIndexFileLocation(tu))) {
iter.remove();
}
else {
@ -276,38 +273,37 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
return getIndexer().getIndexAllFiles();
}
protected ITranslationUnit findContext(IIndex index, String path) {
Object cachedContext= fContextMap.get(path);
protected ITranslationUnit findContext(IIndex index, IIndexFileLocation location) {
Object cachedContext= fContextMap.get(location);
if (cachedContext != null) {
return cachedContext == NO_CONTEXT ? null : (ITranslationUnit) cachedContext;
}
ITranslationUnit context= null;
fContextMap.put(path, NO_CONTEXT); // prevent recursion
fContextMap.put(location, NO_CONTEXT); // prevent recursion
IIndexFile pdomFile;
try {
pdomFile = index.getFile(new Path(path));
pdomFile = index.getFile(location);
if (pdomFile != null) {
ICProject project= getIndexer().getProject();
IIndexInclude[] includedBy = index.findIncludedBy(pdomFile, IIndex.DEPTH_ZERO);
ArrayList paths= new ArrayList(includedBy.length);
ArrayList/*<IIndexFileLocation>*/ paths= new ArrayList/*<IIndexFileLocation>*/(includedBy.length);
for (int i = 0; i < includedBy.length; i++) {
IIndexInclude include = includedBy[i];
String incfilename = include.getIncludedByLocation();
if (CoreModel.isValidSourceUnitName(project.getProject(), incfilename)) {
context= CoreModelUtil.findTranslationUnitForLocation(new Path(incfilename), project);
IIndexFileLocation incLocation = include.getIncludedByLocation();
if (CoreModel.isValidSourceUnitName(project.getProject(), incLocation.getURI().toString())) { // FIXME - is this ok?
ITranslationUnit context = CoreModelUtil.findTranslationUnitForLocation(IndexLocationFactory.getAbsolutePath(incLocation), project);
if (context != null) {
fContextMap.put(path, context);
fContextMap.put(location, context);
return context;
}
}
paths.add(incfilename);
paths.add(incLocation);
}
for (Iterator iter = paths.iterator(); iter.hasNext();) {
String nextLevel = (String) iter.next();
context= findContext(index, nextLevel);
for (Iterator/*<IIndexFileLocation>*/ iter = paths.iterator(); iter.hasNext();) {
IIndexFileLocation nextLevel = (IIndexFileLocation) iter.next();
ITranslationUnit context = findContext(index, nextLevel);
if (context != null) {
fContextMap.put(path, context);
fContextMap.put(location, context);
return context;
}
}
@ -339,12 +335,12 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
protected void addSymbols(IASTTranslationUnit ast, IProgressMonitor pm) throws InterruptedException, CoreException {
final Map symbolMap= new HashMap();
try {
String[] orderedPaths= extractSymbols(ast, symbolMap);
IIndexFileLocation[] orderedPaths= extractSymbols(ast, symbolMap);
for (int i=0; i<orderedPaths.length; i++) {
if (pm.isCanceled()) {
return;
}
String path= orderedPaths[i];
IIndexFileLocation path= orderedPaths[i];
ArrayList[] arrayLists = ((ArrayList[]) symbolMap.get(path));
// resolve the names
@ -360,8 +356,8 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
fReferenceCount++;
else
fDeclarationCount++;
}
}
}
fResolutionTime += System.currentTimeMillis()-start;
}
@ -375,7 +371,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
if (pm.isCanceled())
return;
String path = orderedPaths[i];
IIndexFileLocation path = orderedPaths[i];
if (path != null) {
if (fTrace) {
System.out.println("Indexer: adding " + path); //$NON-NLS-1$
@ -403,35 +399,36 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
}
}
private String[] extractSymbols(IASTTranslationUnit ast, final Map symbolMap) throws CoreException {
LinkedHashSet orderedIncludes= new LinkedHashSet();
ArrayList stack= new ArrayList();
private IIndexFileLocation[] extractSymbols(IASTTranslationUnit ast, final Map symbolMap) throws CoreException {
LinkedHashSet/*<IIndexFileLocation>*/ orderedIncludes= new LinkedHashSet/*<IIndexFileLocation>*/();
ArrayList/*<IIndexFileLocation>*/ stack= new ArrayList/*<IIndexFileLocation>*/();
final String astFilePath = ast.getFilePath();
String currentPath= astFilePath;
final IIndexFileLocation astLocation = findLocation(ast.getFilePath());
IIndexFileLocation currentPath = astLocation;
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
for (int i= 0; i < includes.length; i++) {
IASTPreprocessorIncludeStatement include = includes[i];
IASTFileLocation sourceLoc = include.getFileLocation();
String newPath= sourceLoc != null ? sourceLoc.getFileName() : astFilePath; // command-line includes
IIndexFileLocation newPath= sourceLoc != null ? findLocation(sourceLoc.getFileName()) : astLocation; // command-line includes
while (!stack.isEmpty() && !currentPath.equals(newPath)) {
if (needToUpdate(currentPath)) {
prepareInMap(symbolMap, currentPath);
orderedIncludes.add(currentPath);
}
currentPath= (String) stack.remove(stack.size()-1);
currentPath= (IIndexFileLocation) stack.remove(stack.size()-1);
}
if (needToUpdate(newPath)) {
prepareInMap(symbolMap, newPath);
addToMap(symbolMap, 0, newPath, include);
}
stack.add(currentPath);
currentPath= include.getPath();
currentPath= findLocation(include.getPath());
}
stack.add(currentPath);
while (!stack.isEmpty()) {
currentPath= (String) stack.remove(stack.size()-1);
currentPath= (IIndexFileLocation) stack.remove(stack.size()-1);
if (needToUpdate(currentPath)) {
prepareInMap(symbolMap, currentPath);
orderedIncludes.add(currentPath);
@ -444,7 +441,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
IASTPreprocessorMacroDefinition macro = macros[i2];
IASTFileLocation sourceLoc = macro.getFileLocation();
if (sourceLoc != null) { // skip built-ins and command line macros
String path2 = sourceLoc.getFileName();
IIndexFileLocation path2 = findLocation(sourceLoc.getFileName());
addToMap(symbolMap, 1, path2, macro);
}
}
@ -454,44 +451,41 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
public void visit(IASTName name, IASTName caller) {
IASTFileLocation nameLoc = name.getFileLocation();
if (nameLoc != null) {
addToMap(symbolMap, 2, nameLoc.getFileName(), new IASTName[]{name, caller});
IIndexFileLocation location = findLocation(nameLoc.getFileName());
addToMap(symbolMap, 2, location, new IASTName[]{name, caller});
}
}
});
return (String[]) orderedIncludes.toArray(new String[orderedIncludes.size()]);
return (IIndexFileLocation[]) orderedIncludes.toArray(new IIndexFileLocation[orderedIncludes.size()]);
}
protected abstract IWritableIndex getIndex();
protected abstract int getReadlockCount();
protected abstract boolean needToUpdate(String path) throws CoreException;
protected abstract boolean postAddToIndex(String path, IIndexFile file) throws CoreException;
protected abstract boolean needToUpdate(IIndexFileLocation location) throws CoreException;
protected abstract boolean postAddToIndex(IIndexFileLocation location, IIndexFile file) throws CoreException;
private void addToMap(Map map, int idx, String path, Object thing) {
List[] lists= (List[]) map.get(path);
private void addToMap(Map map, int idx, IIndexFileLocation location, Object thing) {
List[] lists= (List[]) map.get(location);
if (lists != null)
lists[idx].add(thing);
}
private boolean prepareInMap(Map map, String path) {
if (map.get(path) == null) {
private boolean prepareInMap(Map map, IIndexFileLocation location) {
if (map.get(location) == null) {
Object lists= new ArrayList[]{new ArrayList(), new ArrayList(), new ArrayList()};
map.put(path, lists);
map.put(location, lists);
}
return false;
}
private IIndexFragmentFile addToIndex(IWritableIndex index, String location, Map symbolMap) throws CoreException {
// Remove the old symbols in the tu
Path path= new Path(location);
IIndexFragmentFile file= (IIndexFragmentFile) index.getFile(path);
private IIndexFragmentFile addToIndex(IWritableIndex index, IIndexFileLocation location, Map symbolMap) throws CoreException {
IIndexFragmentFile file= (IIndexFragmentFile) index.getFile(location);
if (file != null) {
index.clearFile(file);
} else {
file= index.addFile(location);
}
else {
file= index.addFile(path);
}
file.setTimestamp(path.toFile().lastModified());
file.setTimestamp(EFS.getStore(location.getURI()).fetchInfo().getLastModified());
ArrayList[] lists= (ArrayList[]) symbolMap.get(location);
if (lists != null) {
ArrayList list= lists[0];
@ -501,7 +495,11 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
list= lists[2];
IASTName[][] names= (IASTName[][]) list.toArray(new IASTName[list.size()][]);
index.setFileContent(file, includes, macros, names);
IIndexFileLocation[] includeLocations = new IIndexFileLocation[includes.length];
for(int i=0; i<includes.length; i++) {
includeLocations[i] = findLocation(includes[i].getPath());
}
index.setFileContent(file, includes, includeLocations, macros, names);
}
return file;
}
@ -527,4 +525,13 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
+ fProblemBindingCount + " problems."); //$NON-NLS-1$
}
}
protected IIndexFileLocation getIndexFileLocation(ITranslationUnit tu) {
if(tu.getResource()!=null)
return IndexLocationFactory.getWorkspaceIFL((IFile)tu.getResource());
else
return IndexLocationFactory.getExternalIFL(tu.getLocation());
}
protected abstract IIndexFileLocation findLocation(String absolutePath);
}

View file

@ -14,13 +14,17 @@
package org.eclipse.cdt.internal.core.pdom.indexer.fast;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMIndexer;
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.CodeReader;
@ -44,6 +48,7 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
protected final PDOMFastIndexer indexer;
protected IWritableIndex index;
protected IndexBasedCodeReaderFactory codeReaderFactory;
private Map/*<String,IIndexFileLocation>*/ iflCache;
public PDOMFastIndexerJob(PDOMFastIndexer indexer) throws CoreException {
this.indexer = indexer;
@ -51,13 +56,24 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
protected void setupIndexAndReaderFactory() throws CoreException {
this.index= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(indexer.getProject());
this.codeReaderFactory = new IndexBasedCodeReaderFactory(index);
}
this.iflCache = new HashMap/*<String,IIndexFileLocation>*/();
this.codeReaderFactory = new IndexBasedCodeReaderFactory(index, iflCache);
}
protected IIndexFileLocation findLocation(String absolutePath) {
IIndexFileLocation result = (IIndexFileLocation) iflCache.get(absolutePath);
if(result==null) {
result = IndexLocationFactory.getIFLExpensive(absolutePath);
iflCache.put(absolutePath, result);
}
return result;
}
protected void registerTUsInReaderFactory(Collection files) throws CoreException {
for (Iterator iter = files.iterator(); iter.hasNext();) {
ITranslationUnit tu = (ITranslationUnit) iter.next();
FileInfo info= codeReaderFactory.createFileInfo(tu);
IIndexFileLocation location = getIndexFileLocation(tu);
FileInfo info= codeReaderFactory.createFileInfo(location);
info.setRequested(true);
}
}
@ -111,13 +127,13 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
return 1;
}
protected boolean needToUpdate(String path) throws CoreException {
protected boolean needToUpdate(IIndexFileLocation location) throws CoreException {
// file is requested or is not yet indexed.
FileInfo info= codeReaderFactory.createFileInfo(path);
FileInfo info= codeReaderFactory.createFileInfo(location);
return info.isRequested() || info.fFile == null;
}
protected boolean postAddToIndex(String path, IIndexFile file) throws CoreException {
protected boolean postAddToIndex(IIndexFileLocation path, IIndexFile file) throws CoreException {
FileInfo info= codeReaderFactory.createFileInfo(path);
info.fFile= file;
if (info.isRequested()) {

View file

@ -22,6 +22,8 @@ import org.eclipse.cdt.core.dom.IPDOMIndexer;
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.index.IWritableIndex;
import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
@ -41,8 +43,9 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
protected final PDOMFullIndexer indexer;
protected IWritableIndex index= null;
private Map filePathsToParse= new HashMap();
private Map/*<IIndexFileLocation, Object>*/ filePathsToParse= new HashMap/*<IIndexFileLocation, Object>*/();
private Map/*<String, IIndexFileLocation>*/ iflCache = new HashMap/*<String, IIndexFileLocation>*/();
public PDOMFullIndexerJob(PDOMFullIndexer indexer) throws CoreException {
this.indexer = indexer;
}
@ -55,15 +58,23 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
this.index = ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(indexer.getProject());
}
protected void registerTUsInReaderFactory(Collection sources) throws CoreException {
filePathsToParse= new HashMap();
protected void registerTUsInReaderFactory(Collection/*<ITranslationUnit>*/ sources) throws CoreException {
filePathsToParse= new HashMap/*<IIndexFileLocation, Object>*/();
for (Iterator iter = sources.iterator(); iter.hasNext();) {
ITranslationUnit tu = (ITranslationUnit) iter.next();
filePathsToParse.put(tu.getLocation().toOSString(), REQUIRED);
filePathsToParse.put(getIndexFileLocation(tu), REQUIRED);
}
}
protected IIndexFileLocation findLocation(String absolutePath) {
IIndexFileLocation result = (IIndexFileLocation) iflCache.get(absolutePath);
if(result==null) {
result = IndexLocationFactory.getIFLExpensive(absolutePath);
iflCache.put(absolutePath, result);
}
return result;
}
protected void doParseTU(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException {
IPath path = tu.getLocation();
if (path == null) {
@ -87,18 +98,18 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
return 0;
}
protected boolean needToUpdate(String path) throws CoreException {
Object required= filePathsToParse.get(path);
protected boolean needToUpdate(IIndexFileLocation location) throws CoreException {
Object required= filePathsToParse.get(location);
if (required == null) {
required= MISSING;
filePathsToParse.put(path, required);
filePathsToParse.put(location, required);
}
return required != SKIP;
}
protected boolean postAddToIndex(String path, IIndexFile file) throws CoreException {
Object required= filePathsToParse.get(path);
filePathsToParse.put(path, SKIP);
protected boolean postAddToIndex(IIndexFileLocation location, IIndexFile file) throws CoreException {
Object required= filePathsToParse.get(location);
filePathsToParse.put(location, SKIP);
return required == REQUIRED;
}
}

View file

@ -34,8 +34,8 @@ class PDOMFullReindex extends PDOMFullIndexerJob {
long start = System.currentTimeMillis();
try {
boolean allFiles= getIndexAllFiles();
List sources= new ArrayList();
List headers= new ArrayList();
List/*<ITranslationUnit>*/ sources= new ArrayList/*<ITranslationUnit>*/();
List/*<ITranslationUnit>*/ headers= new ArrayList/*<ITranslationUnit>*/();
collectSources(indexer.getProject(), sources, allFiles ? headers : null, allFiles);
fTotalSourcesEstimate= sources.size() + headers.size();

View file

@ -124,7 +124,7 @@ public class CCodeFormatter extends CodeFormatter {
if (lineSeparator != null) {
this.preferences.line_separator = lineSeparator;
} else {
this.preferences.line_separator = System.getProperty("line.separator");
this.preferences.line_separator = System.getProperty("line.separator"); //$NON-NLS-1$
}
this.preferences.initial_indentation_level = indentationLevel;

View file

@ -22,6 +22,7 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
@ -62,7 +63,7 @@ public class BaseUITestCase extends BaseTestCase {
do {
index.acquireReadLock();
try {
IIndexFile pfile= index.getFile(file.getLocation());
IIndexFile pfile= index.getFile(IndexLocationFactory.getWorkspaceIFL(file));
if (pfile != null && pfile.getTimestamp() >= file.getLocalTimeStamp()) {
return;
}

View file

@ -70,6 +70,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)",
org.eclipse.help;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui.navigator;bundle-version="[3.2.0,4.0.0)",
com.ibm.icu;bundle-version="[3.4.0,4.0.0)",
org.eclipse.cdt.refactoring;bundle-version="[4.0.0,5.0.0)"
org.eclipse.cdt.refactoring;bundle-version="[4.0.0,5.0.0)",
org.eclipse.core.filesystem;bundle-version="[1.1.0,2.0.0)"
Eclipse-LazyStart: true
Bundle-RequiredExecutionEnvironment: J2SE-1.4

View file

@ -31,7 +31,9 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
@ -84,7 +86,7 @@ public class CHQueries {
ISourceReference sf = ((ISourceReference)element);
ITranslationUnit tu= sf.getTranslationUnit();
if (tu != null) {
IPath location= tu.getLocation();
IIndexFileLocation location= IndexLocationFactory.getIFL(tu);
if (location != null) {
IIndexFile file= index.getFile(location);
if (file != null) {

View file

@ -187,7 +187,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
try {
if (binding != null)
{
return getBindingQualifiedName(binding) + " - " + name.getFileName(); //$NON-NLS-1$
return getBindingQualifiedName(binding) + " - " + name.getFileLocation().getFileName(); //$NON-NLS-1$
}
else
return null;
@ -284,7 +284,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
fRequiredIncludes = new IRequiredInclude[selects.length];
List usings = new ArrayList(selects.length);
for (int i = 0; i < fRequiredIncludes.length; i++) {
IRequiredInclude include = getRequiredInclude(((DisplayName)selects[i]).getName().getFileName(), getTranslationUnit());
IRequiredInclude include = getRequiredInclude(((DisplayName)selects[i]).getName().getFileLocation().getFileName(), getTranslationUnit());
if (include != null) {
fRequiredIncludes[i] = include;
IIndexBinding binding = ((DisplayName)selects[i]).getBinding();
@ -309,8 +309,9 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
}
}
else if (pdomNames.size() == 1)
{
String fileName = ((DisplayName)pdomNames.get(0)).getName().getFileName();
{
// we should use the IIndexName.getLocation here rather than getFileLocation
String fileName = ((DisplayName)pdomNames.get(0)).getName().getFileLocation().getFileName();
fRequiredIncludes = new IRequiredInclude[] {getRequiredInclude(fileName, getTranslationUnit())};
IIndexBinding binding = ((DisplayName)pdomNames.get(0)).getBinding();

View file

@ -17,14 +17,15 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.swt.widgets.Display;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
@ -104,9 +105,9 @@ public class IBContentProvider extends AsyncTreeContentProvider {
for (int i = 0; i < includes.length; i++) {
IIndexInclude include = includes[i];
try {
Path includesPath = new Path(include.getIncludesLocation());
IPath includesPath = IndexLocationFactory.getAbsolutePath(include.getIncludesLocation());
if (fComputeIncludedBy) {
directiveFile= targetFile= new IBFile(tu.getCProject(), new Path(include.getIncludedByLocation()));
directiveFile= targetFile= new IBFile(tu.getCProject(), IndexLocationFactory.getAbsolutePath(include.getIncludesLocation()));
}
else {
targetFile= new IBFile(tu.getCProject(), includesPath);
@ -147,7 +148,7 @@ public class IBContentProvider extends AsyncTreeContentProvider {
private IIndexInclude[] findIncludedBy(IIndex index, ITranslationUnit tu, IProgressMonitor pm) {
try {
IPath location= tu.getLocation();
IIndexFileLocation location= IndexLocationFactory.getIFL(tu);
if (location != null) {
IIndexFile file= index.getFile(location);
if (file != null) {
@ -163,7 +164,7 @@ public class IBContentProvider extends AsyncTreeContentProvider {
public IIndexInclude[] findIncludesTo(IIndex index, ITranslationUnit tu, IProgressMonitor pm) {
try {
IPath location= tu.getLocation();
IIndexFileLocation location= IndexLocationFactory.getIFL(tu);
if (location != null) {
IIndexFile file= index.getFile(location);
if (file != null) {

View file

@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ISelection;
@ -27,6 +26,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.ui.CUIPlugin;
@ -75,23 +75,25 @@ public class OpenDefinitionAction extends IndexAction {
}
}
private void showInEditor(IIndexName name) throws CModelException, PartInitException {
IPath path = new Path(name.getFileName());
IEditorPart editor = EditorUtility.openInEditor(path, null);
if (editor != null && editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor)editor;
int nodeOffset = name.getNodeOffset();
int nodeLength = name.getNodeLength();
try {
if (nodeLength == -1) {
// This means the offset is actually a line number
IDocument document = textEditor.getDocumentProvider().getDocument(editor.getEditorInput());
nodeOffset = document.getLineOffset(nodeOffset);
nodeLength = document.getLineLength(nodeOffset);
}
textEditor.selectAndReveal(nodeOffset, nodeLength);
} catch (BadLocationException e) {
CUIPlugin.getDefault().log(e);
private void showInEditor(IIndexName name) throws CModelException, PartInitException, CoreException {
IPath path = IndexLocationFactory.getPath(name.getFile().getLocation());
if(path!=null) {
IEditorPart editor = EditorUtility.openInEditor(path, null);
if (editor != null && editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor)editor;
int nodeOffset = name.getNodeOffset();
int nodeLength = name.getNodeLength();
try {
if (nodeLength == -1) {
// This means the offset is actually a line number
IDocument document = textEditor.getDocumentProvider().getDocument(editor.getEditorInput());
nodeOffset = document.getLineOffset(nodeOffset);
nodeLength = document.getLineLength(nodeOffset);
}
textEditor.selectAndReveal(nodeOffset, nodeLength);
} catch (BadLocationException e) {
CUIPlugin.getDefault().log(e);
}
}
}
}

View file

@ -31,7 +31,7 @@ public class PDOMSearchElement {
public PDOMSearchElement(IIndexName name, IIndexBinding binding) throws CoreException {
this.binding= binding;
this.name = binding.getName();
filename = name.getFileName();
filename = name.getFileLocation().getFileName();
}
public int hashCode() {

View file

@ -18,7 +18,6 @@ import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.search.ui.ISearchQuery;
@ -30,6 +29,7 @@ import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.ui.CUIPlugin;
@ -121,14 +121,14 @@ public class PDOMSearchResult extends AbstractTextSearchResult implements IEdito
public IFile getFile(Object element) {
if (element instanceof IIndexName) {
IIndexName name = (IIndexName)element;
IPath path = new Path(name.getFileName());
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
if (files.length > 0)
return files[0];
else
return null;
} else
return null;
try {
IIndexFileLocation location = name.getFile().getLocation();
if(location.getFullPath()!=null) {
return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(location.getFullPath()));
}
} catch(CoreException ce) { /* fall-through to return null */ }
}
return null;
}
public String getLabel() {