summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2012-09-10 10:39:16 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2012-09-10 14:21:57 +0200
commit0df593353953614e2657b5ddb6f31e1b2e9bcd49 (patch)
tree76de1842d493be35eca98f44c8acbbefb073a85d
parentb17e944d4bbff3cce7a9a2e9aab7e8b910ca8ad8 (diff)
downloadqt-creator-0df593353953614e2657b5ddb6f31e1b2e9bcd49.tar.gz
QmlJS indenter: Fix wrong indentation after list<> typed properties.
Task-number: QTCREATORBUG-7726 Change-Id: If709a9a71cfed69e2f14af92c114f79d11d03145 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
-rw-r--r--src/libs/qmljs/qmljscodeformatter.cpp8
-rw-r--r--src/libs/qmljs/qmljscodeformatter.h4
-rw-r--r--tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp16
3 files changed, 22 insertions, 6 deletions
diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp
index 1a6d853a93..7eddf86e2b 100644
--- a/src/libs/qmljs/qmljscodeformatter.cpp
+++ b/src/libs/qmljs/qmljscodeformatter.cpp
@@ -198,18 +198,18 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
switch (kind) {
case Colon: enter(binding_assignment); break; // oops, was a binding
case Var:
- case Identifier: enter(property_type); break;
+ case Identifier: enter(property_name); break;
case List: enter(property_list_open); break;
default: leave(true); continue;
} break;
- case property_type:
+ case property_name:
turnInto(property_maybe_initializer);
break;
case property_list_open:
if (m_currentLine.midRef(m_currentToken.begin(), m_currentToken.length) == QLatin1String(">"))
- turnInto(property_maybe_initializer);
+ turnInto(property_name);
break;
case property_maybe_initializer:
@@ -939,7 +939,7 @@ CodeFormatter::TokenKind CodeFormatter::extendedTokenKind(const QmlJS::Token &to
if (text == "on")
return On;
if (text == "list")
- return On;
+ return List;
} else if (kind == Keyword) {
const QChar char1 = text.at(0);
const QChar char2 = text.at(1);
diff --git a/src/libs/qmljs/qmljscodeformatter.h b/src/libs/qmljs/qmljscodeformatter.h
index ff964280b8..22bf926a78 100644
--- a/src/libs/qmljs/qmljscodeformatter.h
+++ b/src/libs/qmljs/qmljscodeformatter.h
@@ -110,9 +110,9 @@ public: // must be public to make Q_GADGET introspection work
property_start, // after 'property'
default_property_start, // after 'default'
- property_type, // after first identifier
property_list_open, // after 'list' as a type
- property_maybe_initializer, // after
+ property_name, // after the type
+ property_maybe_initializer, // after the identifier
signal_start, // after 'signal'
signal_maybe_arglist, // after identifier
diff --git a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
index a6a0cb3ed0..3c9ace21b8 100644
--- a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
+++ b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
@@ -108,6 +108,7 @@ private Q_SLOTS:
void multilineString();
void bug1();
void bug2();
+ void bug3();
};
enum { DontCheck = -2, DontIndent = -1 };
@@ -1557,6 +1558,21 @@ void tst_QMLCodeFormatter::bug2()
checkIndent(data);
}
+void tst_QMLCodeFormatter::bug3()
+{
+ QList<Line> data;
+ data << Line("Item {")
+ << Line(" property list<Item> foo")
+ << Line(" function f() {")
+ << Line(" if (1 > 0) {")
+ << Line(" foo = 1")
+ << Line(" }")
+ << Line(" }")
+ << Line("}")
+ ;
+ checkIndent(data);
+}
+
QTEST_APPLESS_MAIN(tst_QMLCodeFormatter)
#include "tst_qmlcodeformatter.moc"