Skip to content

Commit d8da126

Browse files
committed
refactoring of completion for controller method which are inside service classes #428
1 parent 765f24e commit d8da126

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

src/fr/adrienbrault/idea/symfony2plugin/util/controller/ControllerIndex.java

+19-29
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
import fr.adrienbrault.idea.symfony2plugin.dic.XmlServiceParser;
1111
import fr.adrienbrault.idea.symfony2plugin.routing.Route;
1212
import fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper;
13+
import fr.adrienbrault.idea.symfony2plugin.routing.dic.ServiceRouteContainer;
1314
import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver;
1415
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
1516
import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
1617
import fr.adrienbrault.idea.symfony2plugin.util.SymfonyBundleUtil;
1718
import fr.adrienbrault.idea.symfony2plugin.util.dict.ServiceUtil;
1819
import fr.adrienbrault.idea.symfony2plugin.util.dict.SymfonyBundle;
1920
import fr.adrienbrault.idea.symfony2plugin.util.service.ServiceXmlParserFactory;
21+
import org.jetbrains.annotations.NotNull;
2022
import org.jetbrains.annotations.Nullable;
2123

2224
import java.util.*;
@@ -131,45 +133,33 @@ private List<ControllerAction> getActionMethods(SymfonyBundle symfonyBundle) {
131133
return actions;
132134
}
133135

134-
public ArrayList<ControllerAction> getServiceActionMethods(Project project) {
136+
@NotNull
137+
public List<ControllerAction> getServiceActionMethods(@NotNull Project project) {
135138

136-
ArrayList<ControllerAction> actions = new ArrayList<ControllerAction>();
137-
138-
Map<String,Route> routes = RouteHelper.getCompiledRoutes(project);
139+
Map<String,Route> routes = RouteHelper.getAllRoutes(project);
139140
if(routes.size() == 0) {
140-
return actions;
141-
}
142-
143-
ServiceMap serviceMap = ServiceXmlParserFactory.getInstance(project, XmlServiceParser.class).getServiceMap();
144-
if(serviceMap.getMap().size() == 0) {
145-
return actions;
141+
return Collections.emptyList();
146142
}
147143

148-
HashMap<String, String> controllerClassNames = new HashMap<String, String>();
149-
150144
// there is now way to find service controllers directly,
151145
// so we search for predefined service controller and use the public methods
152-
for (Map.Entry<String,Route> entrySet: routes.entrySet()) {
153-
String controllerName = entrySet.getValue().getController();
154-
if(controllerName != null && !controllerName.contains("::") && controllerName.contains(":")) {
155-
String serviceId = controllerName.substring(0, controllerName.lastIndexOf(":"));
156-
if(serviceMap.getMap().containsKey(serviceId)) {
157-
String className = serviceMap.getMap().get(serviceId);
158-
controllerClassNames.put(serviceId, className);
159-
}
146+
ContainerCollectionResolver.LazyServiceCollector collector = new ContainerCollectionResolver.LazyServiceCollector(project);
147+
148+
List<ControllerAction> actions = new ArrayList<ControllerAction>();
149+
for (String serviceName : ServiceRouteContainer.build(routes).getServiceNames()) {
150+
151+
PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(project, serviceName, collector);
152+
if(phpClass == null) {
153+
continue;
160154
}
161-
}
162155

163-
// find public method of the service class which are possible Actions
164-
for(Map.Entry<String, String> classDefinition: controllerClassNames.entrySet()) {
165-
PhpClass phpClass = PhpElementsUtil.getClass(this.phpIndex, classDefinition.getValue());
166-
if(phpClass != null) {
167-
for(Method method : phpClass.getMethods()) {
168-
if(method.getAccess().isPublic() && !method.getName().startsWith("__") && !method.getName().startsWith("set")) {
169-
actions.add(new ControllerAction(classDefinition.getKey() + ":" + method.getName(), method));
170-
}
156+
// find public method of the service class which are possible Actions
157+
for(Method method : phpClass.getMethods()) {
158+
if(method.getAccess().isPublic() && !method.getName().startsWith("__") && !method.getName().startsWith("set")) {
159+
actions.add(new ControllerAction(serviceName + ":" + method.getName(), method));
171160
}
172161
}
162+
173163
}
174164

175165
return actions;

0 commit comments

Comments
 (0)