aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/parser/qqmljs.g5
-rw-r--r--src/qml/parser/qqmljsast_p.h2
-rw-r--r--src/qmldom/qqmldomastcreator.cpp9
-rw-r--r--src/qmldom/qqmldomcomments.cpp8
-rw-r--r--src/qmldom/qqmldomelements.cpp10
-rw-r--r--tests/auto/qml/qmlformat/data/commentsStressTest_enum.formatted.qml10
-rw-r--r--tests/auto/qml/qmlformat/data/commentsStressTest_enum.qml12
-rw-r--r--tests/auto/qml/qmlformat/tst_qmlformat.cpp4
-rw-r--r--tests/auto/qmlls/modules/tst_qmlls_modules.cpp3
9 files changed, 43 insertions, 20 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g
index 0bd9ce0f2e..03f7777dc4 100644
--- a/src/qml/parser/qqmljs.g
+++ b/src/qml/parser/qqmljs.g
@@ -1630,6 +1630,7 @@ EnumMemberList: EnumMemberList T_COMMA T_IDENTIFIER;
/.
case $rule_number: {
AST::UiEnumMemberList *node = new (pool) AST::UiEnumMemberList(sym(1).UiEnumMemberList, stringRef(3));
+ node->commaToken = loc(2);
node->memberToken = loc(3);
sym(1).Node = node;
break;
@@ -1640,7 +1641,9 @@ EnumMemberList: EnumMemberList T_COMMA T_IDENTIFIER T_EQ T_NUMERIC_LITERAL;
/.
case $rule_number: {
AST::UiEnumMemberList *node = new (pool) AST::UiEnumMemberList(sym(1).UiEnumMemberList, stringRef(3), sym(5).dval);
+ node->commaToken = loc(2);
node->memberToken = loc(3);
+ node->equalToken = loc(4);
node->valueToken = loc(5);
sym(1).Node = node;
break;
@@ -1652,7 +1655,9 @@ EnumMemberList: EnumMemberList T_COMMA T_IDENTIFIER T_EQ T_MINUS T_NUMERIC_LITER
/.
case $rule_number: {
AST::UiEnumMemberList *node = new (pool) AST::UiEnumMemberList(sym(1).UiEnumMemberList, stringRef(3), -sym(6).dval);
+ node->commaToken = loc(2);
node->memberToken = loc(3);
+ node->equalToken = loc(4);
node->valueToken = combine(loc(5), loc(6));
sym(1).Node = node;
break;
diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h
index 50186fe27b..91e49f6be8 100644
--- a/src/qml/parser/qqmljsast_p.h
+++ b/src/qml/parser/qqmljsast_p.h
@@ -3789,7 +3789,9 @@ public:
UiEnumMemberList *next;
QStringView member;
double value;
+ SourceLocation commaToken;
SourceLocation memberToken;
+ SourceLocation equalToken;
SourceLocation valueToken;
};
diff --git a/src/qmldom/qqmldomastcreator.cpp b/src/qmldom/qqmldomastcreator.cpp
index 9b9ad035b1..c36acd1a8f 100644
--- a/src/qmldom/qqmldomastcreator.cpp
+++ b/src/qmldom/qqmldomastcreator.cpp
@@ -1342,6 +1342,8 @@ bool QQmlDomAstCreator::visit(AST::UiEnumDeclaration *el)
pushEl(enumPathFromOwner, *ePtr, el);
FileLocations::addRegion(nodeStack.last().fileLocations, EnumKeywordRegion, el->enumToken);
FileLocations::addRegion(nodeStack.last().fileLocations, IdentifierRegion, el->identifierToken);
+ FileLocations::addRegion(nodeStack.last().fileLocations, LeftBraceRegion, el->lbraceToken);
+ FileLocations::addRegion(nodeStack.last().fileLocations, RightBraceRegion, el->rbraceToken);
loadAnnotations(el);
return true;
}
@@ -1364,11 +1366,16 @@ bool QQmlDomAstCreator::visit(AST::UiEnumMemberList *el)
EnumDecl &eDecl = std::get<EnumDecl>(currentNode().value);
Path itPathFromDecl = eDecl.addValue(it);
const auto map = createMap(DomType::EnumItem, itPathFromDecl, nullptr);
- FileLocations::addRegion(map, MainRegion, combine(el->memberToken, el->valueToken));
+ if (el->commaToken.isValid())
+ FileLocations::addRegion(map, CommaTokenRegion, el->commaToken);
if (el->memberToken.isValid())
FileLocations::addRegion(map, IdentifierRegion, el->memberToken);
+ if (el->equalToken.isValid())
+ FileLocations::addRegion(map, EqualTokenRegion, el->equalToken);
if (el->valueToken.isValid())
FileLocations::addRegion(map, EnumValueRegion, el->valueToken);
+ FileLocations::addRegion(
+ map, MainRegion, combine(combine(el->memberToken, el->commaToken), el->valueToken));
return true;
}
diff --git a/src/qmldom/qqmldomcomments.cpp b/src/qmldom/qqmldomcomments.cpp
index 9b7fd5b7a4..5f18f65824 100644
--- a/src/qmldom/qqmldomcomments.cpp
+++ b/src/qmldom/qqmldomcomments.cpp
@@ -492,14 +492,6 @@ const QSet<int> AstRangesVisitor::kindsToSkip()
bool AstRangesVisitor::shouldSkipRegion(const DomItem &item, FileLocationRegion region)
{
switch (item.internalKind()) {
- case DomType::EnumDecl: {
- return (region == FileLocationRegion::IdentifierRegion)
- || (region == FileLocationRegion::EnumKeywordRegion);
- }
- case DomType::EnumItem: {
- return (region == FileLocationRegion::IdentifierRegion)
- || (region == FileLocationRegion::EnumValueRegion);
- }
case DomType::QmlObject: {
return (region == FileLocationRegion::RightBraceRegion
|| region == FileLocationRegion::LeftBraceRegion);
diff --git a/src/qmldom/qqmldomelements.cpp b/src/qmldom/qqmldomelements.cpp
index 57e9024869..35defa7036 100644
--- a/src/qmldom/qqmldomelements.cpp
+++ b/src/qmldom/qqmldomelements.cpp
@@ -1412,10 +1412,8 @@ void EnumDecl::writeOut(const DomItem &self, OutWriter &ow) const
.writeRegion(LeftBraceRegion);
int iLevel = ow.increaseIndent(1);
const auto values = self.field(Fields::values).values();
- for (const auto &value : values) {
- ow.ensureNewline();
+ for (const auto &value : values)
value.writeOut(ow);
- }
ow.decreaseIndent(1, iLevel);
ow.ensureNewline().writeRegion(RightBraceRegion);
}
@@ -2088,17 +2086,17 @@ bool EnumItem::iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor)
void EnumItem::writeOut(const DomItem &self, OutWriter &ow) const
{
+ index_type myIndex = self.pathFromOwner().last().headIndex();
+ if (myIndex != 0)
+ ow.writeRegion(CommaTokenRegion);
ow.ensureNewline();
ow.writeRegion(IdentifierRegion, name());
- index_type myIndex = self.pathFromOwner().last().headIndex();
if (m_valueKind == ValueKind::ExplicitValue) {
QString v = QString::number(value(), 'f', 0);
if (abs(value() - v.toDouble()) > 1.e-10)
v = QString::number(value());
ow.ensureSpace().writeRegion(EqualTokenRegion).ensureSpace().writeRegion(EnumValueRegion, v);
}
- if (myIndex >= 0 && self.container().indexes() != myIndex + 1)
- ow.writeRegion(CommaTokenRegion);
}
QmlUri QmlUri::fromString(const QString &str)
diff --git a/tests/auto/qml/qmlformat/data/commentsStressTest_enum.formatted.qml b/tests/auto/qml/qmlformat/data/commentsStressTest_enum.formatted.qml
new file mode 100644
index 0000000000..ba8b95411f
--- /dev/null
+++ b/tests/auto/qml/qmlformat/data/commentsStressTest_enum.formatted.qml
@@ -0,0 +1,10 @@
+import QtQml
+
+QtObject {
+ enum /**/ Hello /**/ { /**/ //
+ /**/ //
+ World /**/ , /**/ //
+ Kitty /**/ = /**/ 33 /**/, /**/ //
+ Cat /**/ //
+ } /**/ //
+}
diff --git a/tests/auto/qml/qmlformat/data/commentsStressTest_enum.qml b/tests/auto/qml/qmlformat/data/commentsStressTest_enum.qml
new file mode 100644
index 0000000000..b0be68852c
--- /dev/null
+++ b/tests/auto/qml/qmlformat/data/commentsStressTest_enum.qml
@@ -0,0 +1,12 @@
+
+
+import QtQml
+
+QtObject {
+ enum /**/ Hello /**/ { /**/ //
+ /**/ //
+ World /**/ , /**/ //
+ Kitty /**/ = /**/ 33 /**/, /**/ //
+ Cat /**/ //
+ } /**/ //
+}
diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
index 525c0143cf..ee9129075b 100644
--- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp
+++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
@@ -366,6 +366,8 @@ void TestQmlformat::qml_data()
<< "fromAsIdentifier.formatted.qml";
QTest::newRow("finalProperties") << "finalProperties.qml"
<< "finalProperties.formatted.qml";
+ QTest::newRow("commentsStressTest_enum") << "commentsStressTest_enum.qml"
+ << "commentsStressTest_enum.formatted.qml";
}
void TestQmlformat::qml()
{
@@ -383,8 +385,6 @@ void TestQmlformat::qml()
auto exp = readTestFile(fileFormatted);
QEXPECT_FAIL("noSuperfluousSpaceInsertions.fail_id",
"Not all cases have been covered yet (QTBUG-133315, QTBUG-123386)", Abort);
- QEXPECT_FAIL("noSuperfluousSpaceInsertions.fail_enum",
- "Not all cases have been covered yet (QTBUG-133315, QTBUG-123386)", Abort);
QEXPECT_FAIL("noSuperfluousSpaceInsertions.fail_parameters",
"Not all cases have been covered yet (QTBUG-133315, QTBUG-123386)", Abort);
QCOMPARE(output, exp);
diff --git a/tests/auto/qmlls/modules/tst_qmlls_modules.cpp b/tests/auto/qmlls/modules/tst_qmlls_modules.cpp
index e8497ae49b..a7d766b52a 100644
--- a/tests/auto/qmlls/modules/tst_qmlls_modules.cpp
+++ b/tests/auto/qmlls/modules/tst_qmlls_modules.cpp
@@ -872,9 +872,6 @@ void tst_qmlls_modules::documentFormatting()
QCOMPARE(textEdit.range.end.line, lineCount(originalFile));
QCOMPARE(textEdit.range.end.character, 0);
- QEXPECT_FAIL("noSuperfluousSpaceInsertions.fail_enum.qml",
- "Not all cases have been covered yet (QTBUG-133315, QTBUG-123386)",
- Continue);
QEXPECT_FAIL("noSuperfluousSpaceInsertions.fail_id.qml",
"Not all cases have been covered yet (QTBUG-133315, QTBUG-123386)",
Continue);