function CommentsRegistry::associateComments
Adds comments to the given node
Parameters
Node\Node $node Node:
array $comments Array of comments to add:
bool $leading True to add comments as leading comments: or false to add them as trailing comments
Return value
void
1 call to CommentsRegistry::associateComments()
- CommentsRegistry::findNodeForCommentsGroup in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ CommentsRegistry.php - Finds the node to attach the given comments group
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ CommentsRegistry.php, line 306
Class
- CommentsRegistry
- Comments registry class. Internal class used to manage comments
Namespace
Peast\SyntaxCode
public function associateComments($node, $comments, $leading) {
$fn = ($leading ? "Leading" : "Trailing") . "Comments";
$currentComments = $node->{"get{$fn}"}();
foreach ($comments as $comment) {
$loc = $comment->location;
$commentNode = new Node\Comment();
$commentNode->location->start = $loc->start;
$commentNode->location->end = $loc->end;
$commentNode->setRawText($comment->value);
$currentComments[] = $commentNode;
}
$node->{"set{$fn}"}($currentComments);
}