Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QQmlJS::Dom::AstComments Class Referencefinal

Associates comments with AST::Node *. More...

#include <qqmldomcomments_p.h>

+ Inheritance diagram for QQmlJS::Dom::AstComments:
+ Collaboration diagram for QQmlJS::Dom::AstComments:

Public Member Functions

DomType kind () const override
 
bool iterateDirectSubpaths (DomItem &self, DirectVisitor) override
 
std::shared_ptr< AstCommentsmakeCopy (DomItem &self) const
 
Path canonicalPath (DomItem &self) const override
 
 AstComments (std::shared_ptr< Engine > e)
 
 AstComments (const AstComments &o)
 
const QHash< AST::Node *, CommentedElement > & commentedElements () const
 
CommentedElementcommentForNode (AST::Node *n)
 
QMultiMap< quint32, const QList< Comment > * > allCommentsInNode (AST::Node *n)
 low level method returns all comments in a node (including its subnodes)
 
- Public Member Functions inherited from QQmlJS::Dom::OwningItem
 OwningItem (const OwningItem &o)
 
 OwningItem (int derivedFrom=0)
 
 OwningItem (int derivedFrom, QDateTime lastDataUpdateAt)
 
 OwningItem (const OwningItem &&)=delete
 
OwningItemoperator= (const OwningItem &&)=delete
 
Path canonicalPath (DomItem &self) const override=0
 
bool iterateDirectSubpaths (DomItem &self, DirectVisitor) override
 
std::shared_ptr< OwningItemmakeCopy (DomItem &self) const
 
Path pathFromOwner () const
 
Path pathFromOwner (DomItem &) const override final
 
DomItem containingObject (DomItem &self) const override
 
int derivedFrom () const
 
virtual int revision () const
 
QDateTime createdAt () const
 
virtual QDateTime lastDataUpdateAt () const
 
virtual void refreshedDataAt (QDateTime tNew)
 
virtual bool frozen () const
 
virtual bool freeze ()
 
QDateTime frozenAt () const
 
virtual void addError (DomItem &self, ErrorMessage msg)
 
void addErrorLocal (ErrorMessage msg)
 
void clearErrors (ErrorGroups groups=ErrorGroups({}))
 
bool iterateErrors (DomItem &self, function_ref< bool(DomItem source, ErrorMessage msg)> visitor, Path inPath=Path())
 
QMultiMap< Path, ErrorMessagelocalErrors () const
 
virtual bool iterateSubOwners (DomItem &self, function_ref< bool(DomItem &owner)> visitor)
 
QBasicMutexmutex () const
 
- Public Member Functions inherited from QQmlJS::Dom::DomBase
virtual ~DomBase ()=default
 
DomBasedomBase ()
 
virtual DomType kind () const =0
 
virtual DomKind domKind () const
 
virtual Path pathFromOwner (DomItem &self) const =0
 
virtual Path canonicalPath (DomItem &self) const =0
 
virtual bool iterateDirectSubpaths (DomItem &self, DirectVisitor visitor)=0
 
bool iterateDirectSubpathsConst (DomItem &self, DirectVisitor) const
 
virtual DomItem containingObject (DomItem &self) const
 
virtual void dump (DomItem &, Sink sink, int indent, FilterT filter) const
 
virtual quintptr id () const
 
QString typeName () const
 
virtual QList< QStringfields (DomItem &self) const
 
virtual DomItem field (DomItem &self, QStringView name) const
 
virtual index_type indexes (DomItem &self) const
 
virtual DomItem index (DomItem &self, index_type index) const
 
virtual QSet< QString > const keys (DomItem &self) const
 
virtual DomItem key (DomItem &self, QString name) const
 
virtual QString canonicalFilePath (DomItem &self) const
 
virtual void writeOut (DomItem &self, OutWriter &lw) const
 
virtual QCborValue value () const
 

Static Public Member Functions

static void collectComments (MutableDomItem &item)
 
static void collectComments (std::shared_ptr< Engine > engine, AST::Node *n, std::shared_ptr< AstComments > collectComments, MutableDomItem rootItem, FileLocations::Tree rootItemLocations)
 Collects and associates comments with javascript AST::Node pointers and MutableDomItem in rootItem.
 
- Static Public Member Functions inherited from QQmlJS::Dom::OwningItem
static int nextRevision ()
 

Static Public Attributes

static constexpr DomType kindValue = DomType::AstComments
 

Protected Member Functions

std::shared_ptr< OwningItemdoCopy (DomItem &) const override
 
virtual std::shared_ptr< OwningItemdoCopy (DomItem &self) const =0
 

