Commit 80a3caa3 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

CppTools: Fix completion for nested enums



Task-number: QTCREATORBUG-5456

Change-Id: I0bb4756e3cdf3c87a4c2b0fbfe6953faaa5e1c52
Reviewed-by: default avatarAndré Hartmann <aha_1980@gmx.de>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 1ce5b127
......@@ -2328,7 +2328,47 @@ void CppToolsPlugin::test_completion_class_declaration_inside_function_or_block_
QVERIFY(completions.contains(QLatin1String("m2")));
}
void CppToolsPlugin::test_completion_enum_inside_block_inside_function_QTCREATORBUG5456()
void CppToolsPlugin::test_completion_enum_inside_function()
{
const QByteArray source =
"void foo()\n"
"{\n"
" enum E { val1, val2, val3 };\n"
" @\n"
" // padding so we get the scope right\n"
"}\n"
;
CompletionTestCase test(source, "val");
const QStringList completions = test.getCompletions();
QCOMPARE(completions.size(), 3);
QVERIFY(completions.contains(QLatin1String("val1")));
QVERIFY(completions.contains(QLatin1String("val2")));
QVERIFY(completions.contains(QLatin1String("val3")));
}
void CppToolsPlugin::test_completion_anon_enum_inside_function()
{
const QByteArray source =
"void foo()\n"
"{\n"
" enum { val1, val2, val3 };\n"
" @\n"
" // padding so we get the scope right\n"
"}\n"
;
CompletionTestCase test(source, "val");
const QStringList completions = test.getCompletions();
QCOMPARE(completions.size(), 3);
QVERIFY(completions.contains(QLatin1String("val1")));
QVERIFY(completions.contains(QLatin1String("val2")));
QVERIFY(completions.contains(QLatin1String("val3")));
}
void CppToolsPlugin::test_completion_enum_inside_block_inside_function_cxx11_QTCREATORBUG5456()
{
const QByteArray source =
"void foo()\n"
......@@ -2351,7 +2391,7 @@ void CppToolsPlugin::test_completion_enum_inside_block_inside_function_QTCREATOR
QVERIFY(completions.contains(QLatin1String("e3")));
}
void CppToolsPlugin::test_completion_enum_inside_function_QTCREATORBUG5456()
void CppToolsPlugin::test_completion_enum_inside_function_cxx11_QTCREATORBUG5456()
{
const QByteArray source =
"void foo()\n"
......
......@@ -1342,10 +1342,14 @@ void CppCompletionAssistProcessor::globalCompletion(CPlusPlus::Scope *currentSco
ClassOrNamespace *currentBinding = 0;
for (Scope *scope = currentScope; scope; scope = scope->enclosingScope()) {
if (scope->isBlock()) {
if (Block *block = scope->asBlock()) {
if (ClassOrNamespace *binding = context.lookupType(scope)) {
for (unsigned i = 0; i < scope->memberCount(); ++i) {
Symbol *member = scope->memberAt(i);
if (member->isEnum()) {
if (ClassOrNamespace *b = binding->findBlock(block))
completeNamespace(b);
}
if (!member->name())
continue;
if (UsingNamespaceDirective *u = member->asUsingNamespaceDirective()) {
......
......@@ -163,8 +163,10 @@ private slots:
void test_completion_namespace_alias_inside_function_or_block_QTCREATORBUG166();
void test_completion_namespace_alias_inside_function_or_block_QTCREATORBUG166_data();
void test_completion_class_declaration_inside_function_or_block_QTCREATORBUG3620_static_member();
void test_completion_enum_inside_block_inside_function_QTCREATORBUG5456();
void test_completion_enum_inside_function_QTCREATORBUG5456();
void test_completion_enum_inside_function();
void test_completion_anon_enum_inside_function();
void test_completion_enum_inside_block_inside_function_cxx11_QTCREATORBUG5456();
void test_completion_enum_inside_function_cxx11_QTCREATORBUG5456();
void test_completion_template_parameter_defined_inside_scope_of_declaration_QTCREATORBUG9169_1();
void test_completion_template_parameter_defined_inside_scope_of_declaration_QTCREATORBUG9169_2();
......
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