forked from qt-creator/qt-creator
CppEditor: Support try/catch in built-in indenter
Fixes: QTCREATORBUG-29452 Change-Id: Icf3d86a6080aeb741436800ae77af7c8bec3155c Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -284,6 +284,8 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
|
||||
&& m_currentState.at(m_currentState.size() - 2).type == declaration_start) {
|
||||
leave();
|
||||
leave();
|
||||
} else if (m_currentState.top().type == catch_statement) {
|
||||
turnInto(substatement);
|
||||
}
|
||||
break;
|
||||
default: tryExpression(); break;
|
||||
@@ -414,6 +416,11 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
|
||||
default: leave(true); continue;
|
||||
} break;
|
||||
|
||||
case catch_statement:
|
||||
switch (kind) {
|
||||
case T_LPAREN: enter(arglist_open); break;
|
||||
} break;
|
||||
|
||||
case for_statement_paren_open:
|
||||
enter(for_statement_init); continue;
|
||||
|
||||
@@ -965,6 +972,12 @@ bool CodeFormatter::tryStatement()
|
||||
enter(do_statement);
|
||||
enter(substatement);
|
||||
return true;
|
||||
case T_TRY:
|
||||
enter(substatement);
|
||||
return true;
|
||||
case T_CATCH:
|
||||
enter(catch_statement);
|
||||
return true;
|
||||
case T_CASE:
|
||||
case T_DEFAULT:
|
||||
enter(case_start);
|
||||
|
@@ -119,6 +119,8 @@ public: // must be public to make Q_GADGET introspection work
|
||||
for_statement_condition, // The condition part of the for statement
|
||||
for_statement_expression, // The expression part of the for statement
|
||||
|
||||
catch_statement,
|
||||
|
||||
switch_statement, // After 'switch' token
|
||||
case_start, // after a 'case' or 'default' token
|
||||
case_cont, // after the colon in a case/default
|
||||
|
@@ -109,6 +109,7 @@ private Q_SLOTS:
|
||||
void structuredBinding();
|
||||
void subscriptOperatorInFunctionCall();
|
||||
void statementMacros();
|
||||
void tryCatchClause();
|
||||
};
|
||||
|
||||
struct Line {
|
||||
@@ -2231,6 +2232,45 @@ void tst_CodeFormatter::statementMacros()
|
||||
checkIndent(data, settings);
|
||||
}
|
||||
|
||||
void tst_CodeFormatter::tryCatchClause()
|
||||
{
|
||||
CppCodeStyleSettings settings;
|
||||
settings.indentFunctionBody = true;
|
||||
settings.indentFunctionBraces = false;
|
||||
settings.indentBlockBody = false;
|
||||
settings.indentBlockBraces = true;
|
||||
QList<Line> data;
|
||||
data << Line("int main()")
|
||||
<< Line("{")
|
||||
<< Line(" try")
|
||||
<< Line(" {")
|
||||
<< Line(" throw;")
|
||||
<< Line(" }")
|
||||
<< Line(" catch (const E &e)")
|
||||
<< Line(" {")
|
||||
<< Line(" handle(e);")
|
||||
<< Line(" }")
|
||||
<< Line(" catch (...)")
|
||||
<< Line(" {")
|
||||
<< Line(" handle();")
|
||||
<< Line(" }")
|
||||
<< Line("}");
|
||||
checkIndent(data, settings);
|
||||
|
||||
data.clear();
|
||||
data << Line("int main()")
|
||||
<< Line("{")
|
||||
<< Line(" try {")
|
||||
<< Line(" throw;")
|
||||
<< Line(" } catch (const E &e) {")
|
||||
<< Line(" handle(e);")
|
||||
<< Line(" } catch (...) {")
|
||||
<< Line(" handle();")
|
||||
<< Line(" }")
|
||||
<< Line("}");
|
||||
checkIndent(data);
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(tst_CodeFormatter)
|
||||
|
||||
#include "tst_codeformatter.moc"
|
||||
|
Reference in New Issue
Block a user