22
33import com .intellij .patterns .PlatformPatterns ;
44import com .intellij .psi .PsiElement ;
5- import com .intellij .psi .PsiRecursiveElementWalkingVisitor ;
65import com .intellij .psi .util .PsiTreeUtil ;
76import com .intellij .util .containers .ContainerUtil ;
7+ import com .jetbrains .php .lang .documentation .phpdoc .PhpDocUtil ;
88import com .jetbrains .php .lang .documentation .phpdoc .parser .PhpDocElementTypes ;
99import com .jetbrains .php .lang .documentation .phpdoc .psi .PhpDocComment ;
1010import com .jetbrains .php .lang .documentation .phpdoc .psi .tags .PhpDocTag ;
3030 *
3131 * @author Daniel Espendiller <daniel@espendiller.net>
3232 */
33- public class AnnotationRouteElementWalkingVisitor extends PsiRecursiveElementWalkingVisitor {
33+ public class AnnotationRouteElementVisitor {
3434 @ NotNull
3535 private final Map <String , StubIndexedRoute > map ;
3636
@@ -40,32 +40,35 @@ public class AnnotationRouteElementWalkingVisitor extends PsiRecursiveElementWal
4040 @ NotNull
4141 private final Consumer <Pair <String , PsiElement >> consumer ;
4242
43- public AnnotationRouteElementWalkingVisitor (@ NotNull Consumer <Pair <String , PsiElement >> consumer ) {
43+ public AnnotationRouteElementVisitor (@ NotNull Consumer <Pair <String , PsiElement >> consumer ) {
4444 this .consumer = consumer ;
4545 this .map = new HashMap <>();
4646 }
4747
48- public AnnotationRouteElementWalkingVisitor (@ NotNull Map <String , StubIndexedRoute > map ) {
48+ public AnnotationRouteElementVisitor (@ NotNull Map <String , StubIndexedRoute > map ) {
4949 this .map = map ;
5050 this .consumer = c -> {};
5151 }
5252
53- @ Override
54- public void visitElement (PsiElement element ) {
55- if ((element instanceof PhpDocTag )) {
56- visitPhpDocTag ((PhpDocTag ) element );
57- }
53+ public void visitFile (@ NotNull PhpClass phpClass ) {
54+ for (Method method : phpClass .getOwnMethods ()) {
55+ PhpDocComment docComment = method .getDocComment ();
56+ if (docComment != null ) {
57+ PhpDocUtil .processTagElementsByName (docComment , null , docTag -> {
58+ visitPhpDocTag (docTag );
59+ return true ;
60+ });
61+ }
5862
59- if ((element instanceof PhpAttributesList )) {
60- visitPhpAttributesList ((PhpAttributesList ) element );
63+ PhpAttributesList childOfType = PsiTreeUtil .getChildOfType (method , PhpAttributesList .class );
64+ if (childOfType != null ) {
65+ visitPhpAttributesList (childOfType );
66+ }
6167 }
62-
63- super .visitElement (element );
6468 }
65-
6669 private void visitPhpDocTag (@ NotNull PhpDocTag phpDocTag ) {
6770
68- // "@var" and user non related tags dont need an action
71+ // "@var" and user non- related tags don't need an action
6972 if (AnnotationBackportUtil .NON_ANNOTATION_TAGS .contains (phpDocTag .getName ())) {
7073 return ;
7174 }
@@ -89,7 +92,7 @@ private void visitPhpDocTag(@NotNull PhpDocTag phpDocTag) {
8992 routeName = AnnotationBackportUtil .getRouteByMethod (phpDocTag );
9093 }
9194
92- if (routeName != null && StringUtils .isNotBlank (routeName )) {
95+ if (StringUtils .isNotBlank (routeName )) {
9396 // prepend route name on PhpClass scope
9497 String routeNamePrefix = getRouteNamePrefix (phpDocTag );
9598 if (routeNamePrefix != null ) {
0 commit comments