Commit b437b4be authored by Christian Kamm's avatar Christian Kamm
Browse files

QuickFix: split && correctly when compound statements are involved.


Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent b5bd72fb
...@@ -471,7 +471,6 @@ public: ...@@ -471,7 +471,6 @@ public:
void splitAndCondition() void splitAndCondition()
{ {
StatementAST *ifTrueStatement = pattern->statement; StatementAST *ifTrueStatement = pattern->statement;
CompoundStatementAST *compoundStatement = ifTrueStatement->asCompoundStatement();
// take the right-expression from the condition. // take the right-expression from the condition.
QTextCursor rightCursor = textCursor(); QTextCursor rightCursor = textCursor();
...@@ -480,27 +479,14 @@ public: ...@@ -480,27 +479,14 @@ public:
const QString rightCondition = rightCursor.selectedText(); const QString rightCondition = rightCursor.selectedText();
replace(endOf(condition->left_expression), startOf(pattern->rparen_token), QString()); 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 // create the nested if statement
QString nestedIfStatement; QString nestedIfStatement;
nestedIfStatement += QLatin1String(" {\nif ("); // open new compound statement for outer
if (! compoundStatement)
nestedIfStatement += QLatin1String(" {"); // open a compound statement
nestedIfStatement += QLatin1String("\nif (");
nestedIfStatement += rightCondition; nestedIfStatement += rightCondition;
nestedIfStatement += QLatin1String(") {\n}"); nestedIfStatement += QLatin1String(")");
insert(offset, nestedIfStatement);
if (! compoundStatement) insert(endOf(pattern->rparen_token), nestedIfStatement);
insert(endOf(ifTrueStatement), "\n}"); // finish the compound statement insert(endOf(ifTrueStatement), "\n}"); // finish the compound statement
applyChanges(pattern); applyChanges(pattern);
} }
......
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