1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-18 06:25:23 +02:00

186214: apply fix for linked IndexFileLocation ambiguity resolution

This commit is contained in:
Andrew Ferguson 2007-05-10 14:24:54 +00:00
parent e655142a3a
commit 8435a65ac8
9 changed files with 53 additions and 20 deletions

View file

@ -69,15 +69,19 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
protected ITestStrategy strategy; protected ITestStrategy strategy;
public void setStrategy(ITestStrategy strategy) { public void setStrategy(ITestStrategy strategy) {
this.strategy = strategy; if(this.strategy==null) {
this.strategy = strategy;
}
} }
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp();
strategy.setUp(); strategy.setUp();
} }
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
strategy.tearDown(); strategy.tearDown();
super.tearDown();
} }
protected IASTName[] findNames(String section, int len) { protected IASTName[] findNames(String section, int len) {

View file

@ -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"); File location = new File(CProjectHelper.freshDir(),"external2.h");
createExternalFile(location, "struct External {};\n"); createExternalFile(location, "struct External {};\n");
IFolder content= cproject.getProject().getFolder("content"); IFolder content= cproject.getProject().getFolder("content");

View file

@ -747,7 +747,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
codeReaderFactory= SavedCodeReaderFactory.getInstance(); codeReaderFactory= SavedCodeReaderFactory.getInstance();
} }
if (index != null && (style & ITranslationUnit.AST_SKIP_INDEXED_HEADERS) != 0) { 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); IScannerInfo scanInfo = getScannerInfo( (style & ITranslationUnit.AST_SKIP_IF_NO_BUILD_INFO) == 0);
@ -786,7 +786,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} else { } else {
fallbackFactory= SavedCodeReaderFactory.getInstance(); fallbackFactory= SavedCodeReaderFactory.getInstance();
} }
codeReaderFactory= new IndexBasedCodeReaderFactory(index, fallbackFactory); codeReaderFactory= new IndexBasedCodeReaderFactory(getCProject(), index, fallbackFactory);
} }
else { else {
codeReaderFactory = SavedCodeReaderFactory.getInstance(); codeReaderFactory = SavedCodeReaderFactory.getInstance();

View file

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.index; package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.index.IndexFileLocation; import org.eclipse.cdt.internal.core.index.IndexFileLocation;
import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.filesystem.URIUtil;
@ -62,6 +63,14 @@ public class IndexLocationFactory {
return URIUtil.toPath(location.getURI()); 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 * Returns an IIndexFileLocation by searching the workspace for resources that are mapped
* onto the specified absolute path. * onto the specified absolute path.
@ -73,13 +82,21 @@ public class IndexLocationFactory {
* <p> * <p>
* N.B. As this searches the workspace, following links and potentially reading from alternate * N.B. As this searches the workspace, following links and potentially reading from alternate
* file systems, this method may be expensive. * 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 * @param absolutePath
* @return an IIndexFileLocation for the specified resource, containing a workspace relative path if possible. * @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)); IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(absolutePath));
if(files.length==1) { if(files.length==1) {
return getWorkspaceIFL(files[0]); return getWorkspaceIFL(files[0]);
} else {
if(cproject!=null) {
for(int i=0; i<files.length; i++) {
if(files[i].getProject().equals(cproject.getProject()))
return getWorkspaceIFL(files[i]);
}
}
} }
return new IndexFileLocation(URIUtil.toURI(absolutePath), null); return new IndexFileLocation(URIUtil.toURI(absolutePath), null);
} }

View file

@ -34,6 +34,7 @@ import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude; import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.ICodeReaderCache; import org.eclipse.cdt.core.parser.ICodeReaderCache;
import org.eclipse.cdt.core.parser.IMacro; import org.eclipse.cdt.core.parser.IMacro;
@ -76,21 +77,28 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
/** The fallback code reader factory used in case a header file is not indexed */ /** The fallback code reader factory used in case a header file is not indexed */
private ICodeReaderFactory fFallBackFactory; private ICodeReaderFactory fFallBackFactory;
private CallbackHandler fCallbackHandler; private CallbackHandler fCallbackHandler;
private final ICProject cproject;
public IndexBasedCodeReaderFactory(ICProject cproject, IIndex index) {
public IndexBasedCodeReaderFactory(IIndex index) { this(cproject, index, new HashMap/*<String,IIndexFileLocation>*/());
this(index, new HashMap/*<String,IIndexFileLocation>*/());
} }
public IndexBasedCodeReaderFactory(IIndex index, ICodeReaderFactory fallbackFactory) { public IndexBasedCodeReaderFactory(ICProject cproject, IIndex index, ICodeReaderFactory fallbackFactory) {
this(index, new HashMap/*<String,IIndexFileLocation>*/(), fallbackFactory); this(cproject, index, new HashMap/*<String,IIndexFileLocation>*/(), fallbackFactory);
} }
public IndexBasedCodeReaderFactory(IIndex index, Map iflCache) { public IndexBasedCodeReaderFactory(ICProject cproject, IIndex index, Map iflCache) {
this(index, iflCache, null); 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.index = index;
this.fileInfoCache = new HashMap/*<IIndexFileLocation,FileInfo>*/(); this.fileInfoCache = new HashMap/*<IIndexFileLocation,FileInfo>*/();
this.iflCache = iflCache; this.iflCache = iflCache;
@ -249,7 +257,7 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
public IIndexFileLocation findLocation(String absolutePath) { public IIndexFileLocation findLocation(String absolutePath) {
if(!iflCache.containsKey(absolutePath)) { if(!iflCache.containsKey(absolutePath)) {
iflCache.put(absolutePath, IndexLocationFactory.getIFLExpensive(absolutePath)); iflCache.put(absolutePath, IndexLocationFactory.getIFLExpensive(cproject, absolutePath));
} }
return (IIndexFileLocation) iflCache.get(absolutePath); return (IIndexFileLocation) iflCache.get(absolutePath);
} }

View file

@ -73,15 +73,15 @@ public class StandaloneIndexBasedCodeReaderFactory extends IndexBasedCodeReaderF
} }
public StandaloneIndexBasedCodeReaderFactory(IIndex index) { public StandaloneIndexBasedCodeReaderFactory(IIndex index) {
super(index); super(null, index);
} }
public StandaloneIndexBasedCodeReaderFactory(IIndex index, ICodeReaderFactory fallbackFactory) { public StandaloneIndexBasedCodeReaderFactory(IIndex index, ICodeReaderFactory fallbackFactory) {
super(index, new HashMap/*<String,IIndexFileLocation>*/(), fallbackFactory); super(null, index, new HashMap/*<String,IIndexFileLocation>*/(), fallbackFactory);
} }
public StandaloneIndexBasedCodeReaderFactory(IIndex index, Map iflCache) { public StandaloneIndexBasedCodeReaderFactory(IIndex index, Map iflCache) {
super(index, iflCache, new DefaultFallBackFactory()); super(null, index, iflCache, new DefaultFallBackFactory());
} }
public IIndexFileLocation findLocation(String absolutePath) { public IIndexFileLocation findLocation(String absolutePath) {

View file

@ -561,4 +561,8 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
private static int addToHashcode(int result, String key) { private static int addToHashcode(int result, String key) {
return result*31 + key.hashCode(); return result*31 + key.hashCode();
} }
protected ICProject getCProject() {
return fIndexer.project;
}
} }

View file

@ -107,7 +107,7 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler {
fIndex= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject()); fIndex= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject());
fIndex.resetCacheCounters(); fIndex.resetCacheCounters();
fIflCache = new HashMap/*<String,IIndexFileLocation>*/(); fIflCache = new HashMap/*<String,IIndexFileLocation>*/();
fCodeReaderFactory = new IndexBasedCodeReaderFactory(fIndex, fIflCache); fCodeReaderFactory = new IndexBasedCodeReaderFactory(getCProject(), fIndex, fIflCache);
fCodeReaderFactory.setCallbackHandler(this); fCodeReaderFactory.setCallbackHandler(this);
} }
@ -137,7 +137,7 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler {
protected IIndexFileLocation findLocation(String absolutePath) { protected IIndexFileLocation findLocation(String absolutePath) {
IIndexFileLocation result = (IIndexFileLocation) fIflCache.get(absolutePath); IIndexFileLocation result = (IIndexFileLocation) fIflCache.get(absolutePath);
if(result==null) { if(result==null) {
result = IndexLocationFactory.getIFLExpensive(absolutePath); result = IndexLocationFactory.getIFLExpensive(getCProject(), absolutePath);
fIflCache.put(absolutePath, result); fIflCache.put(absolutePath, result);
} }
return result; return result;

View file

@ -143,7 +143,7 @@ class PDOMFullIndexerTask extends PDOMIndexerTask {
protected IIndexFileLocation findLocation(String absolutePath) { protected IIndexFileLocation findLocation(String absolutePath) {
IIndexFileLocation result = (IIndexFileLocation) fIflCache.get(absolutePath); IIndexFileLocation result = (IIndexFileLocation) fIflCache.get(absolutePath);
if(result==null) { if(result==null) {
result = IndexLocationFactory.getIFLExpensive(absolutePath); result = IndexLocationFactory.getIFLExpensive(getCProject(), absolutePath);
fIflCache.put(absolutePath, result); fIflCache.put(absolutePath, result);
} }
return result; return result;