forked from qt-creator/qt-creator
C++ indenter: Fix indentation if template and class appear on one line.
Task-number: QTCREATORBUG-2427
This commit is contained in:
@@ -1040,16 +1040,18 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
|
|||||||
|
|
||||||
switch (newState) {
|
switch (newState) {
|
||||||
case namespace_start:
|
case namespace_start:
|
||||||
if (firstToken)
|
if (firstToken) {
|
||||||
*savedIndentDepth = tokenPosition;
|
*savedIndentDepth = tokenPosition;
|
||||||
*indentDepth = tokenPosition;
|
*indentDepth = tokenPosition;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case enum_start:
|
case enum_start:
|
||||||
case class_start:
|
case class_start:
|
||||||
if (firstToken)
|
if (firstToken) {
|
||||||
*savedIndentDepth = tokenPosition;
|
*savedIndentDepth = tokenPosition;
|
||||||
*indentDepth = tokenPosition;
|
*indentDepth = tokenPosition;
|
||||||
|
}
|
||||||
*paddingDepth = 2*m_indentSize;
|
*paddingDepth = 2*m_indentSize;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1075,9 +1077,10 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case declaration_start:
|
case declaration_start:
|
||||||
if (firstToken)
|
if (firstToken) {
|
||||||
*savedIndentDepth = tokenPosition;
|
*savedIndentDepth = tokenPosition;
|
||||||
*indentDepth = *savedIndentDepth;
|
*indentDepth = *savedIndentDepth;
|
||||||
|
}
|
||||||
// continuation indent in function bodies only, to not indent
|
// continuation indent in function bodies only, to not indent
|
||||||
// after the return type in "void\nfoo() {}"
|
// after the return type in "void\nfoo() {}"
|
||||||
for (int i = 0; state(i).type != topmost_intro; ++i) {
|
for (int i = 0; state(i).type != topmost_intro; ++i) {
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ private Q_SLOTS:
|
|||||||
void blockStmtInIf();
|
void blockStmtInIf();
|
||||||
void nestedInitializer();
|
void nestedInitializer();
|
||||||
void forStatement();
|
void forStatement();
|
||||||
|
void templateSingleline();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Line {
|
struct Line {
|
||||||
@@ -939,6 +940,18 @@ void tst_CodeFormatter::forStatement()
|
|||||||
checkIndent(data);
|
checkIndent(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_CodeFormatter::templateSingleline()
|
||||||
|
{
|
||||||
|
QList<Line> data;
|
||||||
|
data
|
||||||
|
<< Line("template <typename T> class Foo")
|
||||||
|
<< Line("{")
|
||||||
|
<< Line(" T t;")
|
||||||
|
<< Line("}")
|
||||||
|
;
|
||||||
|
checkIndent(data);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_APPLESS_MAIN(tst_CodeFormatter)
|
QTEST_APPLESS_MAIN(tst_CodeFormatter)
|
||||||
#include "tst_codeformatter.moc"
|
#include "tst_codeformatter.moc"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user