1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 297686: Disambiguate class and namespace.

This commit is contained in:
Markus Schorn 2010-01-04 09:45:35 +00:00
parent 78e2f65d6d
commit 3849591e3a
2 changed files with 54 additions and 1 deletions

View file

@ -2125,4 +2125,47 @@ public class IndexBugsTests extends BaseTestCase {
index.releaseReadLock();
}
}
// // a.h
// class P {};
// // b.h
// namespace P {class C {};}
// // source1.cpp
// #include "a.h"
// P p;
// // source2.cpp
// #include "b.h"
// P::C c;
public void testDisambiguateClassVsNamespace_297686() throws Exception {
waitForIndexer();
String[] testData = getContentsForTest(4);
TestSourceReader.createFile(fCProject.getProject(), "a.h", testData[0]);
TestSourceReader.createFile(fCProject.getProject(), "b.h", testData[1]);
IFile s1= TestSourceReader.createFile(fCProject.getProject(), "s1.cpp", testData[2]);
IFile s2= TestSourceReader.createFile(fCProject.getProject(), "s2.cpp", testData[3]);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
indexManager.reindex(fCProject);
waitForIndexer();
IIndex index= indexManager.getIndex(fCProject);
index.acquireReadLock();
try {
IASTTranslationUnit tu = TestSourceReader.createIndexBasedAST(index, fCProject, s1);
IASTSimpleDeclaration sdecl= (IASTSimpleDeclaration) tu.getDeclarations()[0];
IVariable var= (IVariable) sdecl.getDeclarators()[0].getName().resolveBinding();
assertFalse(var.getType() instanceof IProblemBinding);
assertTrue(var.getType() instanceof ICPPClassType);
tu = TestSourceReader.createIndexBasedAST(index, fCProject, s2);
sdecl= (IASTSimpleDeclaration) tu.getDeclarations()[0];
var= (IVariable) sdecl.getDeclarators()[0].getName().resolveBinding();
assertFalse(var.getType() instanceof IProblemBinding);
assertTrue(var.getType() instanceof ICPPClassType);
} finally {
index.releaseReadLock();
}
}
}

View file

@ -1758,10 +1758,15 @@ public class CPPSemantics {
}
if (data.typesOnly) {
if (type != null)
if (type != null) {
if (obj instanceof ICPPNamespace && compareByRelevance(data, type, obj) < 0) {
return obj;
}
return type;
}
if (obj instanceof ICPPNamespace)
return obj;
return null;
}
@ -1780,6 +1785,11 @@ public class CPPSemantics {
}
if (obj != null) {
if (type != null && obj instanceof ICPPNamespace) {
if (compareByRelevance(data, type, obj) >= 0) {
return type;
}
}
return obj;
}
return type;