diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2010-11-04 14:07:58 +0100 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2010-11-04 14:09:47 +0100 |
commit | d2468a4491109dd5132b51576c326e4f657a84ce (patch) | |
tree | b844b99cbb1c901ea23956ecf3b4c04572629a94 /src/plugins/cpptools/cppcodeformatter.cpp | |
parent | 338a349dffc21c7a05eefe844c4acc789de8e9a4 (diff) | |
download | qt-creator-d2468a4491109dd5132b51576c326e4f657a84ce.tar.gz |
C++ indenter: Fix for GNU and Whitesmiths style switch statement.
Task-number: QTCREATORBUG-2994
Diffstat (limited to 'src/plugins/cpptools/cppcodeformatter.cpp')
-rw-r--r-- | src/plugins/cpptools/cppcodeformatter.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp index 03fe1d9096..497a2cfae6 100644 --- a/src/plugins/cpptools/cppcodeformatter.cpp +++ b/src/plugins/cpptools/cppcodeformatter.cpp @@ -1198,7 +1198,11 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd break; case block_open: - if (parentState.type != case_cont) + // case_cont already adds some indent, revert it for a block + if (parentState.type == case_cont && !m_indentSubstatementBraces) + *indentDepth = *savedIndentDepth = parentState.savedIndentDepth; + + if (m_indentSubstatementStatements) *indentDepth += m_indentSize; break; @@ -1302,6 +1306,8 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i case T_LBRACE: { if (topState.type == case_cont) { *indentDepth = topState.savedIndentDepth; + if (m_indentSubstatementBraces) + *indentDepth += m_indentSize; *paddingDepth = 0; // function definition - argument list is expression state } else if (topState.type == expression && previousState.type == declaration_start) { @@ -1332,8 +1338,8 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i } case T_RBRACE: { if (topState.type == block_open && previousState.type == case_cont) { - *indentDepth = previousState.savedIndentDepth; - *paddingDepth = previousState.savedPaddingDepth; + *indentDepth = topState.savedIndentDepth; + *paddingDepth = topState.savedPaddingDepth; break; } for (int i = 0; state(i).type != topmost_intro; ++i) { @@ -1365,10 +1371,16 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i // } // break; case T_DEFAULT: - case T_CASE: + case T_CASE: { + int lastSubstatementIndent = 0; for (int i = 0; state(i).type != topmost_intro; ++i) { const int type = state(i).type; - if (type == switch_statement || type == case_cont) { + if (type == substatement_open) { + lastSubstatementIndent = state(i).savedIndentDepth; + } else if (type == switch_statement) { + *indentDepth = lastSubstatementIndent; + break; + } else if (type == case_cont) { *indentDepth = state(i).savedIndentDepth; break; } else if (type == topmost_intro) { @@ -1376,6 +1388,7 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i } } break; + } case T_PUBLIC: case T_PRIVATE: case T_PROTECTED: |