Additional Inherited Members

- Public Types inherited from QQmlJS::Dom::DomBase
using FilterT = function_ref< bool(DomItem &, const PathEls::PathComponent &, DomItem &)>
 

Detailed Description

Associates comments with AST::Node *.

Stores the comments associated with javascript AST::Node pointers.

Comments are associated to the largest closest node with the following algorithm: \list

  • comments of a node can either be preComments or postComments (before or after the element)
  • define start and end for each element, if two elements start (or end) at the same place the first (larger) wins.
  • associate the comments either with the element just before or just after unless the comments is inside an element (meaning that going back there is a start before finding an end, or going forward an end is met before a start).
  • to choose between the element before or after, we look at the start of the comment, if it is on a new line then associating it as preComment to the element after is preferred, otherwise post comment of the previous element (inline element). This is the only space dependent choice, making comment assignment quite robust
  • if the comment is intrinsically inside all elements then it is moved to before the smallest element. This is the largest reorganization performed, and it is still quite small and difficult to trigger.
  • the comments are stored with the whitespace surrounding them, from the preceding newline (and recording if a newline is required before it) until the newline after. This allows a better reproduction of the comments. \endlist

Definition at line 170 of file qqmldomcomments_p.h.

Constructor & Destructor Documentation

◆ AstComments() [1/2]

QQmlJS::Dom::AstComments::AstComments ( std::shared_ptr< Engine e)
inline

Definition at line 192 of file qqmldomcomments_p.h.

◆ AstComments() [2/2]

QQmlJS::Dom::AstComments::AstComments ( const AstComments o)
inline

Definition at line 193 of file qqmldomcomments_p.h.

Member Function Documentation

◆ allCommentsInNode()

QMultiMap< quint32, const QList< Comment > * > QQmlJS::Dom::AstComments::allCommentsInNode ( AST::Node n)

low level method returns all comments in a node (including its subnodes)

The comments are roughly ordered in the order they appear in the file. Multiple values are in reverse order if the index is even.

Definition at line 725 of file qqmldomcomments.cpp.

◆ canonicalPath()

Path QQmlJS::Dom::AstComments::canonicalPath ( DomItem self) const
inlineoverridevirtual

Implements QQmlJS::Dom::OwningItem.

Definition at line 187 of file qqmldomcomments_p.h.

◆ collectComments() [1/2]

void QQmlJS::Dom::AstComments::collectComments ( MutableDomItem item)
static

Definition at line 467 of file qqmldomcomments.cpp.

References item, and qCWarning.

Referenced by QQmlJS::Dom::createDom().

+ Here is the caller graph for this function:

◆ collectComments() [2/2]

void QQmlJS::Dom::AstComments::collectComments ( std::shared_ptr< Engine engine,
AST::Node n,
std::shared_ptr< AstComments collectComments,
MutableDomItem  rootItem,
FileLocations::Tree  rootItemLocations 
)
static

◆ commentedElements()

const QHash< AST::Node *, CommentedElement > & QQmlJS::Dom::AstComments::commentedElements ( ) const
inline

Definition at line 198 of file qqmldomcomments_p.h.

◆ commentForNode()

CommentedElement * QQmlJS::Dom::AstComments::commentForNode ( AST::Node n)
inline

Definition at line 202 of file qqmldomcomments_p.h.

◆ doCopy()

std::shared_ptr< OwningItem > QQmlJS::Dom::AstComments::doCopy ( DomItem ) const
inlineoverrideprotectedvirtual

Implements QQmlJS::Dom::OwningItem.

Definition at line 173 of file qqmldomcomments_p.h.

◆ iterateDirectSubpaths()

bool QQmlJS::Dom::AstComments::iterateDirectSubpaths ( DomItem self,
DirectVisitor  visitor 
)
overridevirtual

Implements QQmlJS::Dom::DomBase.

Definition at line 435 of file qqmldomcomments.cpp.

References map.

◆ kind()

DomType QQmlJS::Dom::AstComments::kind ( ) const
inlineoverridevirtual

Implements QQmlJS::Dom::DomBase.

Definition at line 180 of file qqmldomcomments_p.h.

◆ makeCopy()

std::shared_ptr< AstComments > QQmlJS::Dom::AstComments::makeCopy ( DomItem self) const
inline

Definition at line 182 of file qqmldomcomments_p.h.

Member Data Documentation

◆ kindValue

constexpr DomType QQmlJS::Dom::AstComments::kindValue = DomType::AstComments
staticconstexpr

Definition at line 179 of file qqmldomcomments_p.h.


The documentation for this class was generated from the following files: