aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmlformat/qmlformat.cpp
diff options
context:
space:
mode:
authorSemih Yavuz <semih.yavuz@qt.io>2025-09-23 15:52:46 +0200
committerSemih Yavuz <semih.yavuz@qt.io>2025-10-01 15:17:41 +0200
commitfaab91858f12b422d246c1d2fd356096def51c7c (patch)
tree4c24fa5d7298edae1909799b17ba2f355c0a2fb8 /tools/qmlformat/qmlformat.cpp
parent4486e9c1a41d467642c47bfd960b84d8620f2551 (diff)
qmlformat: expand OutWriter's constructor
code and comment location information is needed by OutWriter to scan format directives. Allow these to be created at OutWriters' construction. Get this informations through ExternalOwningItem interface. Unfortunately, ExternalOwningItem interface won't provide comment() or engine(). Use derived types to get that information for JSFile and QmlFile. Task-number: QTBUG-97796 Change-Id: I57ef2a3a52579dd5698219a6e6ac9449c113d080 Reviewed-by: Dmitrii Akshintsev <dmitrii.akshintsev@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'tools/qmlformat/qmlformat.cpp')
-rw-r--r--tools/qmlformat/qmlformat.cpp19
1 files changed, 1 insertions, 18 deletions
diff --git a/tools/qmlformat/qmlformat.cpp b/tools/qmlformat/qmlformat.cpp
index 13566fb503..f74ffab566 100644
--- a/tools/qmlformat/qmlformat.cpp
+++ b/tools/qmlformat/qmlformat.cpp
@@ -38,23 +38,6 @@ static void logParsingErrors(const DomItem &fileItem, const QString &filename)
qWarning().noquote() << "Failed to parse" << filename;
}
-// TODO
-// refactor this workaround. ExternalOWningItem is not recognized as an owning type
-// in ownerAs.
-static std::shared_ptr<ExternalOwningItem> getFileItemOwner(const DomItem &fileItem)
-{
- std::shared_ptr<ExternalOwningItem> filePtr = nullptr;
- switch (fileItem.internalKind()) {
- case DomType::JsFile:
- filePtr = fileItem.ownerAs<JsFile>();
- break;
- default:
- filePtr = fileItem.ownerAs<QmlFile>();
- break;
- }
- return filePtr;
-}
-
// TODO refactor
// Introduce better encapsulation and separation of concerns and move to DOM API
// returns a DomItem corresponding to the loaded file and bool indicating the validity of the file
@@ -107,7 +90,7 @@ static bool parseFile(const QString &filename, const QQmlFormatOptions &options)
if (out.open(stdout, QIODevice::WriteOnly)) {
auto lw = createLineWriter([&out](QStringView s) { out.write(s.toUtf8()); }, filename,
lwOptions);
- OutWriter ow(*lw);
+ OutWriter ow(getFileItemOwner(fileItem), *lw);
res = fileItem.writeOutForFile(ow, checks);
ow.flush();
} else {