@@ -57,6 +57,12 @@ public function parse(TokenIterator $tokens): Ast\Type\TypeNode
57
57
$ type = $ this ->parseIntersection ($ tokens , $ type );
58
58
}
59
59
}
60
+
61
+ return $ this ->enrichWithAttributes ($ tokens , $ type , $ startLine , $ startIndex );
62
+ }
63
+
64
+ private function enrichWithAttributes (TokenIterator $ tokens , Ast \Type \TypeNode $ type , int $ startLine , int $ startIndex ): Ast \Type \TypeNode
65
+ {
60
66
$ endLine = $ tokens ->currentTokenLine ();
61
67
$ endIndex = $ tokens ->currentTokenIndex ();
62
68
@@ -76,6 +82,9 @@ public function parse(TokenIterator $tokens): Ast\Type\TypeNode
76
82
/** @phpstan-impure */
77
83
private function subParse (TokenIterator $ tokens ): Ast \Type \TypeNode
78
84
{
85
+ $ startLine = $ tokens ->currentTokenLine ();
86
+ $ startIndex = $ tokens ->currentTokenIndex ();
87
+
79
88
if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_NULLABLE )) {
80
89
$ type = $ this ->parseNullable ($ tokens );
81
90
@@ -99,13 +108,16 @@ private function subParse(TokenIterator $tokens): Ast\Type\TypeNode
99
108
}
100
109
}
101
110
102
- return $ type ;
111
+ return $ this -> enrichWithAttributes ( $ tokens , $ type, $ startLine , $ startIndex ) ;
103
112
}
104
113
105
114
106
115
/** @phpstan-impure */
107
116
private function parseAtomic (TokenIterator $ tokens ): Ast \Type \TypeNode
108
117
{
118
+ $ startLine = $ tokens ->currentTokenLine ();
119
+ $ startIndex = $ tokens ->currentTokenIndex ();
120
+
109
121
if ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_OPEN_PARENTHESES )) {
110
122
$ tokens ->tryConsumeTokenType (Lexer::TOKEN_PHPDOC_EOL );
111
123
$ type = $ this ->subParse ($ tokens );
@@ -114,20 +126,20 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
114
126
$ tokens ->consumeTokenType (Lexer::TOKEN_CLOSE_PARENTHESES );
115
127
116
128
if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
117
- return $ this ->tryParseArrayOrOffsetAccess ($ tokens , $ type );
129
+ $ type = $ this ->tryParseArrayOrOffsetAccess ($ tokens , $ type );
118
130
}
119
131
120
- return $ type ;
132
+ return $ this -> enrichWithAttributes ( $ tokens , $ type, $ startLine , $ startIndex ) ;
121
133
}
122
134
123
135
if ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_THIS_VARIABLE )) {
124
136
$ type = new Ast \Type \ThisTypeNode ();
125
137
126
138
if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
127
- return $ this ->tryParseArrayOrOffsetAccess ($ tokens , $ type );
139
+ $ type = $ this ->tryParseArrayOrOffsetAccess ($ tokens , $ type );
128
140
}
129
141
130
- return $ type ;
142
+ return $ this -> enrichWithAttributes ( $ tokens , $ type, $ startLine , $ startIndex ) ;
131
143
}
132
144
133
145
$ currentTokenValue = $ tokens ->currentTokenValue ();
@@ -143,7 +155,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
143
155
$ isHtml = $ this ->isHtml ($ tokens );
144
156
$ tokens ->rollback ();
145
157
if ($ isHtml ) {
146
- return $ type ;
158
+ return $ this -> enrichWithAttributes ( $ tokens , $ type, $ startLine , $ startIndex ) ;
147
159
}
148
160
149
161
$ type = $ this ->parseGeneric ($ tokens , $ type );
@@ -169,7 +181,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
169
181
}
170
182
}
171
183
172
- return $ type ;
184
+ return $ this -> enrichWithAttributes ( $ tokens , $ type, $ startLine , $ startIndex ) ;
173
185
} else {
174
186
$ tokens ->rollback (); // because of ConstFetchNode
175
187
}
@@ -196,7 +208,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
196
208
throw $ exception ;
197
209
}
198
210
199
- return new Ast \Type \ConstTypeNode ($ constExpr );
211
+ return $ this -> enrichWithAttributes ( $ tokens , new Ast \Type \ConstTypeNode ($ constExpr), $ startLine , $ startIndex );
200
212
} catch (LogicException $ e ) {
201
213
throw $ exception ;
202
214
}
0 commit comments