diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp index 203e73057ebda636b1de6dc62e4a68a7c325326f..6ac322cad6d4f75adae01ef6c8d3b18dd82c806f 100644 --- a/src/plugins/cpptools/cppcodeformatter.cpp +++ b/src/plugins/cpptools/cppcodeformatter.cpp @@ -137,6 +137,11 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block) case T_RBRACE: leave(); continue; // always nested in class_start } break; + case access_specifier_start: + switch (kind) { + case T_COLON: leave(); break; + } break; + case enum_start: switch (kind) { case T_SEMICOLON: leave(); break; @@ -817,6 +822,16 @@ bool CodeFormatter::tryDeclaration() enter(using_start); return true; + case T_PUBLIC: + case T_PRIVATE: + case T_PROTECTED: + case T_Q_SIGNALS: + if (m_currentState.top().type == class_open) { + enter(access_specifier_start); + return true; + } + return false; + default: return false; } @@ -1473,7 +1488,8 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i case T_Q_SIGNALS: if (m_styleSettings.indentDeclarationsRelativeToAccessSpecifiers && topState.type == class_open) { - if (tokenAt(1).is(T_COLON) || tokenAt(2).is(T_COLON)) { + if (tokenAt(1).is(T_COLON) || tokenAt(2).is(T_COLON) + || (tokenAt(tokenCount() - 1).is(T_COLON) && tokenAt(1).is(T___ATTRIBUTE__))) { *indentDepth = topState.savedIndentDepth; if (m_styleSettings.indentAccessSpecifiers) *indentDepth += m_tabSettings.m_indentSize; diff --git a/src/plugins/cpptools/cppcodeformatter.h b/src/plugins/cpptools/cppcodeformatter.h index dae19a2e249efc3ebf65a68bd88806a53f98ad05..38ae9cf45bfe1ee83e6dc27ea0128e90a144cb47 100644 --- a/src/plugins/cpptools/cppcodeformatter.h +++ b/src/plugins/cpptools/cppcodeformatter.h @@ -121,6 +121,8 @@ public: // must be public to make Q_GADGET introspection work class_start, // after the 'class' token class_open, // Brace that opens a class definition. + access_specifier_start, // after 'private', 'protected' etc. + member_init_open, // After ':' that starts a member initialization list. member_init, // At the start and after every ',' in member_init_open member_init_paren_open, // After '(' in member_init. diff --git a/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp b/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp index 1b882e16145d728cf24b801f8431ad8e13b107b5..c142f7cf3d0a266ea04ae9eeed4ecbb5e7df8568 100644 --- a/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp +++ b/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp @@ -125,6 +125,7 @@ private Q_SLOTS: void caseBody6(); void blockBraces1(); void functionDefaultArgument(); + void attributeInAccessSpecifier(); }; struct Line { @@ -1990,6 +1991,20 @@ void tst_CodeFormatter::functionDefaultArgument() checkIndent(data); } +void tst_CodeFormatter::attributeInAccessSpecifier() +{ + QList<Line> data; + data << Line("class C {") + << Line("public __attribute__((annotate(\"foo\"))):") + << Line(" int a;") + << Line("private __attribute__((annotate(\"foo\"))):") + << Line(" int a;") + << Line("};") + << Line("int b;") + ; + checkIndent(data); +} + QTEST_APPLESS_MAIN(tst_CodeFormatter) #include "tst_codeformatter.moc"