Commit 6078b36c authored by Christian Kamm's avatar Christian Kamm
Browse files

C++ indenter: Enable class, struct, enum, namespace, using in functions.

Fixes incorrect indentation we got previously when they were used in a
statement context.
parent 870da8e7
......@@ -72,16 +72,8 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
switch (m_currentState.top().type) {
case topmost_intro:
if (tryDeclaration())
break;
switch (kind) {
case T_NAMESPACE: enter(namespace_start); break;
case T_STRUCT:
case T_UNION:
case T_CLASS: enter(class_start); break;
case T_ENUM: enter(enum_start); break;
case T_USING: enter(using_start); break;
} break;
tryDeclaration();
break;
case namespace_start:
switch (kind) {
......@@ -93,13 +85,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
if (tryDeclaration())
break;
switch (kind) {
case T_NAMESPACE: enter(namespace_start); break;
case T_RBRACE: leave(); continue; // always nested in namespace_start
case T_STRUCT:
case T_UNION:
case T_CLASS: enter(class_start); break;
case T_ENUM: enter(enum_start); break;
case T_USING: enter(using_start); break;
} break;
case class_start:
......@@ -113,11 +99,6 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
break;
switch (kind) {
case T_RBRACE: leave(); continue; // always nested in class_start
case T_STRUCT:
case T_UNION:
case T_CLASS: enter(class_start); break;
case T_ENUM: enter(enum_start); break;
case T_USING: enter(using_start); break;
} break;
case enum_start:
......@@ -704,6 +685,24 @@ bool CodeFormatter::tryDeclaration()
enter(template_start);
return true;
case T_NAMESPACE:
enter(namespace_start);
return true;
case T_STRUCT:
case T_UNION:
case T_CLASS:
enter(class_start);
return true;
case T_ENUM:
enter(enum_start);
return true;
case T_USING:
enter(using_start);
return true;
default:
return false;
}
......
......@@ -42,6 +42,7 @@ private Q_SLOTS:
void operatorOverloads();
void gnuStyle();
void whitesmithsStyle();
void singleLineEnum();
};
struct Line {
......@@ -755,6 +756,19 @@ void tst_CodeFormatter::whitesmithsStyle()
checkIndent(data, 2);
}
void tst_CodeFormatter::singleLineEnum()
{
enum { a, b};
QList<Line> data;
data << Line("enum { foo, bar, car = 2 };")
<< Line("void blah() {")
<< Line(" enum { foo, bar, car = 2 };")
<< Line(" int i;")
<< Line("}")
;
checkIndent(data);
}
QTEST_APPLESS_MAIN(tst_CodeFormatter)
#include "tst_codeformatter.moc"
......
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