1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix+Testcase for 192352, duplicates in 'Open Declaration'

This commit is contained in:
Markus Schorn 2007-06-15 08:23:10 +00:00
parent 33bf35f24f
commit 3025d9e338
2 changed files with 60 additions and 2 deletions

View file

@ -678,4 +678,46 @@ public class IndexBugsTests extends BaseTestCase {
fIndex.releaseReadLock();
}
}
// typedef struct {
// float fNumber;
// int iIdx;
// } StructA_T;
// #include "../__bugsTest__/common.h"
// StructA_T gvar1;
// #include "../__bugsTest__/common.h"
// StructA_T gvar2;
public void testFileInMultipleFragments_bug192352() throws Exception {
StringBuffer[] contents= getContentsForTest(3);
ICProject p2 = CProjectHelper.createCCProject("__bugsTest_2_", "bin", IPDOMManager.ID_FAST_INDEXER);
try {
IFile f3= TestSourceReader.createFile(p2.getProject(), "src.cpp", contents[2].toString());
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "common.h", contents[0].toString());
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1].toString());
waitForIndexer();
IIndex index= CCorePlugin.getIndexManager().getIndex(new ICProject[]{fCProject, p2});
index.acquireReadLock();
try {
IIndexBinding[] bindings= index.findBindings("StructA_T".toCharArray(), IndexFilter.ALL, NPM);
assertEquals(1, bindings.length);
IIndexBinding binding= bindings[0];
IIndexName[] names= index.findReferences(binding);
assertEquals(2, names.length);
names= index.findDeclarations(binding);
assertEquals(1, names.length);
}
finally {
index.releaseReadLock();
}
}
finally {
CProjectHelper.delete(p2);
}
}
}

View file

@ -116,11 +116,27 @@ public class CIndex implements IIndex {
}
public IIndexName[] findNames(IBinding binding, int flags) throws CoreException {
ArrayList result= new ArrayList();
LinkedList result= new LinkedList();
int fragCount= 0;
for (int i = 0; i < fPrimaryFragmentCount; i++) {
IIndexFragmentBinding adaptedBinding= fFragments[i].adaptBinding(binding);
if (adaptedBinding != null) {
result.addAll(Arrays.asList(fFragments[i].findNames(adaptedBinding, flags)));
final IIndexFragmentName[] names = fFragments[i].findNames(adaptedBinding, flags);
if (names.length > 0) {
result.addAll(Arrays.asList(names));
fragCount++;
}
}
}
// bug 192352, files can reside in multipe fragments, remove duplicates
if (fragCount > 1) {
HashSet keys= new HashSet();
for (Iterator iterator = result.iterator(); iterator.hasNext();) {
final IIndexFragmentName name = (IIndexFragmentName) iterator.next();
final String key= name.getFile().getLocation().getURI().toString() + name.getNodeOffset();
if (!keys.add(key)) {
iterator.remove();
}
}
}
return (IIndexName[]) result.toArray(new IIndexName[result.size()]);