Cpp.Comment Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the comment nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.Comment represents the node comment in the syntax tree of your code.
// This is a single-line comment
/* This is a
multi-line comment */
int main() {
return 0; // inline comment
}The code shows comment nodes as // ... and
/* ... */ forms. Each comment in the example is modelled by
Cpp.Comment class.
Predicates
| Type | Raisable | Printable |
|---|---|---|
Comment
| Yes | Yes |
This class defines these predicates that act on the objects of this class. In addition, objects of this class can access the predicates defined by the base class AstNodeProperties. An object of this class is an object of AstNodeProperties class.
| Predicates | Description | Example |
|---|---|---|
is(required Comment &comment)
| Match a comment node and bind it to comment. Use this to start checks on comments. |
This PQL defect checks for any comment nodes. defect anyComment =
when
Cpp.Comment.is(&c)
raise "found comment"
on cIn this C++ code the defect finds every comment node such as single-line and multi-line comments.
// found
/* found */
int f() { return 0; } |
cast(Cpp.Node.Node node, required Comment &cast)
| Check whether an existing Node is a comment and bind it as Comment. | This PQL defect checks whether a generic node is a
defect nodeIsComment =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.Comment.cast(node, &c)
raise "function node converted to comment"
on nIn this C++ code the defect reports all generic nodes that successfully casts into comment nodes.
// found //Comment
/* found */ // Comment
int f() { return 0; } |
isa(Cpp.Node.Node node)
| Return true if the given generic Node is a comment node. | This PQL defect checks for nodes that are not comments. defect notComment =
when
Cpp.Node.is(&node, &,&,&)
and not Cpp.Comment.isa(nde)
raise "node is not a comment"
on nIn this C++ code the defect reports all generic nodes that are not comment nodes.
// found //Comment
/* found */ // Comment
int f() { return 0; } |
contains(Comment self, Lang.String text)
| True when the comment text includes the given substring text. |
This PQL defect checks comments that contain the word "TODO". defect todo =
when
Cpp.Comment.is(&c)
and c.contains("TODO")
raise "No TODO!"
on cIn this C++ code the defect finds comments that include "TODO".
// TODO: implement this
int f() { return 0; } |
isSingleLine(Comment self)
| True when the comment occupies a single source line such as // .... |
This PQL defect checks for single-line comments. defect single =
when
Cpp.Comment.is(&c)
and c.isSingleLine()
raise "single line comment"
on cIn this C++ code the defect finds
// a single-line comment
int f() { return 0; } |
isMultiLine(Comment self)
| True when the comment spans multiple lines such as /* ... */ with line breaks. |
This PQL defect checks for multi-line comments. defect multi =
when
Cpp.Comment.is(&c)
and c.isMultiLine()
raise "multi line comment"
on cIn this C++ code the defect finds block comments that span lines.
/* multi
line
comment */
int f() { return 0; } |
hasNbLines(Comment self, required Lang.Int &nbLines)
| Bind nbLines to the number of source lines the comment occupies. |
This PQL defect checks comments spanning more than one line. defect manyLines =
when
Cpp.Comment.is(&c)
and c.hasNbLines(&n)
and n > 1
raise "comment has {n} lines"
on cIn this C++ code the defect reports the count of lines for multi-line comments.
/* line1
line2 */
int f() { return 0; } |
hasStyle(Comment self, required Lang.String &style)
| Bind style to the comment prefix such as //, /*, /**, or ///. |
This PQL defect extracts the comment style. defect style =
when
Cpp.Comment.is(&c)
and c.hasStyle(&s)
raise "comment has style {s}"
on cIn this C++ code the defect will report
/** doc */ // style will be "/**" for the first and "//" for inline
int f() { return 0; } |
hasDocStyle(Comment self, required Lang.String &style)
| Bind style when the comment uses documentation style /** or ///. |
This PQL defect checks for documentation-style comments. defect docStyle =
when
Cpp.Comment.is(&c)
and c.hasDocStyle(&s)
raise "doc style {s}"
on cIn this C++ code the defect finds comments written for documentation.
/** Documentation */
/// Another doc
int f() { return 0; } |
style(Comment self, required Lang.String &style)
| Bind style to one of the canonical styles //, /*, /**, or ///. |
This PQL defect reads the canonical comment style. defect getStyle =
when
Cpp.Comment.is(&c)
and c.style(&s)
raise "style is {s}"
on cIn this C++ code the defect reports the exact style used for each comment.
// simple
/* c style */
/** cdoc */
///
int f() { return 0; } |
isCStyle(Comment self)
| True when the comment is a C-style block comment /* ... */ including /** ... */. |
This PQL defect checks for C-style block comments. defect cStyle =
when
Cpp.Comment.is(&c)
and c.isCStyle()
raise "C style comment"
on cIn this C++ code the defect finds block comments written with
/* block comment */
int f() { return 0; } |
isCppStyle(Comment self)
| True when the comment is a C++-style single-line comment starting with // including ///. |
This PQL defect checks for defect cppStyle =
when
Cpp.Comment.is(&c)
and c.isCppStyle()
raise "C++ style comment"
on cIn this C++ code the defect finds
// comment
int f() { return 0; } |
isCDocStyle(Comment self)
| True when the comment is a C documentation-style block starting with /**. |
This PQL defect checks for defect cdoc =
when
Cpp.Comment.is(&c)
and c.isCDocStyle()
raise "C doc style"
on cIn this C++ code the defect finds block doc comments used by C-style doc tools.
/** doc comment */
int f() { return 0; } |
isCppDocStyle(Comment self)
| True when the comment is a C++ documentation-style single-line doc starting with ///. |
This PQL defect checks for defect cppdoc =
when
Cpp.Comment.is(&c)
and c.isCppDocStyle()
raise "C++ doc style"
on cIn this C++ code the defect finds
/// doc
int f() { return 0; } |
isDocStyle(Comment self)
| True when the comment is any documentation style either /** or ///. |
This PQL defect checks for any doc-style comment. defect doc =
when
Cpp.Comment.is(&c)
and c.isDocStyle()
raise "doc style comment"
on cIn this C++ code the defect matches both
/** doc */
/// doc
int f() { return 0; } |
isInline(Comment self)
| True when the comment is on the same line as code such as trailing // after statements. |
This PQL defect checks for inline trailing comments. defect inlineComment =
when
Cpp.Comment.is(&c)
and c.isInline()
raise "inline comment"
on cIn this C++ code the defect matches the trailing comment after the return.
int f() { return 0; } // inline comment |
getNextNode(Comment self, required Cpp.Node.Node &node)
| Bind node to the next node in the CST after the comment if one exists. |
This PQL defect checks comments that have a next syntactic node. defect hasNext =
when
Cpp.Comment.is(&c)
and c.getNextNode(&n)
and n.nodeText(&t)
raise "comment has next node {t}"
on cIn this C++ code the defect finds a comment preceding a function and returns that function node text.
// before foo
int foo() { return 1; } |
getPreviousNode(Comment self, required Cpp.Node.Node &node)
| Bind node to the previous node in the CST before the comment if one exists. |
This PQL defect checks comments that follow some code node. defect hasPrev =
when
Cpp.Comment.is(&c)
and c.getPreviousNode(&n)
and n.nodeText(&t)
raise "comment has previous node {t}"
on cIn this C++ code the defect matches a trailing comment after a function or statement and reports the previous node.
int bar() { return 2; } // trailing comment |
getNextNonCommentNode(Comment self, Cpp.Node.Node &node)
| Bind node to the next non-comment node after this comment skipping over intermediate comments. |
This PQL defect checks for the next non-comment sibling or following node. defect nextNonComment =
when
Cpp.Comment.is(&c)
and c.getNextNonCommentNode(&n)
and n.nodeText(&t)
raise "next non-comment node {t}"
on cIn this C++ code the defect finds the next real code node after possibly several comments.
/* comment */
/* another comment */
int baz() { return 3; } |
getPreviousNonCommentNode(Comment self, Cpp.Node.Node &node)
| Bind node to the previous non-comment node before this comment skipping comments. |
This PQL defect checks for the previous code node preceding a comment. defect prevNonComment =
when
Cpp.Comment.is(&c)
and c.getPreviousNonCommentNode(&n)
and n.nodeText(&t)
raise "previous non-comment node {t}"
on cIn this C++ code the defect finds the code element that comes before the comment when comments are grouped.
int qux() { return 4; }
// comment after qux |
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)