Commit f0826649 authored by Lorenz Haas's avatar Lorenz Haas

CppEditor: Add new QuickFix MoveAllFuncDefOutside

This QuickFix behaves like MoveFuncDefOutside except it moves all
member function definitions. It is triggered on the class name.

Change-Id: I1393a51cad521a7bb58a1ed6223ab0fe4db0e592
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent e58b326a
......@@ -2088,6 +2088,42 @@
\endcode
\li Function signature
\row
\li Move All Function Definitions
\li Moves all function definitions to the implementation file or outside the class. For example, rewrites:
\code
class Foo
{
void bar()
{
// do stuff here
}
void baz()
{
// do stuff here
}
};
\endcode
as
\code
class Foo
{
void bar();
void baz();
};
void Foo::bar() {
// do stuff here
}
void Foo::baz() {
// do stuff here
}
\endcode
\li Class name
\row
\li Assign to Local Variable
\li Adds a local variable which stores the return value of a function call or a new expression. For example, rewrites:
......
......@@ -174,6 +174,11 @@ private slots:
void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2();
void test_quickfix_MoveFuncDefOutside_macroUses();
void test_quickfix_MoveAllFuncDefOutside_MemberFuncToCpp();
void test_quickfix_MoveAllFuncDefOutside_MemberFuncOutside();
void test_quickfix_MoveAllFuncDefOutside_DoNotTriggerOnBaseClass();
void test_quickfix_MoveAllFuncDefOutside_classWithBaseClass();
void test_quickfix_MoveFuncDefToDecl_MemberFunc();
void test_quickfix_MoveFuncDefToDecl_MemberFuncOutside();
void test_quickfix_MoveFuncDefToDecl_MemberFuncToCppNS();
......
......@@ -3981,6 +3981,132 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_override()
QuickFixOperationTest(singleDocument(original, expected), &factory);
}
/// Check: Move all definitions from header to cpp.
void CppEditorPlugin::test_quickfix_MoveAllFuncDefOutside_MemberFuncToCpp()
{
QList<QuickFixTestDocument::Ptr> testFiles;
QByteArray original;
QByteArray expected;
// Header File
original =
"class Fo@o {\n"
" int numberA() const\n"
" {\n"
" return 5;\n"
" }\n"
" int numberB() const\n"
" {\n"
" return 5;\n"
" }\n"
"};\n";
expected =
"class Foo {\n"
" int numberA() const;\n"
" int numberB() const;\n"
"};\n";
testFiles << QuickFixTestDocument::create("file.h", original, expected);
// Source File
original =
"#include \"file.h\"\n";
expected =
"#include \"file.h\"\n"
"\n"
"\n"
"int Foo::numberA() const\n"
"{\n"
" return 5;\n"
"}\n"
"\n\n"
"int Foo::numberB() const\n"
"{\n"
" return 5;\n"
"}\n"
;
testFiles << QuickFixTestDocument::create("file.cpp", original, expected);
MoveAllFuncDefOutside factory;
QuickFixOperationTest(testFiles, &factory);
}
/// Check: Move all definition outside class
void CppEditorPlugin::test_quickfix_MoveAllFuncDefOutside_MemberFuncOutside()
{
QByteArray original =
"class F@oo {\n"
" int f1()\n"
" {\n"
" return 1;\n"
" }\n"
" int f2() const\n"
" {\n"
" return 2;\n"
" }\n"
"};\n";
QByteArray expected =
"class Foo {\n"
" int f1();\n"
" int f2() const;\n"
"};\n"
"\n\n"
"int Foo::f1()\n"
"{\n"
" return 1;\n"
"}\n"
"\n\n"
"int Foo::f2() const\n"
"{\n"
" return 2;\n"
"}\n";
MoveAllFuncDefOutside factory;
QuickFixOperationTest(singleDocument(original, expected), &factory);
}
/// Check: Move all definition outside class
void CppEditorPlugin::test_quickfix_MoveAllFuncDefOutside_DoNotTriggerOnBaseClass()
{
QByteArray original =
"class Bar;\n"
"class Foo : public Ba@r {\n"
" int f1()\n"
" {\n"
" return 1;\n"
" }\n"
"};\n";
QByteArray expected = original;
MoveAllFuncDefOutside factory;
QuickFixOperationTest(singleDocument(original, expected), &factory);
}
/// Check: Move all definition outside class
void CppEditorPlugin::test_quickfix_MoveAllFuncDefOutside_classWithBaseClass()
{
QByteArray original =
"class Bar;\n"
"class Fo@o : public Bar {\n"
" int f1()\n"
" {\n"
" return 1;\n"
" }\n"
"};\n";
QByteArray expected =
"class Bar;\n"
"class Foo : public Bar {\n"
" int f1();\n"
"};\n"
"\n\n"
"int Foo::f1()\n"
"{\n"
" return 1;\n"
"}\n";
MoveAllFuncDefOutside factory;
QuickFixOperationTest(singleDocument(original, expected), &factory);
}
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_templates()
{
......
This diff is collapsed.
......@@ -506,6 +506,15 @@ public:
void match(const CppQuickFixInterface &interface, TextEditor::QuickFixOperations &result);
};
/*!
Moves all member function definitions outside the class or to the implementation file.
*/
class MoveAllFuncDefOutside: public CppQuickFixFactory
{
public:
void match(const CppQuickFixInterface &interface, TextEditor::QuickFixOperations &result);
};
/*!
Moves the definition of a function to its declaration.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment