@@ -86,13 +86,22 @@ public function parse(TokenIterator $tokens): Ast\PhpDoc\PhpDocNode
8686 }
8787 }
8888
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+
8999 $ tokens ->forwardToTheEnd ();
90- $ tag = new Ast \PhpDoc \PhpDocTagNode ($ name , new Ast \PhpDoc \InvalidTagValueNode ($ e ->getMessage (), $ e ));
91100
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 );
93102 }
94103
95- return new Ast \PhpDoc \PhpDocNode (array_values ($ children ));
104+ return $ this -> enrichWithAttributes ( $ tokens , new Ast \PhpDoc \PhpDocNode (array_values ($ children )), 1 , 0 );
96105 }
97106
98107
@@ -396,6 +405,8 @@ private function parsePropertyTagValue(TokenIterator $tokens): Ast\PhpDoc\Proper
396405 private function parseMethodTagValue (TokenIterator $ tokens ): Ast \PhpDoc \MethodTagValueNode
397406 {
398407 $ isStatic = $ tokens ->tryConsumeTokenValue ('static ' );
408+ $ startLine = $ tokens ->currentTokenLine ();
409+ $ startIndex = $ tokens ->currentTokenIndex ();
399410 $ returnTypeOrMethodName = $ this ->typeParser ->parse ($ tokens );
400411
401412 if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_IDENTIFIER )) {
@@ -404,7 +415,9 @@ private function parseMethodTagValue(TokenIterator $tokens): Ast\PhpDoc\MethodTa
404415 $ tokens ->next ();
405416
406417 } 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 ;
408421 $ methodName = $ returnTypeOrMethodName ->name ;
409422 $ isStatic = false ;
410423
@@ -414,9 +427,12 @@ private function parseMethodTagValue(TokenIterator $tokens): Ast\PhpDoc\MethodTa
414427 }
415428
416429 $ templateTypes = [];
430+
417431 if ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_OPEN_ANGLE_BRACKET )) {
418432 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 );
420436 } while ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_COMMA ));
421437 $ tokens ->consumeTokenType (Lexer::TOKEN_CLOSE_ANGLE_BRACKET );
422438 }
@@ -437,6 +453,9 @@ private function parseMethodTagValue(TokenIterator $tokens): Ast\PhpDoc\MethodTa
437453
438454 private function parseMethodTagValueParameter (TokenIterator $ tokens ): Ast \PhpDoc \MethodTagValueParameterNode
439455 {
456+ $ startLine = $ tokens ->currentTokenLine ();
457+ $ startIndex = $ tokens ->currentTokenIndex ();
458+
440459 switch ($ tokens ->currentTokenType ()) {
441460 case Lexer::TOKEN_IDENTIFIER :
442461 case Lexer::TOKEN_OPEN_PARENTHESES :
@@ -461,7 +480,12 @@ private function parseMethodTagValueParameter(TokenIterator $tokens): Ast\PhpDoc
461480 $ defaultValue = null ;
462481 }
463482
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+ );
465489 }
466490
467491 private function parseTemplateTagValue (TokenIterator $ tokens , bool $ parseDescription ): Ast \PhpDoc \TemplateTagValueNode
@@ -526,6 +550,8 @@ private function parseTypeAliasTagValue(TokenIterator $tokens): Ast\PhpDoc\TypeA
526550 $ tokens ->tryConsumeTokenType (Lexer::TOKEN_EQUAL );
527551
528552 if ($ this ->preserveTypeAliasesWithInvalidTypes ) {
553+ $ startLine = $ tokens ->currentTokenLine ();
554+ $ startIndex = $ tokens ->currentTokenIndex ();
529555 try {
530556 $ type = $ this ->typeParser ->parse ($ tokens );
531557 if (!$ tokens ->isCurrentTokenType (Lexer::TOKEN_CLOSE_PHPDOC )) {
@@ -544,7 +570,10 @@ private function parseTypeAliasTagValue(TokenIterator $tokens): Ast\PhpDoc\TypeA
544570 return new Ast \PhpDoc \TypeAliasTagValueNode ($ alias , $ type );
545571 } catch (ParserException $ e ) {
546572 $ 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+ );
548577 }
549578 }
550579
@@ -560,16 +589,24 @@ private function parseTypeAliasImportTagValue(TokenIterator $tokens): Ast\PhpDoc
560589
561590 $ tokens ->consumeTokenValue (Lexer::TOKEN_IDENTIFIER , 'from ' );
562591
592+ $ identifierStartLine = $ tokens ->currentTokenLine ();
593+ $ identifierStartIndex = $ tokens ->currentTokenIndex ();
563594 $ importedFrom = $ tokens ->currentTokenValue ();
564595 $ tokens ->consumeTokenType (Lexer::TOKEN_IDENTIFIER );
596+ $ importedFromType = $ this ->enrichWithAttributes (
597+ $ tokens ,
598+ new IdentifierTypeNode ($ importedFrom ),
599+ $ identifierStartLine ,
600+ $ identifierStartIndex
601+ );
565602
566603 $ importedAs = null ;
567604 if ($ tokens ->tryConsumeTokenValue ('as ' )) {
568605 $ importedAs = $ tokens ->currentTokenValue ();
569606 $ tokens ->consumeTokenType (Lexer::TOKEN_IDENTIFIER );
570607 }
571608
572- return new Ast \PhpDoc \TypeAliasImportTagValueNode ($ importedAlias , new IdentifierTypeNode ( $ importedFrom ) , $ importedAs );
609+ return new Ast \PhpDoc \TypeAliasImportTagValueNode ($ importedAlias , $ importedFromType , $ importedAs );
573610 }
574611
575612 /**
0 commit comments