From d0823cd5e2c6d59929fdabd96495eb1ae6e69a0d Mon Sep 17 00:00:00 2001 From: Marco Benelli Date: Wed, 5 Apr 2017 11:19:05 +0200 Subject: [PATCH] QmlJs: fix reformatting of 'signal' statements Reformatting 'signal' preceded by comments used to bring to a bad formatted file. Task-number: QTCREATORBUG-17886 Change-Id: I02e093a4721cd1e75d45b498ea768251aee88ea4 Reviewed-by: Tim Jenssen --- src/libs/qmljs/qmljsreformatter.cpp | 8 ++++++-- tests/auto/qml/reformatter/comments.qml | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libs/qmljs/qmljsreformatter.cpp b/src/libs/qmljs/qmljsreformatter.cpp index ab43c037067..6c4befa0f84 100644 --- a/src/libs/qmljs/qmljsreformatter.cpp +++ b/src/libs/qmljs/qmljsreformatter.cpp @@ -150,8 +150,12 @@ protected: void outCommentText(const QString &str) { QStringList lines = str.split(QLatin1Char('\n')); + bool multiline = lines.length() > 1; for (int i = 0; i < lines.size(); ++i) { - _line = lines.at(i); // multiline comments don't keep track of previos lines + if (multiline) + _line = lines.at(i); // multiline comments don't keep track of previos lines + else + _line += lines.at(i); if (i != lines.size() - 1) newLine(); } @@ -582,7 +586,7 @@ protected: out(ast->identifierToken); } } else { // signal - out("signal "); + out("signal ", ast->identifierToken); out(ast->identifierToken); if (ast->parameters) { out("("); diff --git a/tests/auto/qml/reformatter/comments.qml b/tests/auto/qml/reformatter/comments.qml index 61889ea0079..5bffa03d814 100644 --- a/tests/auto/qml/reformatter/comments.qml +++ b/tests/auto/qml/reformatter/comments.qml @@ -13,4 +13,14 @@ Item { /* Indented multiline comment. */ + + // Comment over a signal. + signal foo + + function test() { + for (var i = model.count - 1; i >= 0; --i) // in-line comment + { + console.log("test") + } + } }