CppEditor: Make "Add curly braces" quickfix more robust

Anchor the opening brace at the closing parenthesis, rather than at the
statement. This way, we won't get troubled by macro weirdness in the
statement part.

Fixes: QTCREATORBUG-13921
Change-Id: I05af24d1642e6b62c78bb2f47a1ef0b1fea326d0
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2020-07-07 15:43:42 +02:00
parent 044faadc2d
commit 5b3aece387
3 changed files with 34 additions and 6 deletions

View File

@@ -5417,6 +5417,31 @@ void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_notTriggeringForIn
QuickFixOperationTest(testDocuments, &factory);
}
void CppEditorPlugin::test_quickfix_addCurlyBraces()
{
QList<QuickFixTestDocument::Ptr> testDocuments;
const QByteArray original = R"delim(
void MyObject::f()
{
@if (true)
emit mySig();
}
)delim";
const QByteArray expected = R"delim(
void MyObject::f()
{
if (true) {
emit mySig();
}
}
)delim";
testDocuments << QuickFixTestDocument::create("file.cpp", original, expected);
AddBracesToIf factory;
QuickFixOperationTest(testDocuments, &factory);
}
void CppEditorPlugin::test_quickfix_ConvertQt4Connect_connectOutOfClass()
{
QByteArray prefix =