mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Testcase for search in unnamed namespace.
This commit is contained in:
parent
ff384fe5c5
commit
b202de6bec
3 changed files with 50 additions and 4 deletions
|
@ -144,8 +144,14 @@ public class IndexSearchTest extends BaseTestCase {
|
|||
bindings= fIndex.findBindings(new Pattern[]{pns, pns, pcl}, false, INDEX_FILTER, NPM);
|
||||
assertEquals(1, bindings.length);
|
||||
checkIsClass(bindings[0]);
|
||||
}
|
||||
|
||||
public void testFindNamespaceInNamespace() throws CoreException {
|
||||
Pattern pcl= Pattern.compile("C160913");
|
||||
Pattern pns= Pattern.compile("ns160913");
|
||||
|
||||
IIndexBinding[] bindings;
|
||||
|
||||
// same with namespace
|
||||
bindings= fIndex.findBindings(pns, true, INDEX_FILTER, NPM);
|
||||
assertEquals(1, bindings.length);
|
||||
checkIsNamespace(bindings[0]);
|
||||
|
@ -164,6 +170,26 @@ public class IndexSearchTest extends BaseTestCase {
|
|||
checkIsNamespace(bindings[0]);
|
||||
}
|
||||
|
||||
public void testClassInUnnamedNamespace1() throws CoreException {
|
||||
Pattern pcl= Pattern.compile("CInUnnamed160913");
|
||||
|
||||
IIndexBinding[] bindings;
|
||||
|
||||
bindings= fIndex.findBindings(pcl, false, INDEX_FILTER, NPM);
|
||||
assertEquals(1, bindings.length);
|
||||
checkIsClass(bindings[0]);
|
||||
}
|
||||
|
||||
public void _testClassInUnnamedNamespace2() throws CoreException {
|
||||
Pattern pcl= Pattern.compile("CInUnnamed160913");
|
||||
|
||||
IIndexBinding[] bindings;
|
||||
|
||||
// the binding in the unnamed namespace is not visible in global scope.
|
||||
bindings= fIndex.findBindings(pcl, true, INDEX_FILTER, NPM);
|
||||
assertEquals(0, bindings.length);
|
||||
}
|
||||
|
||||
public void testFindEnumerator() throws CoreException {
|
||||
Pattern pEnumeration= Pattern.compile("E20061017");
|
||||
Pattern pEnumerator= Pattern.compile("e20061017");
|
||||
|
|
|
@ -7,3 +7,7 @@ namespace ns160913 {
|
|||
class C160913{};
|
||||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
class CInUnnamed160913{};
|
||||
};
|
|
@ -24,9 +24,9 @@ import org.eclipse.cdt.core.dom.ast.IPointerType;
|
|||
import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexLinkage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.BTree;
|
||||
|
@ -102,7 +102,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
getIndex().accept(new IBTreeVisitor() {
|
||||
public int compare(int record) throws CoreException {
|
||||
return 1;
|
||||
};
|
||||
}
|
||||
public boolean visit(int record) throws CoreException {
|
||||
PDOMBinding binding = pdom.getBinding(record);
|
||||
if (binding != null) {
|
||||
|
@ -111,7 +111,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
visitor.leave(binding);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -162,6 +162,22 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
}
|
||||
|
||||
// the scope is from the ast
|
||||
|
||||
// mstodo revisit unnamed namespaces
|
||||
IScope testScope= scope;
|
||||
while (testScope instanceof ICPPNamespaceScope) {
|
||||
IName name= testScope.getScopeName();
|
||||
if (name != null && name.toCharArray().length == 0) {
|
||||
testScope= scope.getParent();
|
||||
if (testScope != null) {
|
||||
scope= testScope;
|
||||
}
|
||||
}
|
||||
else {
|
||||
testScope= null;
|
||||
}
|
||||
}
|
||||
|
||||
IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope);
|
||||
if (scopeNode instanceof IASTCompoundStatement)
|
||||
return null;
|
||||
|
|
Loading…
Add table
Reference in a new issue