forked from qt-creator/qt-creator
C++ indenter: Fix function declaration continuation indent.
Change-Id: I0ebe1f0f531cb4830f80b80c6bb52caeaee01353 Reviewed-on: http://codereview.qt.nokia.com/1167 Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
This commit is contained in:
@@ -1058,6 +1058,14 @@ int QtStyleCodeFormatter::loadLexerState(const QTextBlock &block) const
|
||||
return BaseTextDocumentLayout::lexerState(block);
|
||||
}
|
||||
|
||||
void QtStyleCodeFormatter::addContinuationIndent(int *paddingDepth) const
|
||||
{
|
||||
if (*paddingDepth == 0)
|
||||
*paddingDepth = 2*m_tabSettings.m_indentSize;
|
||||
else
|
||||
*paddingDepth += m_tabSettings.m_indentSize;
|
||||
}
|
||||
|
||||
void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedIndentDepth, int *paddingDepth, int *savedPaddingDepth) const
|
||||
{
|
||||
const State &parentState = state();
|
||||
@@ -1094,12 +1102,8 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
|
||||
case template_param:
|
||||
if (!lastToken)
|
||||
*paddingDepth = nextTokenPosition-*indentDepth;
|
||||
else {
|
||||
if (*paddingDepth == 0)
|
||||
*paddingDepth = 2*m_tabSettings.m_indentSize;
|
||||
else
|
||||
*paddingDepth += m_tabSettings.m_indentSize;
|
||||
}
|
||||
addContinuationIndent(paddingDepth);
|
||||
break;
|
||||
|
||||
case statement_with_condition:
|
||||
@@ -1143,14 +1147,14 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
|
||||
if (!lastToken)
|
||||
*paddingDepth = nextTokenPosition-*indentDepth;
|
||||
else
|
||||
*paddingDepth += m_tabSettings.m_indentSize;
|
||||
addContinuationIndent(paddingDepth);
|
||||
break;
|
||||
|
||||
case ternary_op:
|
||||
if (!lastToken)
|
||||
*paddingDepth = spaceOrNextTokenPosition-*indentDepth;
|
||||
else
|
||||
*paddingDepth += m_tabSettings.m_indentSize;
|
||||
addContinuationIndent(paddingDepth);
|
||||
break;
|
||||
|
||||
case stream_op:
|
||||
@@ -1176,7 +1180,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
|
||||
break;
|
||||
|
||||
case member_init_paren_open:
|
||||
*paddingDepth += m_tabSettings.m_indentSize;
|
||||
addContinuationIndent(paddingDepth);
|
||||
break;
|
||||
|
||||
case case_cont:
|
||||
|
||||
@@ -278,6 +278,8 @@ protected:
|
||||
static bool shouldClearPaddingOnEnter(int state);
|
||||
|
||||
private:
|
||||
void addContinuationIndent(int *paddingDepth) const;
|
||||
|
||||
TextEditor::TabSettings m_tabSettings;
|
||||
CppCodeStyleSettings m_styleSettings;
|
||||
};
|
||||
|
||||
@@ -61,9 +61,11 @@ private Q_SLOTS:
|
||||
void preprocessorContinuation();
|
||||
void cStyleComments();
|
||||
void cppStyleComments();
|
||||
void expressionContinuation();
|
||||
void expressionContinuation1();
|
||||
void expressionContinuation2();
|
||||
void assignContinuation1();
|
||||
void assignContinuation2();
|
||||
void declarationContinuation();
|
||||
void classAccess();
|
||||
void ternary();
|
||||
void objcAtDeclarations();
|
||||
@@ -601,7 +603,7 @@ void tst_CodeFormatter::cppStyleComments()
|
||||
checkIndent(data);
|
||||
}
|
||||
|
||||
void tst_CodeFormatter::expressionContinuation()
|
||||
void tst_CodeFormatter::expressionContinuation1()
|
||||
{
|
||||
QList<Line> data;
|
||||
data << Line("void foo() {")
|
||||
@@ -628,9 +630,27 @@ void tst_CodeFormatter::expressionContinuation()
|
||||
<< Line(" ~ foo - blah(1)")
|
||||
<< Line(" ~ << '?'")
|
||||
<< Line(" ~ << \"\\n\";")
|
||||
<< Line(" i += foo(")
|
||||
<< Line("}")
|
||||
;
|
||||
checkIndent(data);
|
||||
}
|
||||
|
||||
void tst_CodeFormatter::expressionContinuation2()
|
||||
{
|
||||
QList<Line> data;
|
||||
data << Line("void foo() {")
|
||||
<< Line(" i += abc +")
|
||||
<< Line(" ~ foo(,")
|
||||
<< Line(" ~ bar,")
|
||||
<< Line(" ~ 2);")
|
||||
<< Line(" ~ 2")
|
||||
<< Line(" ~ );")
|
||||
<< Line(" i += abc +")
|
||||
<< Line(" ~ foo(,")
|
||||
<< Line(" ~ bar(")
|
||||
<< Line(" ~ bar,")
|
||||
<< Line(" ~ 2")
|
||||
<< Line(" ~ ),")
|
||||
<< Line(" ~ abc);")
|
||||
<< Line("}")
|
||||
;
|
||||
checkIndent(data);
|
||||
@@ -676,6 +696,18 @@ void tst_CodeFormatter::assignContinuation2()
|
||||
checkIndent(data, style);
|
||||
}
|
||||
|
||||
void tst_CodeFormatter::declarationContinuation()
|
||||
{
|
||||
QList<Line> data;
|
||||
data << Line("void foo(")
|
||||
<< Line("~ int a,")
|
||||
<< Line("~ int b);")
|
||||
<< Line("void foo(int a,")
|
||||
<< Line("~ int b);")
|
||||
;
|
||||
checkIndent(data);
|
||||
}
|
||||
|
||||
void tst_CodeFormatter::classAccess()
|
||||
{
|
||||
QList<Line> data;
|
||||
|
||||
Reference in New Issue
Block a user