forked from qt-creator/qt-creator
CppEditor: Fix moving function definition out of specialized class
Fixes: QTCREATORBUG-25808 Change-Id: I5950c7f66b736c6ee30411e8fdc0356d78faa518 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -389,18 +389,22 @@ void TypePrettyPrinter::visit(Function *type)
|
||||
for (Scope *s = type->enclosingScope(); s && i >= 0; s = s->enclosingScope()) {
|
||||
if (Template *templ = s->asTemplate()) {
|
||||
QString &n = nameParts[i];
|
||||
n += '<';
|
||||
for (int index = 0; index < templ->templateParameterCount(); ++index) {
|
||||
if (index)
|
||||
n += QLatin1String(", ");
|
||||
QString arg = _overview->prettyName(templ->templateParameterAt(index)->name());
|
||||
if (arg.isEmpty()) {
|
||||
arg += 'T';
|
||||
arg += QString::number(index + 1);
|
||||
const int paramCount = templ->templateParameterCount();
|
||||
if (paramCount > 0) {
|
||||
n += '<';
|
||||
for (int index = 0; index < paramCount; ++index) {
|
||||
if (index)
|
||||
n += QLatin1String(", ");
|
||||
QString arg = _overview->prettyName(
|
||||
templ->templateParameterAt(index)->name());
|
||||
if (arg.isEmpty()) {
|
||||
arg += 'T';
|
||||
arg += QString::number(index + 1);
|
||||
}
|
||||
n += arg;
|
||||
}
|
||||
n += arg;
|
||||
n += '>';
|
||||
}
|
||||
n += '>';
|
||||
}
|
||||
if (s->identifier())
|
||||
--i;
|
||||
@@ -435,7 +439,8 @@ void TypePrettyPrinter::visit(Function *type)
|
||||
if (_overview->showEnclosingTemplate) {
|
||||
if (Template *templ = type->enclosingTemplate()) {
|
||||
QString templateScope = "template<";
|
||||
for (int i = 0, total = templ->templateParameterCount(); i < total; ++i) {
|
||||
const int paramCount = templ->templateParameterCount();
|
||||
for (int i = 0; i < paramCount; ++i) {
|
||||
if (Symbol *param = templ->templateParameterAt(i)) {
|
||||
if (i > 0)
|
||||
templateScope.append(", ");
|
||||
@@ -452,7 +457,8 @@ void TypePrettyPrinter::visit(Function *type)
|
||||
}
|
||||
}
|
||||
}
|
||||
_text.prepend(templateScope + ">\n");
|
||||
if (paramCount > 0)
|
||||
_text.prepend(templateScope + ">\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -203,6 +203,7 @@ private slots:
|
||||
void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2();
|
||||
void test_quickfix_MoveFuncDefOutside_macroUses();
|
||||
void test_quickfix_MoveFuncDefOutside_template();
|
||||
void test_quickfix_MoveFuncDefOutside_template_specializedClass();
|
||||
void test_quickfix_MoveFuncDefOutside_unnamedTemplate();
|
||||
void test_quickfix_MoveFuncDefOutside_MemberFuncToCpp_Static();
|
||||
void test_quickfix_MoveFuncDefOutside_MemberFuncToCpp_WithInlinePartOfName();
|
||||
|
||||
@@ -6521,6 +6521,33 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_template()
|
||||
QuickFixOperationTest(singleDocument(original, expected), &factory);
|
||||
}
|
||||
|
||||
void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_template_specializedClass()
|
||||
{
|
||||
QByteArray original = R"(
|
||||
template<typename T> class base {};
|
||||
template<>
|
||||
class base<int>
|
||||
{
|
||||
public:
|
||||
void @bar() {}
|
||||
};
|
||||
)";
|
||||
QByteArray expected = R"(
|
||||
template<typename T> class base {};
|
||||
template<>
|
||||
class base<int>
|
||||
{
|
||||
public:
|
||||
void bar();
|
||||
};
|
||||
|
||||
void base<int>::bar() {}
|
||||
)";
|
||||
|
||||
MoveFuncDefOutside factory;
|
||||
QuickFixOperationTest(singleDocument(original, expected), &factory);
|
||||
}
|
||||
|
||||
void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_unnamedTemplate()
|
||||
{
|
||||
QByteArray original =
|
||||
|
||||
Reference in New Issue
Block a user