Commit eb30ab66 authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Erik Verbruggen

C++: fixed code completion for namespace aliases

Task-number: QTCREATORBUG-166

Change-Id: I7a19065a57bfb943e5fc4e2bd9bd81988c1175e3
Reviewed-by: default avatarSergey Shambir <sergey.shambir.auto@gmail.com>
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent bde66672
......@@ -641,7 +641,8 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope,
if (s->asNamespaceAlias() && binding) {
ClassOrNamespace *targetNamespaceBinding = binding->lookupType(name);
if (targetNamespaceBinding && targetNamespaceBinding->symbols().size() == 1) {
//there can be many namespace definitions
if (targetNamespaceBinding && targetNamespaceBinding->symbols().size() > 0) {
Symbol *resolvedSymbol = targetNamespaceBinding->symbols().first();
item.setType(resolvedSymbol->type()); // override the type
}
......
......@@ -1751,3 +1751,50 @@ void CppToolsPlugin::test_completion_typedef_using_templates2()
QVERIFY(completions.contains(QLatin1String("Foo")));
QVERIFY(completions.contains(QLatin1String("bar")));
}
void CppToolsPlugin::test_completion_namespace_alias_with_many_namespace_declarations()
{
TestData data;
data.srcText =
"namespace NS1\n"
"{\n"
"namespace NS2\n"
"{\n"
"struct Foo1\n"
"{\n"
" int bar1;\n"
"};\n"
"}\n"
"}\n"
"namespace NS1\n"
"{\n"
"namespace NS2\n"
"{\n"
"struct Foo2\n"
"{\n"
" int bar2;\n"
"};\n"
"}\n"
"}\n"
"namespace NS = NS1::NS2;\n"
"int main()\n"
"{\n"
" @\n"
" // padding so we get the scope right\n"
"}\n"
;
setup(&data);
Utils::ChangeSet change;
QString txt = QLatin1String("NS::");
change.insert(data.pos, txt);
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += txt.length();
QStringList completions = getCompletions(data);
QCOMPARE(completions.size(), 2);
QVERIFY(completions.contains(QLatin1String("Foo1")));
QVERIFY(completions.contains(QLatin1String("Foo2")));
}
......@@ -517,7 +517,9 @@ public:
BasicProposalItem *operator()(Symbol *symbol)
{
if (! symbol || ! symbol->name() || symbol->name()->isQualifiedNameId())
//using declaration can be qualified
if (! symbol || ! symbol->name() || (symbol->name()->isQualifiedNameId()
&& ! symbol->asUsingDeclaration()))
return 0;
BasicProposalItem *previousItem = switchCompletionItem(0);
......
......@@ -126,6 +126,7 @@ private slots:
void test_completion_template_specialization_with_pointer();
void test_completion_typedef_using_templates1();
void test_completion_typedef_using_templates2();
void test_completion_namespace_alias_with_many_namespace_declarations();
void test_format_pointerdeclaration_in_simpledeclarations();
void test_format_pointerdeclaration_in_simpledeclarations_data();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment