Commit 59d6fbd5 authored by Lorenz Haas's avatar Lorenz Haas

CppEditor: MoveAllFuncDef now ignores generated function definitions

Task-number: QTCREATORBUG-13900
Change-Id: I394ed96072c590df627bc29f1962cdab4f7d34d7
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent b6a0dbee
......@@ -174,6 +174,7 @@ private slots:
void test_quickfix_MoveAllFuncDefOutside_MemberFuncOutside();
void test_quickfix_MoveAllFuncDefOutside_DoNotTriggerOnBaseClass();
void test_quickfix_MoveAllFuncDefOutside_classWithBaseClass();
void test_quickfix_MoveAllFuncDefOutside_ignoreMacroCode();
void test_quickfix_MoveFuncDefToDecl_MemberFunc();
void test_quickfix_MoveFuncDefToDecl_MemberFuncOutside();
......
......@@ -4102,6 +4102,34 @@ void CppEditorPlugin::test_quickfix_MoveAllFuncDefOutside_classWithBaseClass()
QuickFixOperationTest(singleDocument(original, expected), &factory);
}
/// Check: Do not take macro expanded code into account (QTCREATORBUG-13900)
void CppEditorPlugin::test_quickfix_MoveAllFuncDefOutside_ignoreMacroCode()
{
QByteArray original =
"#define FAKE_Q_OBJECT int bar() {return 5;}\n"
"class Fo@o {\n"
" FAKE_Q_OBJECT\n"
" int f1()\n"
" {\n"
" return 1;\n"
" }\n"
"};\n";
QByteArray expected =
"#define FAKE_Q_OBJECT int bar() {return 5;}\n"
"class Foo {\n"
" FAKE_Q_OBJECT\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()
{
......
......@@ -4650,8 +4650,10 @@ public:
{
MoveFuncDefRefactoringHelper helper(this, m_type, m_headerFileName, m_cppFileName);
for (DeclarationListAST *it = m_classDef->member_specifier_list; it; it = it->next) {
if (FunctionDefinitionAST *funcAST = it->value->asFunctionDefinition())
helper.performMove(funcAST);
if (FunctionDefinitionAST *funcAST = it->value->asFunctionDefinition()) {
if (funcAST->symbol && !funcAST->symbol->isGenerated())
helper.performMove(funcAST);
}
}
helper.applyChanges();
}
......@@ -4685,9 +4687,11 @@ void MoveAllFuncDefOutside::match(const CppQuickFixInterface &interface, QuickFi
// Determine if the class has at least one function definition
bool classContainsFunctions = false;
for (DeclarationListAST *it = classAST->member_specifier_list; it; it = it->next) {
if (it->value->asFunctionDefinition()) {
classContainsFunctions = true;
break;
if (FunctionDefinitionAST *funcAST = it->value->asFunctionDefinition()) {
if (funcAST->symbol && !funcAST->symbol->isGenerated()) {
classContainsFunctions = true;
break;
}
}
}
if (!classContainsFunctions)
......
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