mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
186214: apply fix for linked IndexFileLocation ambiguity resolution
This commit is contained in:
parent
e655142a3a
commit
8435a65ac8
9 changed files with 53 additions and 20 deletions
|
@ -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) {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 {
|
|||
* <p>
|
||||
* 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<files.length; i++) {
|
||||
if(files[i].getProject().equals(cproject.getProject()))
|
||||
return getWorkspaceIFL(files[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new IndexFileLocation(URIUtil.toURI(absolutePath), null);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ 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.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
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 */
|
||||
private ICodeReaderFactory fFallBackFactory;
|
||||
private CallbackHandler fCallbackHandler;
|
||||
private final ICProject cproject;
|
||||
|
||||
|
||||
public IndexBasedCodeReaderFactory(IIndex index) {
|
||||
this(index, new HashMap/*<String,IIndexFileLocation>*/());
|
||||
public IndexBasedCodeReaderFactory(ICProject cproject, IIndex index) {
|
||||
this(cproject, index, new HashMap/*<String,IIndexFileLocation>*/());
|
||||
}
|
||||
|
||||
public IndexBasedCodeReaderFactory(IIndex index, ICodeReaderFactory fallbackFactory) {
|
||||
this(index, new HashMap/*<String,IIndexFileLocation>*/(), fallbackFactory);
|
||||
public IndexBasedCodeReaderFactory(ICProject cproject, IIndex index, ICodeReaderFactory fallbackFactory) {
|
||||
this(cproject, index, new HashMap/*<String,IIndexFileLocation>*/(), 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/*<IIndexFileLocation,FileInfo>*/();
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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/*<String,IIndexFileLocation>*/(), fallbackFactory);
|
||||
super(null, index, new HashMap/*<String,IIndexFileLocation>*/(), fallbackFactory);
|
||||
}
|
||||
|
||||
public StandaloneIndexBasedCodeReaderFactory(IIndex index, Map iflCache) {
|
||||
super(index, iflCache, new DefaultFallBackFactory());
|
||||
super(null, index, iflCache, new DefaultFallBackFactory());
|
||||
}
|
||||
|
||||
public IIndexFileLocation findLocation(String absolutePath) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -107,7 +107,7 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler {
|
|||
fIndex= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject());
|
||||
fIndex.resetCacheCounters();
|
||||
fIflCache = new HashMap/*<String,IIndexFileLocation>*/();
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue