CppEditor: Add template enclosing scope on "Insert Declaration"

Change-Id: Iff4893193b56c2ed86b4b9515a1a1df847528369
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Orgad Shaneh
2016-07-31 23:54:48 +03:00
committed by Orgad Shaneh
parent 2890966ec3
commit 5a40bddf08
3 changed files with 59 additions and 1 deletions

View File

@@ -147,6 +147,8 @@ private slots:
void test_quickfix_InsertDefFromDecl_unicodeIdentifier(); void test_quickfix_InsertDefFromDecl_unicodeIdentifier();
void test_quickfix_InsertDeclFromDef(); void test_quickfix_InsertDeclFromDef();
void test_quickfix_InsertDeclFromDef_templateFuncTypename();
void test_quickfix_InsertDeclFromDef_templateFuncInt();
void test_quickfix_InsertDeclFromDef_notTriggeredForTemplateFunc(); void test_quickfix_InsertDeclFromDef_notTriggeredForTemplateFunc();
void test_quickfix_AddIncludeForUndefinedIdentifier_data(); void test_quickfix_AddIncludeForUndefinedIdentifier_data();

View File

@@ -2715,6 +2715,56 @@ void CppEditorPlugin::test_quickfix_InsertDeclFromDef()
insertToSectionDeclFromDef("private slots", 5); insertToSectionDeclFromDef("private slots", 5);
} }
void CppEditorPlugin::test_quickfix_InsertDeclFromDef_templateFuncTypename()
{
QByteArray original =
"class Foo\n"
"{\n"
"};\n"
"\n"
"template<class T>\n"
"void Foo::fu@nc() {}\n";
QByteArray expected =
"class Foo\n"
"{\n"
"public:\n"
" template<class T>\n"
" void func();\n"
"};\n"
"\n"
"template<class T>\n"
"void Foo::fu@nc() {}\n";
InsertDeclFromDef factory;
QuickFixOperationTest(singleDocument(original, expected), &factory, {}, 0);
}
void CppEditorPlugin::test_quickfix_InsertDeclFromDef_templateFuncInt()
{
QByteArray original =
"class Foo\n"
"{\n"
"};\n"
"\n"
"template<int N>\n"
"void Foo::fu@nc() {}\n";
QByteArray expected =
"class Foo\n"
"{\n"
"public:\n"
" template<int N>\n"
" void func();\n"
"};\n"
"\n"
"template<int N>\n"
"void Foo::fu@nc() {}\n";
InsertDeclFromDef factory;
QuickFixOperationTest(singleDocument(original, expected), &factory, {}, 0);
}
void CppEditorPlugin::test_quickfix_InsertDeclFromDef_notTriggeredForTemplateFunc() void CppEditorPlugin::test_quickfix_InsertDeclFromDef_notTriggeredForTemplateFunc()
{ {
QByteArray contents = QByteArray contents =

View File

@@ -2508,9 +2508,15 @@ QString InsertDeclOperation::generateDeclaration(const Function *function)
oo.showFunctionSignatures = true; oo.showFunctionSignatures = true;
oo.showReturnTypes = true; oo.showReturnTypes = true;
oo.showArgumentNames = true; oo.showArgumentNames = true;
oo.showEnclosingTemplate = true;
const Symbol *symbol = function;
if (const Scope *enclosingScope = function->enclosingScope()) {
if (const Template *templ = enclosingScope->asTemplate())
symbol = templ;
}
QString decl; QString decl;
decl += oo.prettyType(function->type(), function->unqualifiedName()); decl += oo.prettyType(symbol->type(), function->unqualifiedName());
decl += QLatin1String(";\n"); decl += QLatin1String(";\n");
return decl; return decl;