From b437b4be0fbd8dc0cf9c6e0acea879dc7b18525a Mon Sep 17 00:00:00 2001 From: Christian Kamm <christian.d.kamm@nokia.com> Date: Mon, 23 Nov 2009 13:44:08 +0100 Subject: [PATCH] QuickFix: split && correctly when compound statements are involved. Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com> --- src/plugins/cppeditor/cppquickfix.cpp | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/plugins/cppeditor/cppquickfix.cpp b/src/plugins/cppeditor/cppquickfix.cpp index fc086a4cf8b..03fff23155f 100644 --- a/src/plugins/cppeditor/cppquickfix.cpp +++ b/src/plugins/cppeditor/cppquickfix.cpp @@ -471,7 +471,6 @@ public: void splitAndCondition() { StatementAST *ifTrueStatement = pattern->statement; - CompoundStatementAST *compoundStatement = ifTrueStatement->asCompoundStatement(); // take the right-expression from the condition. QTextCursor rightCursor = textCursor(); @@ -480,27 +479,14 @@ public: const QString rightCondition = rightCursor.selectedText(); replace(endOf(condition->left_expression), startOf(pattern->rparen_token), QString()); - int offset = 0; - - if (compoundStatement) - offset = endOf(compoundStatement->lbrace_token); - else - offset = endOf(pattern->rparen_token); - // create the nested if statement QString nestedIfStatement; - - if (! compoundStatement) - nestedIfStatement += QLatin1String(" {"); // open a compound statement - - nestedIfStatement += QLatin1String("\nif ("); + nestedIfStatement += QLatin1String(" {\nif ("); // open new compound statement for outer nestedIfStatement += rightCondition; - nestedIfStatement += QLatin1String(") {\n}"); - - insert(offset, nestedIfStatement); + nestedIfStatement += QLatin1String(")"); - if (! compoundStatement) - insert(endOf(ifTrueStatement), "\n}"); // finish the compound statement + insert(endOf(pattern->rparen_token), nestedIfStatement); + insert(endOf(ifTrueStatement), "\n}"); // finish the compound statement applyChanges(pattern); } -- GitLab