@@ -26,38 +26,38 @@ public class RouteHelper {
26
26
public static PsiElement [] getMethods (Project project , String routeName ) {
27
27
28
28
Symfony2ProjectComponent symfony2ProjectComponent = project .getComponent (Symfony2ProjectComponent .class );
29
- Map <String ,Route > routes = symfony2ProjectComponent .getRoutes ();
30
29
31
- for ( Route route : routes . values ( )) {
32
- if ( route . getName (). equals ( routeName )) {
33
- String controllerName = route . getController ();
30
+ if (! symfony2ProjectComponent . getRoutes (). containsKey ( routeName )) {
31
+ return new PsiElement [ 0 ];
32
+ }
34
33
35
- // convert to class: FooBundle\Controller\BarController::fooBarAction
36
- // convert to class: foo_service_bar:fooBar
37
- if (controllerName .contains ("::" )) {
38
- String className = controllerName .substring (0 , controllerName .lastIndexOf ("::" ));
39
- String methodName = controllerName .substring (controllerName .lastIndexOf ("::" ) + 2 );
34
+ Route route = symfony2ProjectComponent .getRoutes ().get (routeName );
40
35
41
- PhpIndex phpIndex = PhpIndex .getInstance (project );
42
- Collection <? extends PhpNamedElement > methodCalls = phpIndex .getBySignature ("#M#C\\ " + className + "." + methodName , null , 0 );
43
- return methodCalls .toArray (new PsiElement [methodCalls .size ()]);
36
+ String controllerName = route .getController ();
37
+ if (controllerName == null ) {
38
+ return new PsiElement [0 ];
39
+ }
44
40
45
- } else if (controllerName .contains (":" )) {
46
- ControllerIndex controllerIndex = new ControllerIndex (project );
41
+ // convert to class: FooBundle\Controller\BarController::fooBarAction
42
+ // convert to class: foo_service_bar:fooBar
43
+ if (controllerName .contains ("::" )) {
44
+ String className = controllerName .substring (0 , controllerName .lastIndexOf ("::" ));
45
+ String methodName = controllerName .substring (controllerName .lastIndexOf ("::" ) + 2 );
47
46
48
- ControllerAction controllerServiceAction = controllerIndex .getControllerActionOnService (controllerName );
49
- if (controllerServiceAction != null ) {
50
- return new PsiElement [] {controllerServiceAction .getMethod ()};
51
- }
47
+ return PhpElementsUtil .getPsiElementsBySignature (project , "#M#C\\ " + className + "." + methodName );
52
48
53
- }
49
+ } else if (controllerName .contains (":" )) {
50
+ ControllerIndex controllerIndex = new ControllerIndex (project );
54
51
55
- return new PsiElement [0 ];
52
+ ControllerAction controllerServiceAction = controllerIndex .getControllerActionOnService (controllerName );
53
+ if (controllerServiceAction != null ) {
54
+ return new PsiElement [] {controllerServiceAction .getMethod ()};
56
55
}
57
56
58
57
}
59
58
60
59
return new PsiElement [0 ];
60
+
61
61
}
62
62
63
63
private static <E > ArrayList <E > makeCollection (Iterable <E > iter ) {
@@ -79,7 +79,7 @@ public static Map<String, Route> getRoutes(Project project, VirtualFile virtualF
79
79
80
80
PsiFile psiFile = PsiElementUtils .virtualFileToPsiFile (project , virtualFile );
81
81
if (!(psiFile instanceof PhpFile )) {
82
-
82
+ return routes ;
83
83
}
84
84
85
85
// heavy stuff here, to get nested routing array :)
@@ -136,7 +136,7 @@ private static Route convertRouteConfig(String routeName, ArrayCreationExpressio
136
136
defaults = PhpElementsUtil .getArrayKeyValueMap ((ArrayCreationExpression ) hashElementCollection .get (1 ).getValue ());
137
137
}
138
138
139
- HashMap <String , String > requirements = new HashMap <String , String >();
139
+ HashMap <String , String >requirements = new HashMap <String , String >();
140
140
if (hashElementCollection .size () >= 3 && hashElementCollection .get (2 ).getValue () instanceof ArrayCreationExpression ) {
141
141
requirements = PhpElementsUtil .getArrayKeyValueMap ((ArrayCreationExpression ) hashElementCollection .get (2 ).getValue ());
142
142
}
0 commit comments