1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Shift all comments, not just docblocks

This commit is contained in:
Brown 2018-10-26 11:22:43 -04:00
parent addaea2c1c
commit dbb155f18d
2 changed files with 42 additions and 18 deletions

View File

@ -57,9 +57,9 @@ class OffsetMapCheckerVisitor extends PhpParser\NodeVisitorAbstract implements P
{
$attrs = $node->getAttributes();
if ($c = $node->getDocComment()) {
if ($cs = $node->getComments()) {
/** @var int */
$stmt_start_pos = $c->getFilePos();
$stmt_start_pos = $cs[0]->getFilePos();
} else {
/** @var int */
$stmt_start_pos = $attrs['startFilePos'];
@ -229,14 +229,26 @@ class OffsetMapCheckerVisitor extends PhpParser\NodeVisitorAbstract implements P
if ($start_offset !== 0 || $end_offset !== 0 || $line_offset !== 0) {
if ($start_offset !== 0) {
if ($c) {
$node->setDocComment(
new PhpParser\Comment\Doc(
if ($cs) {
$new_comments = [];
foreach ($cs as $c) {
if ($c instanceof PhpParser\Comment\Doc) {
$new_comments[] = new PhpParser\Comment\Doc(
$c->getText(),
$c->getLine() + $line_offset,
$c->getFilePos() + $start_offset
)
);
} else {
$new_comments[] = new PhpParser\Comment(
$c->getText(),
$c->getLine() + $line_offset,
$c->getFilePos() + $start_offset
);
}
}
$node->setAttribute('comments', $new_comments);
/** @psalm-suppress MixedOperand */
$node->setAttribute('startFilePos', $attrs['startFilePos'] + $start_offset);

View File

@ -27,14 +27,26 @@ class OffsetShifterVisitor extends PhpParser\NodeVisitorAbstract implements PhpP
{
$attrs = $node->getAttributes();
if ($c = $node->getDocComment()) {
$node->setDocComment(
new PhpParser\Comment\Doc(
if ($cs = $node->getComments()) {
$new_comments = [];
foreach ($cs as $c) {
if ($c instanceof PhpParser\Comment\Doc) {
$new_comments[] = new PhpParser\Comment\Doc(
$c->getText(),
$c->getLine() + $this->line_offset,
$c->getFilePos() + $this->file_offset
)
);
} else {
$new_comments[] = new PhpParser\Comment(
$c->getText(),
$c->getLine() + $this->line_offset,
$c->getFilePos() + $this->file_offset
);
}
}
$node->setAttribute('comments', $new_comments);
}
/** @psalm-suppress MixedOperand */