|
10 | 10 |
|
11 | 11 | class DiagnosticsProvider { |
12 | 12 |
|
| 13 | + /** |
| 14 | + * @var string[] maps the token kind to the corresponding name |
| 15 | + */ |
13 | 16 | private static $tokenKindToText; |
14 | 17 |
|
15 | 18 | /** |
16 | 19 | * @param int $kind (must be a valid token kind) |
17 | 20 | * @return string |
18 | 21 | */ |
19 | 22 | public static function getTextForTokenKind($kind) { |
20 | | - if (!isset(self::$tokenKindToText)) { |
21 | | - self::initTokenKindToText(); |
22 | | - } |
23 | 23 | return self::$tokenKindToText[$kind]; |
24 | 24 | } |
25 | 25 |
|
26 | 26 | /** |
27 | | - * @return string[] |
| 27 | + * This is called when this class is loaded, at the bottom of this file. |
| 28 | + * @return void |
28 | 29 | */ |
29 | | - private static function initTokenKindToText() { |
| 30 | + public static function initTokenKindToText() { |
30 | 31 | self::$tokenKindToText = \array_flip(\array_merge( |
31 | 32 | TokenStringMaps::OPERATORS_AND_PUNCTUATORS, |
32 | 33 | TokenStringMaps::KEYWORDS, |
@@ -58,9 +59,6 @@ public static function checkDiagnostics($node) { |
58 | 59 | * @return Diagnostic|null |
59 | 60 | */ |
60 | 61 | private static function checkDiagnosticForUnexpectedToken($token) { |
61 | | - if (!isset(self::$tokenKindToText)) { |
62 | | - self::initTokenKindToText(); |
63 | | - } |
64 | 62 | if ($token instanceof SkippedToken) { |
65 | 63 | // TODO - consider also attaching parse context information to skipped tokens |
66 | 64 | // this would allow us to provide more helpful error messages that inform users what to do |
@@ -107,3 +105,5 @@ public static function getDiagnostics(Node $n) : array { |
107 | 105 | return $diagnostics; |
108 | 106 | } |
109 | 107 | } |
| 108 | + |
| 109 | +DiagnosticsProvider::initTokenKindToText(); |
0 commit comments