forked from qt-creator/qt-creator
C++ indenter: Enable class, struct, enum, namespace, using in functions.
Fixes incorrect indentation we got previously when they were used in a statement context.
This commit is contained in:
@@ -72,16 +72,8 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
|
||||
|
||||
switch (m_currentState.top().type) {
|
||||
case topmost_intro:
|
||||
if (tryDeclaration())
|
||||
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;
|
||||
|
||||
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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user