Skip to content

Commit 9789d4f

Browse files
committed
Fix missing xp::$sn lookup when reflecting generics
See xp-framework/core#332 (comment)
1 parent 7f6e019 commit 9789d4f

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ XP Reflection ChangeLog
33

44
## ?.?.? / ????-??-??
55

6+
## 2.13.6 / 2023-06-25
7+
8+
* Fixed missing `xp::$sn` lookup when reflecting generics - @thekid
9+
610
## 2.13.5 / 2023-06-25
711

812
* Fixed parameter default values, by-reference and variadic markers,

src/main/php/lang/meta/MetaInformation.class.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private function tags($reflect) {
5454
* @return [:string]
5555
*/
5656
public function scopeImports($reflect) {
57-
$meta= &\xp::$meta[strtr($reflect->name, '\\', '.')];
57+
$meta= &\xp::$meta[\xp::$cn[$reflect->name] ?? strtr($reflect->name, '\\', '.')];
5858
return $meta['use'] ?? $meta['use']= $this->annotations->imports($reflect);
5959
}
6060

@@ -65,7 +65,7 @@ public function scopeImports($reflect) {
6565
* @return [:var[]]
6666
*/
6767
public function typeAnnotations($reflect) {
68-
if ($meta= \xp::$meta[strtr($reflect->name, '\\', '.')]['class'] ?? null) {
68+
if ($meta= \xp::$meta[\xp::$cn[$reflect->name] ?? strtr($reflect->name, '\\', '.')]['class'] ?? null) {
6969
return $this->annotations($meta);
7070
} else {
7171
return $this->annotations->ofType($reflect);
@@ -79,7 +79,7 @@ public function typeAnnotations($reflect) {
7979
* @return ?string
8080
*/
8181
public function typeComment($reflect) {
82-
if ($meta= \xp::$meta[strtr($reflect->name, '\\', '.')]['class'] ?? null) {
82+
if ($meta= \xp::$meta[\xp::$cn[$reflect->name] ?? strtr($reflect->name, '\\', '.')]['class'] ?? null) {
8383
return $meta[DETAIL_COMMENT];
8484
} else if (false === ($c= $reflect->getDocComment())) {
8585
return null;
@@ -95,7 +95,8 @@ public function typeComment($reflect) {
9595
* @return [:var[]]
9696
*/
9797
public function constantAnnotations($reflect) {
98-
$c= strtr($reflect->getDeclaringClass()->name, '\\', '.');
98+
$name= $reflect->getDeclaringClass()->name;
99+
$c= \xp::$cn[$name] ?? strtr($name, '\\', '.');
99100
if ($meta= \xp::$meta[$c][2][$reflect->name] ?? null) {
100101
return $this->annotations($meta);
101102
} else {
@@ -111,7 +112,8 @@ public function constantAnnotations($reflect) {
111112
* @return ?string
112113
*/
113114
public function constantType($reflect) {
114-
$c= strtr($reflect->getDeclaringClass()->name, '\\', '.');
115+
$name= $reflect->getDeclaringClass()->name;
116+
$c= \xp::$cn[$name] ?? strtr($name, '\\', '.');
115117
if ($meta= \xp::$meta[$c][2][$reflect->name] ?? null) {
116118
return $meta[DETAIL_RETURNS];
117119
} else {
@@ -127,7 +129,8 @@ public function constantType($reflect) {
127129
* @return ?string
128130
*/
129131
public function constantComment($reflect) {
130-
$c= strtr($reflect->getDeclaringClass()->name, '\\', '.');
132+
$name= $reflect->getDeclaringClass()->name;
133+
$c= \xp::$cn[$name] ?? strtr($name, '\\', '.');
131134
if ($meta= \xp::$meta[$c][2][$reflect->name] ?? null) {
132135
return $meta[DETAIL_COMMENT];
133136
} else if (false === ($c= $reflect->getDocComment())) {
@@ -144,7 +147,8 @@ public function constantComment($reflect) {
144147
* @return [:var[]]
145148
*/
146149
public function propertyAnnotations($reflect) {
147-
$c= strtr($reflect->getDeclaringClass()->name, '\\', '.');
150+
$name= $reflect->getDeclaringClass()->name;
151+
$c= \xp::$cn[$name] ?? strtr($name, '\\', '.');
148152
if ($meta= \xp::$meta[$c][0][$reflect->name] ?? null) {
149153
return $this->annotations($meta);
150154
} else {
@@ -159,7 +163,8 @@ public function propertyAnnotations($reflect) {
159163
* @return ?string
160164
*/
161165
public function propertyType($reflect) {
162-
$c= strtr($reflect->getDeclaringClass()->name, '\\', '.');
166+
$name= $reflect->getDeclaringClass()->name;
167+
$c= \xp::$cn[$name] ?? strtr($name, '\\', '.');
163168
if ($meta= \xp::$meta[$c][0][$reflect->name] ?? null) {
164169
return $meta[DETAIL_RETURNS];
165170
} else {
@@ -175,7 +180,8 @@ public function propertyType($reflect) {
175180
* @return ?string
176181
*/
177182
public function propertyComment($reflect) {
178-
$c= strtr($reflect->getDeclaringClass()->name, '\\', '.');
183+
$name= $reflect->getDeclaringClass()->name;
184+
$c= \xp::$cn[$name] ?? strtr($name, '\\', '.');
179185
if ($meta= \xp::$meta[$c][0][$reflect->name] ?? null) {
180186
return $meta[DETAIL_COMMENT];
181187
} else if (false === ($c= $reflect->getDocComment())) {
@@ -207,7 +213,8 @@ public function methodAnnotations($reflect) {
207213
* @return ?string
208214
*/
209215
public function methodReturns($reflect) {
210-
$c= strtr($reflect->getDeclaringClass()->name, '\\', '.');
216+
$name= $reflect->getDeclaringClass()->name;
217+
$c= \xp::$cn[$name] ?? strtr($name, '\\', '.');
211218
if ($meta= \xp::$meta[$c][1][$reflect->name] ?? null) {
212219
return $meta[DETAIL_RETURNS];
213220
} else {
@@ -222,7 +229,8 @@ public function methodReturns($reflect) {
222229
* @return ?string
223230
*/
224231
public function methodComment($reflect) {
225-
$c= strtr($reflect->getDeclaringClass()->name, '\\', '.');
232+
$name= $reflect->getDeclaringClass()->name;
233+
$c= \xp::$cn[$name] ?? strtr($name, '\\', '.');
226234
if ($meta= \xp::$meta[$c][1][$reflect->name] ?? null) {
227235
return $meta[DETAIL_COMMENT];
228236
} else if (false === ($c= $reflect->getDocComment())) {
@@ -239,7 +247,8 @@ public function methodComment($reflect) {
239247
* @return string[]
240248
*/
241249
public function methodParameterTypes($method) {
242-
$c= strtr($method->getDeclaringClass()->name, '\\', '.');
250+
$name= $method->getDeclaringClass()->name;
251+
$c= \xp::$cn[$name] ?? strtr($name, '\\', '.');
243252
if ($meta= \xp::$meta[$c][1][$method->name][DETAIL_ARGUMENTS] ?? null) return $meta;
244253

245254
$r= [];
@@ -257,7 +266,8 @@ public function methodParameterTypes($method) {
257266
* @return [:var[]]
258267
*/
259268
public function parameterAnnotations($method, $reflect) {
260-
$c= strtr($method->getDeclaringClass()->name, '\\', '.');
269+
$name= $method->getDeclaringClass()->name;
270+
$c= \xp::$cn[$name] ?? strtr($name, '\\', '.');
261271
if ($target= \xp::$meta[$c][1][$method->name][DETAIL_TARGET_ANNO] ?? null) {
262272
if ($param= $target['$'.$reflect->name] ?? null) {
263273
$r= [];
@@ -282,7 +292,7 @@ public function virtualProperties($reflect) {
282292
do {
283293

284294
// If meta information is already loaded, use property arguments
285-
if ($meta= \xp::$meta[strtr($reflect->name, '\\', '.')][0] ?? null) {
295+
if ($meta= \xp::$meta[\xp::$cn[$reflect->name] ?? strtr($reflect->name, '\\', '.')][0] ?? null) {
286296
foreach ($meta as $name => $property) {
287297
if ($arg= $property[DETAIL_ARGUMENTS] ?? null) {
288298
$r[$name]= [$arg[0], $property[DETAIL_RETURNS]];

0 commit comments

Comments
 (0)