forked from qt-creator/qt-creator
CppEditor: Add enclosing template on "Add Definition"
The template id for the class name is missing, but it's better than
nothing.
For example:
template<class T>
class Foo
{
void func(); // Add Definition
};
// The following lines are added
template<class T>
void Foo::func() // Should be Foo<T>::func
{
}
Change-Id: I60a0cbd348985def3dfb7037067786e942278593
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
39aff55d8a
commit
d0d1f43e8f
@@ -145,6 +145,8 @@ private slots:
|
|||||||
void test_quickfix_InsertDefFromDecl_rvalueReference();
|
void test_quickfix_InsertDefFromDecl_rvalueReference();
|
||||||
void test_quickfix_InsertDefFromDecl_findImplementationFile();
|
void test_quickfix_InsertDefFromDecl_findImplementationFile();
|
||||||
void test_quickfix_InsertDefFromDecl_unicodeIdentifier();
|
void test_quickfix_InsertDefFromDecl_unicodeIdentifier();
|
||||||
|
void test_quickfix_InsertDefFromDecl_templateClass();
|
||||||
|
void test_quickfix_InsertDefFromDecl_templateFunction();
|
||||||
|
|
||||||
void test_quickfix_InsertDeclFromDef();
|
void test_quickfix_InsertDeclFromDef();
|
||||||
void test_quickfix_InsertDeclFromDef_templateFuncTypename();
|
void test_quickfix_InsertDeclFromDef_templateFuncTypename();
|
||||||
|
|||||||
@@ -2668,6 +2668,56 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_unicodeIdentifier()
|
|||||||
QuickFixOperationTest(testDocuments, &factory);
|
QuickFixOperationTest(testDocuments, &factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_templateClass()
|
||||||
|
{
|
||||||
|
QByteArray original =
|
||||||
|
"template<class T>\n"
|
||||||
|
"class Foo\n"
|
||||||
|
"{\n"
|
||||||
|
" void fun@c();\n"
|
||||||
|
"};\n";
|
||||||
|
QByteArray expected =
|
||||||
|
"template<class T>\n"
|
||||||
|
"class Foo\n"
|
||||||
|
"{\n"
|
||||||
|
" void fun@c();\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"template<class T>\n"
|
||||||
|
"void Foo::func()\n" // Should really be Foo<T>::func()
|
||||||
|
"{\n"
|
||||||
|
"\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
InsertDefFromDecl factory;
|
||||||
|
QuickFixOperationTest(singleDocument(original, expected), &factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_templateFunction()
|
||||||
|
{
|
||||||
|
QByteArray original =
|
||||||
|
"class Foo\n"
|
||||||
|
"{\n"
|
||||||
|
" template<class T>\n"
|
||||||
|
" void fun@c();\n"
|
||||||
|
"};\n";
|
||||||
|
QByteArray expected =
|
||||||
|
"class Foo\n"
|
||||||
|
"{\n"
|
||||||
|
" template<class T>\n"
|
||||||
|
" void fun@c();\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"template<class T>\n"
|
||||||
|
"void Foo::func()\n"
|
||||||
|
"{\n"
|
||||||
|
"\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
InsertDefFromDecl factory;
|
||||||
|
QuickFixOperationTest(singleDocument(original, expected), &factory);
|
||||||
|
}
|
||||||
|
|
||||||
// Function for one of InsertDeclDef section cases
|
// Function for one of InsertDeclDef section cases
|
||||||
void insertToSectionDeclFromDef(const QByteArray §ion, int sectionIndex)
|
void insertToSectionDeclFromDef(const QByteArray §ion, int sectionIndex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2567,6 +2567,7 @@ public:
|
|||||||
oo.showFunctionSignatures = true;
|
oo.showFunctionSignatures = true;
|
||||||
oo.showReturnTypes = true;
|
oo.showReturnTypes = true;
|
||||||
oo.showArgumentNames = true;
|
oo.showArgumentNames = true;
|
||||||
|
oo.showEnclosingTemplate = true;
|
||||||
|
|
||||||
if (m_defpos == DefPosInsideClass) {
|
if (m_defpos == DefPosInsideClass) {
|
||||||
const int targetPos = targetFile->position(m_loc.line(), m_loc.column());
|
const int targetPos = targetFile->position(m_loc.line(), m_loc.column());
|
||||||
|
|||||||
Reference in New Issue
Block a user