summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2013-12-15 16:35:43 +0200
committerOrgad Shaneh <orgads@gmail.com>2014-01-21 14:06:16 +0100
commit80a3caa39626f3d57079e300008afda4a897dd6d (patch)
tree9558a2aaaea78af6a1af4ad8259e47539a3315b1
parent1ce5b1273a0c14cb4bb19f8a6c2ce206c8af318d (diff)
downloadqt-creator-80a3caa39626f3d57079e300008afda4a897dd6d.tar.gz
CppTools: Fix completion for nested enums
Task-number: QTCREATORBUG-5456 Change-Id: I0bb4756e3cdf3c87a4c2b0fbfe6953faaa5e1c52 Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
-rw-r--r--src/plugins/cpptools/cppcompletion_test.cpp44
-rw-r--r--src/plugins/cpptools/cppcompletionassist.cpp6
-rw-r--r--src/plugins/cpptools/cpptoolsplugin.h6
3 files changed, 51 insertions, 5 deletions
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index ff3f5c38b1..cc2dffd1ce 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -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"
diff --git a/src/plugins/cpptools/cppcompletionassist.cpp b/src/plugins/cpptools/cppcompletionassist.cpp
index 2c8878a24a..8d55943e95 100644
--- a/src/plugins/cpptools/cppcompletionassist.cpp
+++ b/src/plugins/cpptools/cppcompletionassist.cpp
@@ -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()) {
diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h
index 067c484bb5..2d82219aba 100644
--- a/src/plugins/cpptools/cpptoolsplugin.h
+++ b/src/plugins/cpptools/cpptoolsplugin.h
@@ -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();