aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmlformat/qmlformat.cpp
diff options
context:
space:
mode:
authorDmitrii Akshintsev <dmitrii.akshintsev@qt.io>2023-12-05 10:42:23 +0100
committerDmitrii Akshintsev <dmitrii.akshintsev@qt.io>2024-01-25 18:35:04 +0100
commitade897c021be7089a86702de3e9e626ab8cb7648 (patch)
treefd16b199e7fb78332caf21f0f32b733c22e09860 /tools/qmlformat/qmlformat.cpp
parent32041ca0b9196a4997ec3c6157e1703e853126c2 (diff)
QQmlJS::Dom::OutWriter. Refactoring
The refactoring consists of: - Changing writeOut & writeOutForFile API to return boolean instead of MutableDomItem, which better reflects the existing usecases improving consistency of the data model* Moreover, previous API was exposing DomItem, which was not "committed to base" (MutableDomItem.commitToBase()), meaning it was exposing the "unmerged" Item alongside with the "temporary environment" - Refactoring & renaming OutWriter::updatedFile breaking it into smaller chunks preserving only necessary functionality - Adding some comments / documentation Before this commit, the writeOut API was "exposing",so called, "updatedFile", which is basically the copy of the original fileItem + renewed scriptExpressions which were modified during the writeOut of the original fileItem. The idea behind the "mutating" Dom API is that one has to create a MutableDomItem, do some changes to it and then "commit" them. This process is also facilitated by the creation of separate Env. (git analogy might be handy here: We create a separate branch, where all the mutation will happen and then we "merge" this branch) However, in the writeOutForFile usecase this "updatedFile" was needed only for the verifying of the consistency of the "writtenOut" DOM, however the API was exposing it further back to the caller sites, without "committing". The potential issue here is inconsistency of the data Model. On one side we have an original File Item owned by the Base Env, on the other side we have an "updatedFile" which is owned by another Env. Taking into account that there are no usecases requiring "exposing" "updatedFile", but also no need for "committing" the changes, It's arguably better to keep that temporary "updatedFile" locally, not exposing it outside the writeOutForFile function. Thereby improving consistency of the data model. Change-Id: If45eca4b4d6d703e2a76d0580f124d0292af5ed8 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Diffstat (limited to 'tools/qmlformat/qmlformat.cpp')
-rw-r--r--tools/qmlformat/qmlformat.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/tools/qmlformat/qmlformat.cpp b/tools/qmlformat/qmlformat.cpp
index 9ef37f7800..e6dd518cb6 100644
--- a/tools/qmlformat/qmlformat.cpp
+++ b/tools/qmlformat/qmlformat.cpp
@@ -168,7 +168,7 @@ static bool parseFile(const QString &filename, const Options &options)
checks = WriteOutCheck::None;
}
- MutableDomItem res;
+ bool res = false;
if (options.inplace) {
if (options.verbose)
qWarning().noquote() << "Writing to file" << filename;
@@ -183,7 +183,7 @@ static bool parseFile(const QString &filename, const Options &options)
res = fileItem.writeOutForFile(ow, checks);
ow.flush();
}
- return bool(res);
+ return res;
}
Options buildCommandLineOptions(const QCoreApplication &app)