diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/cplusplus/TypePrettyPrinter.cpp | 30 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppeditorplugin.h | 1 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppquickfix_test.cpp | 19 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppquickfixes.cpp | 1 |
4 files changed, 49 insertions, 2 deletions
diff --git a/src/libs/cplusplus/TypePrettyPrinter.cpp b/src/libs/cplusplus/TypePrettyPrinter.cpp index 193a00803c..c85444a228 100644 --- a/src/libs/cplusplus/TypePrettyPrinter.cpp +++ b/src/libs/cplusplus/TypePrettyPrinter.cpp @@ -383,6 +383,31 @@ static bool endsWithPtrOrRef(const QString &type) void TypePrettyPrinter::visit(Function *type) { + if (_overview->showTemplateParameters) { + QStringList nameParts = _name.split("::"); + int i = nameParts.length() - 1; + 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); + } + n += arg; + } + n += '>'; + } + if (s->identifier()) + --i; + } + _name = nameParts.join("::"); + } + if (_needsParens) { _text.prepend(QLatin1Char('(')); if (! _name.isEmpty()) { @@ -417,7 +442,10 @@ void TypePrettyPrinter::visit(Function *type) if (TypenameArgument *typenameArg = param->asTypenameArgument()) { templateScope.append(QLatin1String(typenameArg->isClassDeclarator() ? "class " : "typename ")); - templateScope.append(_overview->prettyName(typenameArg->name())); + QString name = _overview->prettyName(typenameArg->name()); + if (name.isEmpty()) + name.append('T').append(QString::number(i + 1)); + templateScope.append(name); } else if (Argument *arg = param->asArgument()) { templateScope.append(operator()(arg->type(), _overview->prettyName(arg->name()))); diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h index 869bc68bb5..5d13949563 100644 --- a/src/plugins/cppeditor/cppeditorplugin.h +++ b/src/plugins/cppeditor/cppeditorplugin.h @@ -177,6 +177,7 @@ private slots: void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2(); void test_quickfix_MoveFuncDefOutside_macroUses(); void test_quickfix_MoveFuncDefOutside_template(); + void test_quickfix_MoveFuncDefOutside_unnamedTemplate(); void test_quickfix_MoveAllFuncDefOutside_MemberFuncToCpp(); void test_quickfix_MoveAllFuncDefOutside_MemberFuncOutside(); diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index b45fe7e911..793f3113a8 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -5573,7 +5573,24 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_template() "class Foo { void fu@nc(); };\n" "\n" "template<class T>\n" - "void Foo::func() {}\n"; // Should be Foo<T>::func + "void Foo<T>::func() {}\n"; + ; + + MoveFuncDefOutside factory; + QuickFixOperationTest(singleDocument(original, expected), &factory); +} + +void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_unnamedTemplate() +{ + QByteArray original = + "template<typename T, typename>\n" + "class Foo { void fu@nc() {} };\n"; + QByteArray expected = + "template<typename T, typename>\n" + "class Foo { void fu@nc(); };\n" + "\n" + "template<typename T, typename T2>\n" + "void Foo<T, T2>::func() {}\n"; ; MoveFuncDefOutside factory; diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index a59f2c18f2..9d1fa2e03e 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -5952,6 +5952,7 @@ QString definitionSignature(const CppQuickFixInterface *assist, oo.showReturnTypes = true; oo.showArgumentNames = true; oo.showEnclosingTemplate = true; + oo.showTemplateParameters = true; const Name *name = func->name(); if (name && nameIncludesOperatorName(name)) { CoreDeclaratorAST *coreDeclarator = functionDefinitionAST->declarator->core_declarator; |