Commit 904a1d78 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

CppTools: Fix indentation of stream operators after string



Task-number: QTCREATORBUG-12053
Change-Id: Ia34165d860bd7fd371a84a8349bed7a3fe1c01a9
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 60c4235b
...@@ -1437,8 +1437,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd ...@@ -1437,8 +1437,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
break; break;
case string_open: case string_open:
*indentDepth = tokenPosition; *paddingDepth = tokenPosition - *indentDepth;
*paddingDepth = 0;
break; break;
} }
...@@ -1467,16 +1466,25 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i ...@@ -1467,16 +1466,25 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
// adjusting the indentDepth here instead of in enter() gives 'else if' the correct indentation // adjusting the indentDepth here instead of in enter() gives 'else if' the correct indentation
// ### could be moved? // ### could be moved?
if (topState.type == substatement) switch (topState.type) {
case substatement:
*indentDepth += m_tabSettings.m_indentSize; *indentDepth += m_tabSettings.m_indentSize;
break;
// keep user-adjusted indent in multiline comments // keep user-adjusted indent in multiline comments
if (topState.type == multiline_comment_start case multiline_comment_start:
|| topState.type == multiline_comment_cont) { case multiline_comment_cont:
if (!tokens.isEmpty()) { if (!tokens.isEmpty()) {
*indentDepth = column(tokens.at(0).bytesBegin()); *indentDepth = column(tokens.at(0).bytesBegin());
return; return;
} }
break;
case string_open:
if (!tokenAt(0).isStringLiteral()) {
*paddingDepth = topState.savedPaddingDepth;
topState = previousState;
previousState = state(2);
}
break;
} }
const int kind = tokenAt(0).kind(); const int kind = tokenAt(0).kind();
......
...@@ -634,6 +634,8 @@ void tst_CodeFormatter::expressionContinuation1() ...@@ -634,6 +634,8 @@ void tst_CodeFormatter::expressionContinuation1()
<< Line(" ~ << bar +") << Line(" ~ << bar +")
<< Line(" ~ foo - blah(1)") << Line(" ~ foo - blah(1)")
<< Line(" ~ << '?'") << Line(" ~ << '?'")
<< Line(" ~ << \"string\"")
<< Line(" ~ \" concatenated\"")
<< Line(" ~ << \"\\n\";") << Line(" ~ << \"\\n\";")
<< Line("}") << Line("}")
; ;
...@@ -2159,13 +2161,13 @@ void tst_CodeFormatter::strings() ...@@ -2159,13 +2161,13 @@ void tst_CodeFormatter::strings()
{ {
QList<Line> data; QList<Line> data;
data << Line("char *a = \"foo\"") data << Line("char *a = \"foo\"")
<< Line(" \"bar\" \"why\"") << Line("~ \"bar\" \"why\"")
<< Line(" \"baz\";") << Line("~ \"baz\";")
<< Line("void foo()") << Line("void foo()")
<< Line("{") << Line("{")
<< Line(" func(1, 2, \"foo\"") << Line(" func(1, 2, \"foo\"")
<< Line(" \"bar\"") << Line(" ~ \"bar\"")
<< Line(" \"baz\", 4,") << Line(" ~ \"baz\", 4,")
<< Line(" ~ 5, 6);") << Line(" ~ 5, 6);")
<< Line("}") << Line("}")
; ;
......
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