forked from qt-creator/qt-creator
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: Erik Verbruggen <erik.verbruggen@nokia.com> Sanity-Review: Erik Verbruggen <erik.verbruggen@nokia.com>
This commit is contained in:
@@ -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"
|
||||
|
Reference in New Issue
Block a user