forked from qt-creator/qt-creator
CppEditor: Quick fix "move definition" keeps ctor-initialization list
Task-number: QTCREATORBUG-9157 Change-Id: Ic46086ba07a86292bbf48de62b69e3f33628fd86 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
7d2a7685aa
commit
39d000430e
@@ -140,6 +140,7 @@ private slots:
|
|||||||
void test_quickfix_MoveFuncDefOutside_MemberFuncOutsideWithNs();
|
void test_quickfix_MoveFuncDefOutside_MemberFuncOutsideWithNs();
|
||||||
void test_quickfix_MoveFuncDefOutside_FreeFuncToCpp();
|
void test_quickfix_MoveFuncDefOutside_FreeFuncToCpp();
|
||||||
void test_quickfix_MoveFuncDefOutside_FreeFuncToCppNS();
|
void test_quickfix_MoveFuncDefOutside_FreeFuncToCppNS();
|
||||||
|
void test_quickfix_MoveFuncDefOutside_CtorWithInitialization();
|
||||||
|
|
||||||
void test_quickfix_MoveFuncDefToDecl_MemberFunc();
|
void test_quickfix_MoveFuncDefToDecl_MemberFunc();
|
||||||
void test_quickfix_MoveFuncDefToDecl_MemberFuncOutside();
|
void test_quickfix_MoveFuncDefToDecl_MemberFuncOutside();
|
||||||
@@ -148,6 +149,7 @@ private slots:
|
|||||||
void test_quickfix_MoveFuncDefToDecl_MemberFuncOutsideWithNs();
|
void test_quickfix_MoveFuncDefToDecl_MemberFuncOutsideWithNs();
|
||||||
void test_quickfix_MoveFuncDefToDecl_FreeFuncToCpp();
|
void test_quickfix_MoveFuncDefToDecl_FreeFuncToCpp();
|
||||||
void test_quickfix_MoveFuncDefToDecl_FreeFuncToCppNS();
|
void test_quickfix_MoveFuncDefToDecl_FreeFuncToCppNS();
|
||||||
|
void test_quickfix_MoveFuncDefToDecl_CtorWithInitialization();
|
||||||
|
|
||||||
// The following tests depend on the projects that are loaded on startup
|
// The following tests depend on the projects that are loaded on startup
|
||||||
// and will be skipped in case no projects are loaded.
|
// and will be skipped in case no projects are loaded.
|
||||||
|
@@ -1351,6 +1351,46 @@ void CppPlugin::test_quickfix_MoveFuncDefOutside_FreeFuncToCppNS()
|
|||||||
data.run(&factory);
|
data.run(&factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check: Move Ctor with member initialization list (QTCREATORBUG-9157).
|
||||||
|
void CppPlugin::test_quickfix_MoveFuncDefOutside_CtorWithInitialization()
|
||||||
|
{
|
||||||
|
QList<TestDocumentPtr> testFiles;
|
||||||
|
QByteArray original;
|
||||||
|
QByteArray expected;
|
||||||
|
|
||||||
|
// Header File
|
||||||
|
original =
|
||||||
|
"class Foo {\n"
|
||||||
|
"public:\n"
|
||||||
|
" Fo@o() : a(42), b(3.141) {}\n"
|
||||||
|
"private:\n"
|
||||||
|
" int a;\n"
|
||||||
|
" float b;\n"
|
||||||
|
"};";
|
||||||
|
expected =
|
||||||
|
"class Foo {\n"
|
||||||
|
"public:\n"
|
||||||
|
" Foo();\n"
|
||||||
|
"private:\n"
|
||||||
|
" int a;\n"
|
||||||
|
" float b;\n"
|
||||||
|
"};\n";
|
||||||
|
testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
|
||||||
|
|
||||||
|
// Source File
|
||||||
|
original ="#include \"file.h\"\n";
|
||||||
|
expected =
|
||||||
|
"#include \"file.h\"\n"
|
||||||
|
"\n"
|
||||||
|
"Foo::Foo() : a(42), b(3.141) {}\n"
|
||||||
|
"\n";
|
||||||
|
testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
|
||||||
|
|
||||||
|
MoveFuncDefOutside factory;
|
||||||
|
TestCase data(testFiles);
|
||||||
|
data.run(&factory);
|
||||||
|
}
|
||||||
|
|
||||||
/// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncToCpp()
|
/// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncToCpp()
|
||||||
void CppPlugin::test_quickfix_MoveFuncDefToDecl_MemberFunc()
|
void CppPlugin::test_quickfix_MoveFuncDefToDecl_MemberFunc()
|
||||||
{
|
{
|
||||||
@@ -1578,3 +1618,43 @@ void CppPlugin::test_quickfix_MoveFuncDefToDecl_FreeFuncToCppNS()
|
|||||||
TestCase data(testFiles);
|
TestCase data(testFiles);
|
||||||
data.run(&factory);
|
data.run(&factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check: revert test_quickfix_MoveFuncDefOutside_CtorWithInitialization()
|
||||||
|
void CppPlugin::test_quickfix_MoveFuncDefToDecl_CtorWithInitialization()
|
||||||
|
{
|
||||||
|
QList<TestDocumentPtr> testFiles;
|
||||||
|
QByteArray original;
|
||||||
|
QByteArray expected;
|
||||||
|
|
||||||
|
// Header File
|
||||||
|
original =
|
||||||
|
"class Foo {\n"
|
||||||
|
"public:\n"
|
||||||
|
" Foo();\n"
|
||||||
|
"private:\n"
|
||||||
|
" int a;\n"
|
||||||
|
" float b;\n"
|
||||||
|
"};";
|
||||||
|
expected =
|
||||||
|
"class Foo {\n"
|
||||||
|
"public:\n"
|
||||||
|
" Foo() : a(42), b(3.141) {}\n"
|
||||||
|
"private:\n"
|
||||||
|
" int a;\n"
|
||||||
|
" float b;\n"
|
||||||
|
"};\n";
|
||||||
|
testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
|
||||||
|
|
||||||
|
// Source File
|
||||||
|
original =
|
||||||
|
"#include \"file.h\"\n"
|
||||||
|
"\n"
|
||||||
|
"Foo::F@oo() : a(42), b(3.141) {}"
|
||||||
|
;
|
||||||
|
expected ="#include \"file.h\"\n\n\n";
|
||||||
|
testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
|
||||||
|
|
||||||
|
MoveFuncDefToDecl factory;
|
||||||
|
TestCase data(testFiles);
|
||||||
|
data.run(&factory);
|
||||||
|
}
|
||||||
|
@@ -3645,7 +3645,6 @@ public:
|
|||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr fromFile = refactoring.file(m_headerFileName);
|
CppRefactoringFilePtr fromFile = refactoring.file(m_headerFileName);
|
||||||
const QString textFuncBody = fromFile->textOf(m_funcDef->function_body);
|
|
||||||
CppRefactoringFilePtr toFile;
|
CppRefactoringFilePtr toFile;
|
||||||
int insertPos = 0;
|
int insertPos = 0;
|
||||||
Scope *scopeAtInsertPos = 0;
|
Scope *scopeAtInsertPos = 0;
|
||||||
@@ -3666,6 +3665,10 @@ public:
|
|||||||
// construct definition
|
// construct definition
|
||||||
const QString funcDec = getDefinitionSignature(assistInterface(), m_func, toFile,
|
const QString funcDec = getDefinitionSignature(assistInterface(), m_func, toFile,
|
||||||
scopeAtInsertPos);
|
scopeAtInsertPos);
|
||||||
|
QString textFuncBody;
|
||||||
|
if (m_funcDef->ctor_initializer)
|
||||||
|
textFuncBody = fromFile->textOf(m_funcDef->ctor_initializer) + QLatin1Char(' ');
|
||||||
|
textFuncBody += fromFile->textOf(m_funcDef->function_body);
|
||||||
QString funcDef = QString::fromLatin1("\n%1 %2\n")
|
QString funcDef = QString::fromLatin1("\n%1 %2\n")
|
||||||
.arg(funcDec)
|
.arg(funcDec)
|
||||||
.arg(textFuncBody);
|
.arg(textFuncBody);
|
||||||
@@ -3792,8 +3795,11 @@ public:
|
|||||||
CppRefactoringFilePtr toFile = refactoring.file(m_toFileName);
|
CppRefactoringFilePtr toFile = refactoring.file(m_toFileName);
|
||||||
ChangeSet::Range fromRange = fromFile->range(m_funcAST);
|
ChangeSet::Range fromRange = fromFile->range(m_funcAST);
|
||||||
const QString definitionText = fromFile->textOf(m_funcAST->function_body);
|
const QString definitionText = fromFile->textOf(m_funcAST->function_body);
|
||||||
const QString wholeFunctionText = QString::fromLatin1("%1 %2").arg(m_declarationText)
|
QString wholeFunctionText = m_declarationText;
|
||||||
.arg(definitionText);
|
if (m_funcAST->ctor_initializer)
|
||||||
|
wholeFunctionText += QLatin1Char(' ') + fromFile->textOf(m_funcAST->ctor_initializer);
|
||||||
|
wholeFunctionText += QLatin1Char(' ') + definitionText;
|
||||||
|
|
||||||
|
|
||||||
// Replace declaration with function and delete old definition
|
// Replace declaration with function and delete old definition
|
||||||
Utils::ChangeSet toTarget;
|
Utils::ChangeSet toTarget;
|
||||||
|
Reference in New Issue
Block a user