@@ -151,7 +151,7 @@ private static class MyPsiRecursiveElementWalkingVisitor extends PsiRecursiveEle
151
151
private final Map <String , StubIndexedRoute > map ;
152
152
private Map <String , String > fileImports ;
153
153
154
- public MyPsiRecursiveElementWalkingVisitor (Map <String , StubIndexedRoute > map ) {
154
+ private MyPsiRecursiveElementWalkingVisitor (@ NotNull Map <String , StubIndexedRoute > map ) {
155
155
this .map = map ;
156
156
}
157
157
@@ -163,7 +163,7 @@ public void visitElement(PsiElement element) {
163
163
super .visitElement (element );
164
164
}
165
165
166
- public void visitPhpDocTag (PhpDocTag phpDocTag ) {
166
+ private void visitPhpDocTag (@ NotNull PhpDocTag phpDocTag ) {
167
167
168
168
// "@var" and user non related tags dont need an action
169
169
if (AnnotationBackportUtil .NON_ANNOTATION_TAGS .contains (phpDocTag .getName ())) {
@@ -189,24 +189,29 @@ public void visitPhpDocTag(PhpDocTag phpDocTag) {
189
189
return ;
190
190
}
191
191
192
- String routeName = AnnotationBackportUtil .getAnnotationRouteName ( phpDocAttributeList . getText () );
192
+ String routeName = AnnotationBackportUtil .getPropertyValue ( phpDocTag , "name" );
193
193
if (routeName == null ) {
194
194
routeName = AnnotationBackportUtil .getRouteByMethod (phpDocTag );
195
195
}
196
196
197
197
if (routeName != null && StringUtils .isNotBlank (routeName )) {
198
+ // prepend route name on PhpClass scope
199
+ String routeNamePrefix = getRouteNamePrefix (phpDocTag );
200
+ if (routeNamePrefix != null ) {
201
+ routeName = routeNamePrefix + routeName ;
202
+ }
198
203
199
204
StubIndexedRoute route = new StubIndexedRoute (routeName );
200
205
201
206
String path = "" ;
202
207
203
- // get class scope pattern
208
+ // extract class path @Route("/foo") => "/foo" for prefixing upcoming methods
204
209
String classPath = getClassRoutePattern (phpDocTag );
205
210
if (classPath != null ) {
206
211
path += classPath ;
207
212
}
208
213
209
- // extract method path
214
+ // extract method path @Route("/foo") => "/foo"
210
215
PhpPsiElement firstPsiChild = ((PhpPsiElement ) phpDocAttributeList ).getFirstPsiChild ();
211
216
if (firstPsiChild instanceof StringLiteralExpression ) {
212
217
String contents = ((StringLiteralExpression ) firstPsiChild ).getContents ();
@@ -228,6 +233,39 @@ public void visitPhpDocTag(PhpDocTag phpDocTag) {
228
233
}
229
234
}
230
235
236
+ /**
237
+ * Extract route name of parent class "@Route(name="foo_")"
238
+ */
239
+ @ Nullable
240
+ private String getRouteNamePrefix (@ NotNull PhpDocTag phpDocTag ) {
241
+ PhpClass phpClass = PsiTreeUtil .getParentOfType (phpDocTag , PhpClass .class );
242
+ if (phpClass == null ) {
243
+ return null ;
244
+ }
245
+
246
+ PhpDocComment docComment = phpClass .getDocComment ();
247
+ if (docComment == null ) {
248
+ return null ;
249
+ }
250
+
251
+ for (PhpDocTag docTag : PsiTreeUtil .getChildrenOfTypeAsList (docComment , PhpDocTag .class )) {
252
+ String annotationFqnName = AnnotationRoutesStubIndex .getClassNameReference (docTag , this .fileImports );
253
+
254
+ // check @Route or alias
255
+ if (annotationFqnName == null || !RouteHelper .isRouteClassAnnotation (annotationFqnName )) {
256
+ continue ;
257
+ }
258
+
259
+ // extract "name" property
260
+ String annotationRouteName = AnnotationBackportUtil .getPropertyValue (docTag , "name" );
261
+ if (StringUtils .isNotBlank (annotationRouteName )) {
262
+ return annotationRouteName ;
263
+ }
264
+ }
265
+
266
+ return null ;
267
+ }
268
+
231
269
private void extractMethods (@ NotNull PhpDocTag phpDocTag , @ NotNull StubIndexedRoute route ) {
232
270
PsiElement phpDoc = phpDocTag .getParent ();
233
271
if (!(phpDoc instanceof PhpDocComment )) {
0 commit comments