Fix bugs and docs of FilePositionMap
I wasn't using some of those APIs for Node/Token, and didn't notice the incorrect phpdoc/code.
This commit is contained in:
Родитель
59351ce2a6
Коммит
8ed14c2f84
|
@ -24,7 +24,7 @@ class FilePositionMap {
|
|||
/** @var int the 0-based byte offset of the most recent request for a line number. */
|
||||
private $currentOffset;
|
||||
|
||||
/** @var int the line number for $this->currentOffset (updated whenever currentOffset is updated) */
|
||||
/** @var int the 1-based line number for $this->currentOffset (updated whenever currentOffset is updated) */
|
||||
private $lineForCurrentOffset;
|
||||
|
||||
public function __construct(string $file_contents) {
|
||||
|
@ -45,7 +45,7 @@ class FilePositionMap {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Node $node the node to get the start line for.
|
||||
* @param Token $token the token to get the start line for.
|
||||
*/
|
||||
public function getTokenStartLine(Token $token) : int {
|
||||
return $this->getLineNumberForOffset($token->start);
|
||||
|
@ -86,12 +86,12 @@ class FilePositionMap {
|
|||
* Similar to getStartLine but includes the column
|
||||
*/
|
||||
public function getEndLineCharacterPositionForOffset($node) : LineCharacterPosition {
|
||||
return $this->getLineCharacterPositionForOffset($node);
|
||||
return $this->getLineCharacterPositionForOffset($node->getEndPosition());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Node|Token $node
|
||||
* Similar to getStartLine but includes the column
|
||||
* @param int $offset
|
||||
* Similar to getStartLine but includes both the line and the column
|
||||
*/
|
||||
public function getLineCharacterPositionForOffset(int $offset) : LineCharacterPosition {
|
||||
$line = $this->getLineNumberForOffset($offset);
|
||||
|
@ -99,6 +99,10 @@ class FilePositionMap {
|
|||
return new LineCharacterPosition($line, $character);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset - A 0-based byte offset
|
||||
* @return int - gets the 1-based line number for $offset
|
||||
*/
|
||||
public function getLineNumberForOffset(int $offset) : int {
|
||||
if ($offset < 0) {
|
||||
$offset = 0;
|
||||
|
@ -117,7 +121,8 @@ class FilePositionMap {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return int - gets the 1-based column offset
|
||||
* @param int $offset - A 0-based byte offset
|
||||
* @return int - gets the 1-based column number for $offset
|
||||
*/
|
||||
public function getColumnForOffset(int $offset) : int {
|
||||
$length = $this->fileContentsLength;
|
||||
|
|
Загрузка…
Ссылка в новой задаче