diff options
author | Semih Yavuz <semih.yavuz@qt.io> | 2024-01-15 21:36:22 +0100 |
---|---|---|
committer | Semih Yavuz <semih.yavuz@qt.io> | 2024-02-22 17:59:35 +0100 |
commit | 9ee160941064f2c18f5a2197bf85c6e8af979826 (patch) | |
tree | 2b78d81f1c5922d2dfb7e35d160892a33c5ca1ca /src/qmldom/qqmldomcomments_p.h | |
parent | b0cc4d02407a0af5521a064c366b12ecc41448f4 (diff) |
qqmldomcomments: link comments to nodes or regions by CommentCollector
That used to live in AstComments which actually represents comments
linked to AST::Node's. Instead, let's use a separate class for this job.
Document and refactor methods which link comments to the elements and
provide readable variable names.
Task-number: QTBUG-120484
Change-Id: Ie238b9bab5f610c7cdb08a16f0cbf4802e922306
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'src/qmldom/qqmldomcomments_p.h')
-rw-r--r-- | src/qmldom/qqmldomcomments_p.h | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/qmldom/qqmldomcomments_p.h b/src/qmldom/qqmldomcomments_p.h index 39fa5a1878..65f730dbb3 100644 --- a/src/qmldom/qqmldomcomments_p.h +++ b/src/qmldom/qqmldomcomments_p.h @@ -80,7 +80,7 @@ public: { } Comment(QStringView c, int newlinesBefore = 1, CommentType type = Pre) - : m_comment(c), m_newlinesBefore(newlinesBefore), m_type(type) + : m_comment(c), m_newlinesBefore(newlinesBefore), m_type(type) { } @@ -130,7 +130,7 @@ public: if (comment.type() == Comment::CommentType::Pre) m_preComments.append(comment); else - m_postComments.append(comment); + m_postComments.append(comment); } const QList<Comment> &preComments() const { return m_preComments;} @@ -211,11 +211,6 @@ public: } Path canonicalPath(const DomItem &self) const override { return self.m_ownerPath; } - static void collectComments(MutableDomItem &item); - static void collectComments( - const std::shared_ptr<Engine> &engine, AST::Node *n, - const std::shared_ptr<AstComments> &collectComments, const MutableDomItem &rootItem, - const FileLocations::Tree &rootItemLocations); AstComments(const std::shared_ptr<Engine> &e) : m_engine(e) { } AstComments(const AstComments &o) : OwningItem(o), m_engine(o.m_engine), m_commentedElements(o.m_commentedElements) @@ -226,6 +221,12 @@ public: { return m_commentedElements; } + + QHash<AST::Node *, CommentedElement> &commentedElements() + { + return m_commentedElements; + } + CommentedElement *commentForNode(AST::Node *n) { if (m_commentedElements.contains(n)) @@ -239,6 +240,20 @@ private: QHash<AST::Node *, CommentedElement> m_commentedElements; }; +class CommentCollector +{ +public: + CommentCollector() = default; + CommentCollector(MutableDomItem item); + void collectComments(); + void collectComments(const std::shared_ptr<Engine> &engine, AST::Node *rootNode, + const std::shared_ptr<AstComments> &astComments); + +private: + MutableDomItem m_rootItem; + FileLocations::Tree m_fileLocations; +}; + class VisitAll : public AST::Visitor { public: |