@@ -86,13 +86,22 @@ public function parse(TokenIterator $tokens): Ast\PhpDoc\PhpDocNode
86
86
}
87
87
}
88
88
89
+ $ tag = new Ast \PhpDoc \PhpDocTagNode (
90
+ $ name ,
91
+ $ this ->enrichWithAttributes (
92
+ $ tokens ,
93
+ new Ast \PhpDoc \InvalidTagValueNode ($ e ->getMessage (), $ e ),
94
+ $ startLine ,
95
+ $ startIndex
96
+ )
97
+ );
98
+
89
99
$ tokens ->forwardToTheEnd ();
90
- $ tag = new Ast \PhpDoc \PhpDocTagNode ($ name , new Ast \PhpDoc \InvalidTagValueNode ($ e ->getMessage (), $ e ));
91
100
92
- return new Ast \PhpDoc \PhpDocNode ([$ this ->enrichWithAttributes ($ tokens , $ tag , $ startLine , $ startIndex )]);
101
+ return $ this -> enrichWithAttributes ( $ tokens , new Ast \PhpDoc \PhpDocNode ([$ this ->enrichWithAttributes ($ tokens , $ tag , $ startLine , $ startIndex )]), 1 , 0 );
93
102
}
94
103
95
- return new Ast \PhpDoc \PhpDocNode (array_values ($ children ));
104
+ return $ this -> enrichWithAttributes ( $ tokens , new Ast \PhpDoc \PhpDocNode (array_values ($ children )), 1 , 0 );
96
105
}
97
106
98
107
@@ -396,6 +405,8 @@ private function parsePropertyTagValue(TokenIterator $tokens): Ast\PhpDoc\Proper
396
405
private function parseMethodTagValue (TokenIterator $ tokens ): Ast \PhpDoc \MethodTagValueNode
397
406
{
398
407
$ isStatic = $ tokens ->tryConsumeTokenValue ('static ' );
408
+ $ startLine = $ tokens ->currentTokenLine ();
409
+ $ startIndex = $ tokens ->currentTokenIndex ();
399
410
$ returnTypeOrMethodName = $ this ->typeParser ->parse ($ tokens );
400
411
401
412
if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_IDENTIFIER )) {
@@ -404,7 +415,9 @@ private function parseMethodTagValue(TokenIterator $tokens): Ast\PhpDoc\MethodTa
404
415
$ tokens ->next ();
405
416
406
417
} elseif ($ returnTypeOrMethodName instanceof Ast \Type \IdentifierTypeNode) {
407
- $ returnType = $ isStatic ? new Ast \Type \IdentifierTypeNode ('static ' ) : null ;
418
+ $ returnType = $ isStatic
419
+ ? $ this ->typeParser ->enrichWithAttributes ($ tokens , new Ast \Type \IdentifierTypeNode ('static ' ), $ startLine , $ startIndex )
420
+ : null ;
408
421
$ methodName = $ returnTypeOrMethodName ->name ;
409
422
$ isStatic = false ;
410
423
@@ -414,9 +427,12 @@ private function parseMethodTagValue(TokenIterator $tokens): Ast\PhpDoc\MethodTa
414
427
}
415
428
416
429
$ templateTypes = [];
430
+
417
431
if ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_OPEN_ANGLE_BRACKET )) {
418
432
do {
419
- $ templateTypes [] = $ this ->parseTemplateTagValue ($ tokens , false );
433
+ $ startLine = $ tokens ->currentTokenLine ();
434
+ $ startIndex = $ tokens ->currentTokenIndex ();
435
+ $ templateTypes [] = $ this ->enrichWithAttributes ($ tokens , $ this ->parseTemplateTagValue ($ tokens , false ), $ startLine , $ startIndex );
420
436
} while ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_COMMA ));
421
437
$ tokens ->consumeTokenType (Lexer::TOKEN_CLOSE_ANGLE_BRACKET );
422
438
}
@@ -437,6 +453,9 @@ private function parseMethodTagValue(TokenIterator $tokens): Ast\PhpDoc\MethodTa
437
453
438
454
private function parseMethodTagValueParameter (TokenIterator $ tokens ): Ast \PhpDoc \MethodTagValueParameterNode
439
455
{
456
+ $ startLine = $ tokens ->currentTokenLine ();
457
+ $ startIndex = $ tokens ->currentTokenIndex ();
458
+
440
459
switch ($ tokens ->currentTokenType ()) {
441
460
case Lexer::TOKEN_IDENTIFIER :
442
461
case Lexer::TOKEN_OPEN_PARENTHESES :
@@ -461,7 +480,12 @@ private function parseMethodTagValueParameter(TokenIterator $tokens): Ast\PhpDoc
461
480
$ defaultValue = null ;
462
481
}
463
482
464
- return new Ast \PhpDoc \MethodTagValueParameterNode ($ parameterType , $ isReference , $ isVariadic , $ parameterName , $ defaultValue );
483
+ return $ this ->enrichWithAttributes (
484
+ $ tokens ,
485
+ new Ast \PhpDoc \MethodTagValueParameterNode ($ parameterType , $ isReference , $ isVariadic , $ parameterName , $ defaultValue ),
486
+ $ startLine ,
487
+ $ startIndex
488
+ );
465
489
}
466
490
467
491
private function parseTemplateTagValue (TokenIterator $ tokens , bool $ parseDescription ): Ast \PhpDoc \TemplateTagValueNode
@@ -526,6 +550,8 @@ private function parseTypeAliasTagValue(TokenIterator $tokens): Ast\PhpDoc\TypeA
526
550
$ tokens ->tryConsumeTokenType (Lexer::TOKEN_EQUAL );
527
551
528
552
if ($ this ->preserveTypeAliasesWithInvalidTypes ) {
553
+ $ startLine = $ tokens ->currentTokenLine ();
554
+ $ startIndex = $ tokens ->currentTokenIndex ();
529
555
try {
530
556
$ type = $ this ->typeParser ->parse ($ tokens );
531
557
if (!$ tokens ->isCurrentTokenType (Lexer::TOKEN_CLOSE_PHPDOC )) {
@@ -544,7 +570,10 @@ private function parseTypeAliasTagValue(TokenIterator $tokens): Ast\PhpDoc\TypeA
544
570
return new Ast \PhpDoc \TypeAliasTagValueNode ($ alias , $ type );
545
571
} catch (ParserException $ e ) {
546
572
$ this ->parseOptionalDescription ($ tokens );
547
- return new Ast \PhpDoc \TypeAliasTagValueNode ($ alias , new Ast \Type \InvalidTypeNode ($ e ));
573
+ return new Ast \PhpDoc \TypeAliasTagValueNode (
574
+ $ alias ,
575
+ $ this ->enrichWithAttributes ($ tokens , new Ast \Type \InvalidTypeNode ($ e ), $ startLine , $ startIndex )
576
+ );
548
577
}
549
578
}
550
579
@@ -560,16 +589,24 @@ private function parseTypeAliasImportTagValue(TokenIterator $tokens): Ast\PhpDoc
560
589
561
590
$ tokens ->consumeTokenValue (Lexer::TOKEN_IDENTIFIER , 'from ' );
562
591
592
+ $ identifierStartLine = $ tokens ->currentTokenLine ();
593
+ $ identifierStartIndex = $ tokens ->currentTokenIndex ();
563
594
$ importedFrom = $ tokens ->currentTokenValue ();
564
595
$ tokens ->consumeTokenType (Lexer::TOKEN_IDENTIFIER );
596
+ $ importedFromType = $ this ->enrichWithAttributes (
597
+ $ tokens ,
598
+ new IdentifierTypeNode ($ importedFrom ),
599
+ $ identifierStartLine ,
600
+ $ identifierStartIndex
601
+ );
565
602
566
603
$ importedAs = null ;
567
604
if ($ tokens ->tryConsumeTokenValue ('as ' )) {
568
605
$ importedAs = $ tokens ->currentTokenValue ();
569
606
$ tokens ->consumeTokenType (Lexer::TOKEN_IDENTIFIER );
570
607
}
571
608
572
- return new Ast \PhpDoc \TypeAliasImportTagValueNode ($ importedAlias , new IdentifierTypeNode ( $ importedFrom ) , $ importedAs );
609
+ return new Ast \PhpDoc \TypeAliasImportTagValueNode ($ importedAlias , $ importedFromType , $ importedAs );
573
610
}
574
611
575
612
/**
0 commit comments