@@ -61,7 +61,12 @@ public function parse(TokenIterator $tokens): Ast\Type\TypeNode
61
61
return $ this ->enrichWithAttributes ($ tokens , $ type , $ startLine , $ startIndex );
62
62
}
63
63
64
- private function enrichWithAttributes (TokenIterator $ tokens , Ast \Type \TypeNode $ type , int $ startLine , int $ startIndex ): Ast \Type \TypeNode
64
+ /**
65
+ * @template T of Ast\Node
66
+ * @param T $type
67
+ * @return T
68
+ */
69
+ private function enrichWithAttributes (TokenIterator $ tokens , Ast \Node $ type , int $ startLine , int $ startIndex ): Ast \Node
65
70
{
66
71
$ endLine = $ tokens ->currentTokenLine ();
67
72
$ endIndex = $ tokens ->currentTokenIndex ();
@@ -139,7 +144,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
139
144
}
140
145
141
146
if ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_THIS_VARIABLE )) {
142
- $ type = new Ast \Type \ThisTypeNode ();
147
+ $ type = $ this -> enrichWithAttributes ( $ tokens , new Ast \Type \ThisTypeNode (), $ startLine , $ startIndex );
143
148
144
149
if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
145
150
$ type = $ this ->tryParseArrayOrOffsetAccess ($ tokens , $ type );
@@ -151,7 +156,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
151
156
$ currentTokenValue = $ tokens ->currentTokenValue ();
152
157
$ tokens ->pushSavePoint (); // because of ConstFetchNode
153
158
if ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_IDENTIFIER )) {
154
- $ type = new Ast \Type \IdentifierTypeNode ($ currentTokenValue );
159
+ $ type = $ this -> enrichWithAttributes ( $ tokens , new Ast \Type \IdentifierTypeNode ($ currentTokenValue), $ startLine , $ startIndex );
155
160
156
161
if (!$ tokens ->isCurrentTokenType (Lexer::TOKEN_DOUBLE_COLON )) {
157
162
$ tokens ->dropSavePoint (); // because of ConstFetchNode
@@ -454,7 +459,10 @@ private function parseCallable(TokenIterator $tokens, Ast\Type\IdentifierTypeNod
454
459
455
460
$ tokens ->consumeTokenType (Lexer::TOKEN_CLOSE_PARENTHESES );
456
461
$ tokens ->consumeTokenType (Lexer::TOKEN_COLON );
457
- $ returnType = $ this ->parseCallableReturnType ($ tokens );
462
+
463
+ $ startLine = $ tokens ->currentTokenLine ();
464
+ $ startIndex = $ tokens ->currentTokenIndex ();
465
+ $ returnType = $ this ->enrichWithAttributes ($ tokens , $ this ->parseCallableReturnType ($ tokens ), $ startLine , $ startIndex );
458
466
459
467
return new Ast \Type \CallableTypeNode ($ identifier , $ parameters , $ returnType );
460
468
}
@@ -463,6 +471,8 @@ private function parseCallable(TokenIterator $tokens, Ast\Type\IdentifierTypeNod
463
471
/** @phpstan-impure */
464
472
private function parseCallableParameter (TokenIterator $ tokens ): Ast \Type \CallableTypeParameterNode
465
473
{
474
+ $ startLine = $ tokens ->currentTokenLine ();
475
+ $ startIndex = $ tokens ->currentTokenIndex ();
466
476
$ type = $ this ->parse ($ tokens );
467
477
$ isReference = $ tokens ->tryConsumeTokenType (Lexer::TOKEN_REFERENCE );
468
478
$ isVariadic = $ tokens ->tryConsumeTokenType (Lexer::TOKEN_VARIADIC );
@@ -476,7 +486,12 @@ private function parseCallableParameter(TokenIterator $tokens): Ast\Type\Callabl
476
486
}
477
487
478
488
$ isOptional = $ tokens ->tryConsumeTokenType (Lexer::TOKEN_EQUAL );
479
- return new Ast \Type \CallableTypeParameterNode ($ type , $ isReference , $ isVariadic , $ parameterName , $ isOptional );
489
+ return $ this ->enrichWithAttributes (
490
+ $ tokens ,
491
+ new Ast \Type \CallableTypeParameterNode ($ type , $ isReference , $ isVariadic , $ parameterName , $ isOptional ),
492
+ $ startLine ,
493
+ $ startIndex
494
+ );
480
495
}
481
496
482
497
0 commit comments