Commit 359bc13e authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppEditor: Fix "Complete Switch Statement"

...if enum type is defined inside a class or namespace.

Task-number: QTCREATORBUG-12311
Change-Id: I71b64bbe9d419707b66caacd10550041efc1520c
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent d3c5fff6
......@@ -325,6 +325,50 @@ void CppEditorPlugin::test_quickfix_data()
"}\n"
);
// Checks: Enum type in class is found.
QTest::newRow("CompleteSwitchCaseStatement_enumTypeInClass")
<< CppQuickFixFactoryPtr(new CompleteSwitchCaseStatement) << _(
"struct C { enum EnumType { V1, V2 }; };\n"
"\n"
"void f(C::EnumType t) {\n"
" @switch (t) {\n"
" }\n"
"}\n"
) << _(
"struct C { enum EnumType { V1, V2 }; };\n"
"\n"
"void f(C::EnumType t) {\n"
" switch (t) {\n"
" case C::V1:\n"
" break;\n"
" case C::V2:\n"
" break;\n"
" }\n"
"}\n"
);
// Checks: Enum type in namespace is found.
QTest::newRow("CompleteSwitchCaseStatement_enumTypeInNamespace")
<< CppQuickFixFactoryPtr(new CompleteSwitchCaseStatement) << _(
"namespace N { enum EnumType { V1, V2 }; };\n"
"\n"
"void f(N::EnumType t) {\n"
" @switch (t) {\n"
" }\n"
"}\n"
) << _(
"namespace N { enum EnumType { V1, V2 }; };\n"
"\n"
"void f(N::EnumType t) {\n"
" switch (t) {\n"
" case N::V1:\n"
" break;\n"
" case N::V2:\n"
" break;\n"
" }\n"
"}\n"
);
// Checks: The missing enum value is added.
QTest::newRow("CompleteSwitchCaseStatement_oneValueMissing")
<< CppQuickFixFactoryPtr(new CompleteSwitchCaseStatement) << _(
......
......@@ -2293,6 +2293,8 @@ Enum *findEnum(const QList<LookupItem> &results, const LookupContext &ctxt)
if (ClassOrNamespace *con = ctxt.lookupType(namedType->name(), result.scope())) {
const QList<Enum *> enums = con->unscopedEnums();
const Name *referenceName = namedType->name();
if (const QualifiedNameId *qualifiedName = referenceName->asQualifiedNameId())
referenceName = qualifiedName->name();
foreach (Enum *e, enums) {
if (const Name *candidateName = e->name()) {
if (candidateName->match(referenceName))
......
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