Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QQmlJS::Dom::Comment Class Reference

Represents a comment. More...

#include <qqmldomcomments_p.h>

+ Collaboration diagram for QQmlJS::Dom::Comment:

Public Types

enum  CommentType { Pre , Post }
 

Public Member Functions

DomType kind () const
 
 Comment (const QString &c, const QQmlJS::SourceLocation &loc, int newlinesBefore=1, CommentType type=Pre)
 
 Comment (QStringView c, const QQmlJS::SourceLocation &loc, int newlinesBefore=1, CommentType type=Pre)
 
bool iterateDirectSubpaths (const DomItem &self, DirectVisitor visitor) const
 Expose attributes to the Dom.
 
int newlinesBefore () const
 
void setNewlinesBefore (int n)
 
QStringView rawComment () const
 
CommentInfo info () const
 
void write (OutWriter &lw, SourceLocation *commentLocation=nullptr) const
 
CommentType type () const
 
QQmlJS::SourceLocation sourceLocation () const
 

Static Public Attributes

static constexpr DomType kindValue = DomType::Comment
 

Friends

bool operator== (const Comment &c1, const Comment &c2)
 
bool operator!= (const Comment &c1, const Comment &c2)
 

Detailed Description

Represents a comment.

Comments are not needed for execute the program, so they are aimed to the programmer, and have few functions: explaining code, adding extra info/context (who did write, when licensing,...) or disabling code. Being for the programmer and being non functional it is difficult to treat them properly. So preserving them as much as possible is the best course of action.

To acheive this comment is represented by \list

  • newlinesBefore: the number of newlines before the comment, to preserve spacing between comments (the extraction routines limit this to 2 at most, i.e. a single empty line)
  • rawComment: a string with the actual comment including whitespace before and after and the comment characters (whitespace before is limited to spaces/tabs to preserve indentation or spacing just before starting the comment) \endlist The rawComment is a bit annoying if one wants to change the comment, or extract information from it. For this reason info gives access to the various elements of it: the comment characters #, // or / , the space before it, and the actual comment content.

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.

A comment has methods to write it out again (write) and expose it to the Dom (iterateDirectSubpaths).

Definition at line 70 of file qqmldomcomments_p.h.

Member Enumeration Documentation

◆ CommentType

Enumerator
Pre 
Post 

Definition at line 76 of file qqmldomcomments_p.h.

Constructor & Destructor Documentation

◆ Comment() [1/2]

QQmlJS::Dom::Comment::Comment ( const QString & c,
const QQmlJS::SourceLocation & loc,
int newlinesBefore = 1,
CommentType type = Pre )
inline

Definition at line 78 of file qqmldomcomments_p.h.

◆ Comment() [2/2]

QQmlJS::Dom::Comment::Comment ( QStringView c,
const QQmlJS::SourceLocation & loc,
int newlinesBefore = 1,
CommentType type = Pre )
inline

Definition at line 83 of file qqmldomcomments_p.h.

Member Function Documentation

◆ info()

CommentInfo QQmlJS::Dom::Comment::info ( ) const
inline

Definition at line 93 of file qqmldomcomments_p.h.

Referenced by write().

+ Here is the caller graph for this function:

◆ iterateDirectSubpaths()

bool QQmlJS::Dom::Comment::iterateDirectSubpaths ( const DomItem & self,
DirectVisitor visitor ) const

Expose attributes to the Dom.

Definition at line 193 of file qqmldomcomments.cpp.

References newlinesBefore(), and rawComment().

+ Here is the call graph for this function:

◆ kind()

DomType QQmlJS::Dom::Comment::kind ( ) const
inline

Definition at line 74 of file qqmldomcomments_p.h.

◆ newlinesBefore()

int QQmlJS::Dom::Comment::newlinesBefore ( ) const
inline

Definition at line 90 of file qqmldomcomments_p.h.

Referenced by iterateDirectSubpaths(), and write().

+ Here is the caller graph for this function:

◆ rawComment()

QStringView QQmlJS::Dom::Comment::rawComment ( ) const
inline

Definition at line 92 of file qqmldomcomments_p.h.

Referenced by iterateDirectSubpaths().

+ Here is the caller graph for this function:

◆ setNewlinesBefore()

void QQmlJS::Dom::Comment::setNewlinesBefore ( int n)
inline

Definition at line 91 of file qqmldomcomments_p.h.

◆ sourceLocation()

QQmlJS::SourceLocation QQmlJS::Dom::Comment::sourceLocation ( ) const
inline

Definition at line 104 of file qqmldomcomments_p.h.

◆ type()

CommentType QQmlJS::Dom::Comment::type ( ) const
inline

Definition at line 96 of file qqmldomcomments_p.h.

Referenced by QQmlJS::Dom::CommentedElement::addComment(), and QQmlJS::Dom::RegionComments::addComment().

+ Here is the caller graph for this function:

◆ write()

void QQmlJS::Dom::Comment::write ( OutWriter & lw,
SourceLocation * commentLocation = nullptr ) const

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const Comment & c1,
const Comment & c2 )
friend

Definition at line 102 of file qqmldomcomments_p.h.

◆ operator==

bool operator== ( const Comment & c1,
const Comment & c2 )
friend

Definition at line 98 of file qqmldomcomments_p.h.

Member Data Documentation

◆ kindValue

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

Definition at line 73 of file qqmldomcomments_p.h.


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