@@ -24,7 +24,7 @@ class FilePositionMap {
24
24
/** @var int the 0-based byte offset of the most recent request for a line number. */
25
25
private $ currentOffset ;
26
26
27
- /** @var int the line number for $this->currentOffset (updated whenever currentOffset is updated) */
27
+ /** @var int the 1-based line number for $this->currentOffset (updated whenever currentOffset is updated) */
28
28
private $ lineForCurrentOffset ;
29
29
30
30
public function __construct (string $ file_contents ) {
@@ -45,7 +45,7 @@ public function getNodeStartLine(Node $node) : int {
45
45
}
46
46
47
47
/**
48
- * @param Node $node the node to get the start line for.
48
+ * @param Token $token the token to get the start line for.
49
49
*/
50
50
public function getTokenStartLine (Token $ token ) : int {
51
51
return $ this ->getLineNumberForOffset ($ token ->start );
@@ -86,19 +86,23 @@ public function getEndLine($node) : int {
86
86
* Similar to getStartLine but includes the column
87
87
*/
88
88
public function getEndLineCharacterPositionForOffset ($ node ) : LineCharacterPosition {
89
- return $ this ->getLineCharacterPositionForOffset ($ node );
89
+ return $ this ->getLineCharacterPositionForOffset ($ node-> getEndPosition () );
90
90
}
91
91
92
92
/**
93
- * @param Node|Token $node
94
- * Similar to getStartLine but includes the column
93
+ * @param int $offset
94
+ * Similar to getStartLine but includes both the line and the column
95
95
*/
96
96
public function getLineCharacterPositionForOffset (int $ offset ) : LineCharacterPosition {
97
97
$ line = $ this ->getLineNumberForOffset ($ offset );
98
98
$ character = $ this ->getColumnForOffset ($ offset );
99
99
return new LineCharacterPosition ($ line , $ character );
100
100
}
101
101
102
+ /**
103
+ * @param int $offset - A 0-based byte offset
104
+ * @return int - gets the 1-based line number for $offset
105
+ */
102
106
public function getLineNumberForOffset (int $ offset ) : int {
103
107
if ($ offset < 0 ) {
104
108
$ offset = 0 ;
@@ -117,7 +121,8 @@ public function getLineNumberForOffset(int $offset) : int {
117
121
}
118
122
119
123
/**
120
- * @return int - gets the 1-based column offset
124
+ * @param int $offset - A 0-based byte offset
125
+ * @return int - gets the 1-based column number for $offset
121
126
*/
122
127
public function getColumnForOffset (int $ offset ) : int {
123
128
$ length = $ this ->fileContentsLength ;
0 commit comments