Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2010-01-04 09:45:45 +0000
committerMarkus Schorn2010-01-04 09:45:45 +0000
commit7cbd3a3e0154a6e3eff27567ff4e72062953c6bb (patch)
tree4d05ca1671ce2b3132e4ecd7f65c71c357e186dd
parent1d531b4d2f952a66171a46701d307040a974a256 (diff)
downloadorg.eclipse.cdt-7cbd3a3e0154a6e3eff27567ff4e72062953c6bb.tar.gz
org.eclipse.cdt-7cbd3a3e0154a6e3eff27567ff4e72062953c6bb.tar.xz
org.eclipse.cdt-7cbd3a3e0154a6e3eff27567ff4e72062953c6bb.zip
Bug 297686: Disambiguate class and namespace.
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java43
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java12
2 files changed, 54 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java
index f18f9bf7799..866a3ec3260 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java
@@ -2180,4 +2180,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();
+ }
+ }
+
} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
index 0835131cb08..bcd75eaa3ca 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
@@ -1913,10 +1913,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;
}
@@ -1935,6 +1940,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;

Back to the top