diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2010-07-15 16:14:22 +0200 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2010-07-15 16:15:09 +0200 |
commit | 1a61ae01cb4ac0eaa175cd6d7859e0a3b49c6a05 (patch) | |
tree | 4379c5e3156c8c9ac5beadd462022460728cb11e /src/plugins/cpptools/cppcodeformatter.cpp | |
parent | 9b24e0ae2af9523691f99a30bca9e83200bfd6d9 (diff) | |
download | qt-creator-1a61ae01cb4ac0eaa175cd6d7859e0a3b49c6a05.tar.gz |
C++ indenter: Respect user indent with stream operators.
Reviewed-by: Erik Verbruggen
Diffstat (limited to 'src/plugins/cpptools/cppcodeformatter.cpp')
-rw-r--r-- | src/plugins/cpptools/cppcodeformatter.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp index 75fe53fda8..a17488ac1d 100644 --- a/src/plugins/cpptools/cppcodeformatter.cpp +++ b/src/plugins/cpptools/cppcodeformatter.cpp @@ -203,9 +203,17 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block) } break; case stream_op: - if (tryExpression()) + case stream_op_cont: + if (kind != T_LESS_LESS && kind != T_GREATER_GREATER && tryExpression()) break; switch (kind) { + case T_LESS_LESS: + case T_GREATER_GREATER: + if (m_currentState.top().type == stream_op) + enter(stream_op_cont); + else // stream_op_cont already + turnInto(stream_op_cont); + break; case T_COMMA: case T_SEMICOLON: leave(); continue; // always nested, propagate semicolon } break; @@ -604,12 +612,10 @@ bool CodeFormatter::tryExpression(bool alsoExpression) case T_LESS_LESS: case T_GREATER_GREATER: - // don't go into stream operator state inside arglist_open - // or another stream_op newState = stream_op; for (int i = m_currentState.size() - 1; i >= 0; --i) { const int type = m_currentState.at(i).type; - if (type == arglist_open || type == stream_op) { + if (type == arglist_open) { // likely a left-shift instead newState = -1; break; } @@ -1020,6 +1026,10 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd case stream_op: *indentDepth = tokenPosition + tk.length() + 1; break; + case stream_op_cont: + if (firstToken) + *savedIndentDepth = *indentDepth = tokenPosition + tk.length() + 1; + break; case member_init_open: // undo the continuation indent of the parent @@ -1257,7 +1267,7 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i break; case T_LESS_LESS: case T_GREATER_GREATER: - if (topState.type == stream_op) + if (topState.type == stream_op || topState.type == stream_op_cont) *indentDepth -= 3; // to align << with << break; case T_COMMENT: |