forked from qt-creator/qt-creator
CppEditor: Consider namespaces in "extract function" quickfix
Fixes: QTCREATORBUG-23256 Change-Id: I99b1271907767c3607e35adb49bd4109f3eca18c Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -5125,6 +5125,34 @@ void CppEditorPlugin::test_quickfix_ExtractFunction_data()
|
|||||||
"{\n"
|
"{\n"
|
||||||
" extracted();\n"
|
" extracted();\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
|
QTest::newRow("class in namespace")
|
||||||
|
<< _("namespace NS {\n"
|
||||||
|
"class C {\n"
|
||||||
|
" void f(C &c);\n"
|
||||||
|
"};\n"
|
||||||
|
"}\n"
|
||||||
|
"void NS::C::f(NS::C &c)\n"
|
||||||
|
"{\n"
|
||||||
|
" @{start}C *c = &c;@{end}\n"
|
||||||
|
"}\n")
|
||||||
|
<< _("namespace NS {\n"
|
||||||
|
"class C {\n"
|
||||||
|
" void f(C &c);\n"
|
||||||
|
"\n"
|
||||||
|
"public:\n"
|
||||||
|
" void extracted(NS::C &c);\n" // TODO: Remove non-required qualification
|
||||||
|
"};\n"
|
||||||
|
"}\n"
|
||||||
|
"void NS::C::extracted(NS::C &c)\n"
|
||||||
|
"{\n"
|
||||||
|
" C *c = &c;\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"void NS::C::f(NS::C &c)\n"
|
||||||
|
"{\n"
|
||||||
|
" extracted(c);\n"
|
||||||
|
"}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorPlugin::test_quickfix_ExtractFunction()
|
void CppEditorPlugin::test_quickfix_ExtractFunction()
|
||||||
|
@@ -3438,12 +3438,17 @@ public:
|
|||||||
|
|
||||||
// Write class qualification, if any.
|
// Write class qualification, if any.
|
||||||
if (matchingClass) {
|
if (matchingClass) {
|
||||||
Class *current = matchingClass;
|
const Scope *current = matchingClass;
|
||||||
QVector<const Name *> classes{matchingClass->name()};
|
QVector<const Name *> classes{matchingClass->name()};
|
||||||
while (current->enclosingScope()->asClass()) {
|
while (current->enclosingScope()->asClass()) {
|
||||||
current = current->enclosingScope()->asClass();
|
current = current->enclosingScope()->asClass();
|
||||||
classes.prepend(current->name());
|
classes.prepend(current->name());
|
||||||
}
|
}
|
||||||
|
while (current->enclosingScope() && current->enclosingScope()->asNamespace()) {
|
||||||
|
current = current->enclosingScope()->asNamespace();
|
||||||
|
if (current->name())
|
||||||
|
classes.prepend(current->name());
|
||||||
|
}
|
||||||
for (const Name *n : classes) {
|
for (const Name *n : classes) {
|
||||||
const Name *name = rewriteName(n, &env, control);
|
const Name *name = rewriteName(n, &env, control);
|
||||||
funcDef.append(printer.prettyName(name));
|
funcDef.append(printer.prettyName(name));
|
||||||
|
Reference in New Issue
Block a user