Commit aa3d406f authored by Christian Kamm's avatar Christian Kamm
Browse files

C++ indenter: Accept attributes in access specifiers.

Change-Id: Ie85b8264c9579e8c8312e30018280fb11f95edda
Reviewed-on: http://codereview.qt-project.org/6328


Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@nokia.com>
Sanity-Review: Erik Verbruggen <erik.verbruggen@nokia.com>
parent 6a988ee8
......@@ -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;
......
......@@ -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.
......
......@@ -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"
......
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