diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2023-09-29 15:32:33 +0200 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2023-11-01 21:30:44 +0100 |
commit | 720daec0ca6e5157f5b6cc1769b6ace8c7dd0daf (patch) | |
tree | 632e6166f6446dd9bcb2172bdb687bfb679ae79f /src/qmldom/qqmldomcomments_p.h | |
parent | af6573093f0fe9d4b45608644ca410adf9168d7e (diff) |
qmldom: introduce FileLocationRegion enum as key for sourcelocations
Previously in the Dom, SourceLocations and comments were stored in
QMaps and keyed by strings (so-called region names). This commit
replaces the string keys with a newly introduced enum called
FileLocationRegion.
Replace the QMaps in
FileLocations::{regions,preCommentLocations,postCommentLocations} and
RegionComments::{preComments,postComments} to key by FileLocationRegion
enum instead of string, along with all their usages.
The DomItem Dom::Map interface requires the above-mentioned maps to be able to key
by string, so implement two helper methods fileLocationRegionValue() and
fileLocationRegionName() in qqmldom_utils that can translate a string to
FileLocationRegion and back. Those two helpers are used to construct a
Dom::Map in Map::fromFileRegionMap and Map::fromFileRegionListMap.
Add a test for Dom::Map constructed in that way.
Change-Id: I185a4114c9db9f86d9e219079d12d833abfe590e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmldom/qqmldomcomments_p.h')
-rw-r--r-- | src/qmldom/qqmldomcomments_p.h | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/qmldom/qqmldomcomments_p.h b/src/qmldom/qqmldomcomments_p.h index 7f7d4b9c9d..085a537142 100644 --- a/src/qmldom/qqmldomcomments_p.h +++ b/src/qmldom/qqmldomcomments_p.h @@ -142,29 +142,29 @@ public: return !(c1 == c2); } - Path addPreComment(const Comment &comment, QString regionName) + Path addPreComment(const Comment &comment, FileLocationRegion region) { - auto &preList = regionComments[regionName].preComments; + auto &preList = regionComments[region].preComments; index_type idx = preList.size(); preList.append(comment); return Path::Field(Fields::regionComments) - .key(regionName) + .key(fileLocationRegionName(region)) .field(Fields::preComments) .index(idx); } - Path addPostComment(const Comment &comment, QString regionName) + Path addPostComment(const Comment &comment, FileLocationRegion region) { - auto &postList = regionComments[regionName].postComments; + auto &postList = regionComments[region].postComments; index_type idx = postList.size(); postList.append(comment); return Path::Field(Fields::regionComments) - .key(regionName) + .key(fileLocationRegionName(region)) .field(Fields::postComments) .index(idx); } - QMap<QString, CommentedElement> regionComments; + QMap<FileLocationRegion, CommentedElement> regionComments; }; class QMLDOM_EXPORT AstComments final : public OwningItem |