From 8435a65ac89703f5fe383fbcbe0b2ace2a6c99f2 Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Thu, 10 May 2007 14:24:54 +0000 Subject: [PATCH] 186214: apply fix for linked IndexFileLocation ambiguity resolution --- .../tests/IndexBindingResolutionTestBase.java | 6 ++++- .../index/tests/IndexLocationTest.java | 2 +- .../internal/core/model/TranslationUnit.java | 4 +-- .../cdt/core/index/IndexLocationFactory.java | 19 +++++++++++++- .../index/IndexBasedCodeReaderFactory.java | 26 ++++++++++++------- ...StandaloneIndexBasedCodeReaderFactory.java | 6 ++--- .../core/pdom/indexer/PDOMIndexerTask.java | 4 +++ .../indexer/fast/PDOMFastIndexerTask.java | 4 +-- .../indexer/full/PDOMFullIndexerTask.java | 2 +- 9 files changed, 53 insertions(+), 20 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java index 9664e3d0f64..0cfb991d6f2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java @@ -69,15 +69,19 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { protected ITestStrategy strategy; public void setStrategy(ITestStrategy strategy) { - this.strategy = strategy; + if(this.strategy==null) { + this.strategy = strategy; + } } protected void setUp() throws Exception { + super.setUp(); strategy.setUp(); } protected void tearDown() throws Exception { strategy.tearDown(); + super.tearDown(); } protected IASTName[] findNames(String section, int len) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java index f9382faed5b..697a753927a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java @@ -177,7 +177,7 @@ public class IndexLocationTest extends BaseTestCase { } } - public void _testSameFileLinkedToOnceInTwoProjects_186214() throws Exception { + public void testSameFileLinkedToOnceInTwoProjects_186214() throws Exception { File location = new File(CProjectHelper.freshDir(),"external2.h"); createExternalFile(location, "struct External {};\n"); IFolder content= cproject.getProject().getFolder("content"); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java index 055c7011974..9c13f8ce4ed 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java @@ -747,7 +747,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { codeReaderFactory= SavedCodeReaderFactory.getInstance(); } if (index != null && (style & ITranslationUnit.AST_SKIP_INDEXED_HEADERS) != 0) { - codeReaderFactory= new IndexBasedCodeReaderFactory(index, codeReaderFactory); + codeReaderFactory= new IndexBasedCodeReaderFactory(getCProject(), index, codeReaderFactory); } IScannerInfo scanInfo = getScannerInfo( (style & ITranslationUnit.AST_SKIP_IF_NO_BUILD_INFO) == 0); @@ -786,7 +786,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { } else { fallbackFactory= SavedCodeReaderFactory.getInstance(); } - codeReaderFactory= new IndexBasedCodeReaderFactory(index, fallbackFactory); + codeReaderFactory= new IndexBasedCodeReaderFactory(getCProject(), index, fallbackFactory); } else { codeReaderFactory = SavedCodeReaderFactory.getInstance(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexLocationFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexLocationFactory.java index e974f1f7a31..a47f2301d21 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexLocationFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexLocationFactory.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.core.index; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.core.index.IndexFileLocation; import org.eclipse.core.filesystem.URIUtil; @@ -62,6 +63,14 @@ public class IndexLocationFactory { return URIUtil.toPath(location.getURI()); } + /** + * Equivalent to the overloaded form with the ICProject parameter set to null + * @see IndexLocationFactory#getIFLExpensive(ICProject, String) + */ + public static IIndexFileLocation getIFLExpensive(String absolutePath) { + return getIFLExpensive(null, absolutePath); + } + /** * Returns an IIndexFileLocation by searching the workspace for resources that are mapped * onto the specified absolute path. @@ -73,13 +82,21 @@ public class IndexLocationFactory { *

* N.B. As this searches the workspace, following links and potentially reading from alternate * file systems, this method may be expensive. + * @param cproject the ICProject to prefer when resolving external includes to workspace resources (may be null) * @param absolutePath * @return an IIndexFileLocation for the specified resource, containing a workspace relative path if possible. */ - public static IIndexFileLocation getIFLExpensive(String absolutePath) { + public static IIndexFileLocation getIFLExpensive(ICProject cproject, String absolutePath) { IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(absolutePath)); if(files.length==1) { return getWorkspaceIFL(files[0]); + } else { + if(cproject!=null) { + for(int i=0; i*/()); + public IndexBasedCodeReaderFactory(ICProject cproject, IIndex index) { + this(cproject, index, new HashMap/**/()); } - public IndexBasedCodeReaderFactory(IIndex index, ICodeReaderFactory fallbackFactory) { - this(index, new HashMap/**/(), fallbackFactory); + public IndexBasedCodeReaderFactory(ICProject cproject, IIndex index, ICodeReaderFactory fallbackFactory) { + this(cproject, index, new HashMap/**/(), fallbackFactory); } - public IndexBasedCodeReaderFactory(IIndex index, Map iflCache) { - this(index, iflCache, null); + public IndexBasedCodeReaderFactory(ICProject cproject, IIndex index, Map iflCache) { + this(cproject, index, iflCache, null); } - public IndexBasedCodeReaderFactory(IIndex index, Map iflCache, ICodeReaderFactory fallbackFactory) { + /** + * @param cproject the ICProject to prefer when resolving external includes to workspace resources (may be null) + * @param index the IIndex that backs this code reader + * @param iflCache + * @param fallbackFactory + */ + public IndexBasedCodeReaderFactory(ICProject cproject, IIndex index, Map iflCache, ICodeReaderFactory fallbackFactory) { + this.cproject= cproject; this.index = index; this.fileInfoCache = new HashMap/**/(); this.iflCache = iflCache; @@ -249,7 +257,7 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory { public IIndexFileLocation findLocation(String absolutePath) { if(!iflCache.containsKey(absolutePath)) { - iflCache.put(absolutePath, IndexLocationFactory.getIFLExpensive(absolutePath)); + iflCache.put(absolutePath, IndexLocationFactory.getIFLExpensive(cproject, absolutePath)); } return (IIndexFileLocation) iflCache.get(absolutePath); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexBasedCodeReaderFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexBasedCodeReaderFactory.java index b2a8a907b1c..8ec8b5e4b33 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexBasedCodeReaderFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexBasedCodeReaderFactory.java @@ -73,15 +73,15 @@ public class StandaloneIndexBasedCodeReaderFactory extends IndexBasedCodeReaderF } public StandaloneIndexBasedCodeReaderFactory(IIndex index) { - super(index); + super(null, index); } public StandaloneIndexBasedCodeReaderFactory(IIndex index, ICodeReaderFactory fallbackFactory) { - super(index, new HashMap/**/(), fallbackFactory); + super(null, index, new HashMap/**/(), fallbackFactory); } public StandaloneIndexBasedCodeReaderFactory(IIndex index, Map iflCache) { - super(index, iflCache, new DefaultFallBackFactory()); + super(null, index, iflCache, new DefaultFallBackFactory()); } public IIndexFileLocation findLocation(String absolutePath) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java index aad65400013..a5ae464ce7c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java @@ -561,4 +561,8 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer private static int addToHashcode(int result, String key) { return result*31 + key.hashCode(); } + + protected ICProject getCProject() { + return fIndexer.project; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerTask.java index 68b2e38fc12..0b6827d76fc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerTask.java @@ -107,7 +107,7 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler { fIndex= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject()); fIndex.resetCacheCounters(); fIflCache = new HashMap/**/(); - fCodeReaderFactory = new IndexBasedCodeReaderFactory(fIndex, fIflCache); + fCodeReaderFactory = new IndexBasedCodeReaderFactory(getCProject(), fIndex, fIflCache); fCodeReaderFactory.setCallbackHandler(this); } @@ -137,7 +137,7 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler { protected IIndexFileLocation findLocation(String absolutePath) { IIndexFileLocation result = (IIndexFileLocation) fIflCache.get(absolutePath); if(result==null) { - result = IndexLocationFactory.getIFLExpensive(absolutePath); + result = IndexLocationFactory.getIFLExpensive(getCProject(), absolutePath); fIflCache.put(absolutePath, result); } return result; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerTask.java index 44332fcd02e..bc19460b6ae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerTask.java @@ -143,7 +143,7 @@ class PDOMFullIndexerTask extends PDOMIndexerTask { protected IIndexFileLocation findLocation(String absolutePath) { IIndexFileLocation result = (IIndexFileLocation) fIflCache.get(absolutePath); if(result==null) { - result = IndexLocationFactory.getIFLExpensive(absolutePath); + result = IndexLocationFactory.getIFLExpensive(getCProject(), absolutePath); fIflCache.put(absolutePath, result); } return result;