Skip to content

Commit 016a275

Browse files
committedApr 20, 2015
optimize container as service navigation now its use indexed services, too. in preparation for #428
1 parent 7c5cef3 commit 016a275

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed
 

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

+18-13
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
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.stubs.ContainerCollectionResolver;
1314
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
1415
import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
1516
import fr.adrienbrault.idea.symfony2plugin.util.SymfonyBundleUtil;
17+
import fr.adrienbrault.idea.symfony2plugin.util.dict.ServiceUtil;
1618
import fr.adrienbrault.idea.symfony2plugin.util.dict.SymfonyBundle;
1719
import fr.adrienbrault.idea.symfony2plugin.util.service.ServiceXmlParserFactory;
1820
import org.jetbrains.annotations.Nullable;
@@ -21,8 +23,10 @@
2123

2224
public class ControllerIndex {
2325

24-
Project project;
25-
PhpIndex phpIndex;
26+
private Project project;
27+
private PhpIndex phpIndex;
28+
29+
private ContainerCollectionResolver.LazyServiceCollector lazyServiceCollector;
2630

2731
public ControllerIndex(Project project) {
2832
this.project = project;
@@ -52,20 +56,17 @@ public ControllerAction getControllerActionOnService(String shortcutName) {
5256
String serviceId = shortcutName.substring(0, shortcutName.lastIndexOf(":"));
5357
String methodName = shortcutName.substring(shortcutName.lastIndexOf(":") + 1);
5458

55-
ServiceMap serviceMap = ServiceXmlParserFactory.getInstance(this.project, XmlServiceParser.class).getServiceMap();
56-
57-
if(serviceMap.getMap().containsKey(serviceId)) {
58-
Collection<? extends PhpNamedElement> methodCalls = this.phpIndex.getBySignature("#M#C" + serviceMap.getMap().get(serviceId) + "." + methodName, null, 0);
59-
60-
for(PhpNamedElement phpNamedElement : methodCalls) {
61-
if(phpNamedElement instanceof Method) {
62-
return new ControllerAction(serviceId, (Method) phpNamedElement);
63-
}
64-
}
59+
PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(this.project, serviceId, getLazyServiceCollector(this.project));
60+
if(phpClass == null) {
61+
return null;
62+
}
6563

64+
Method method = phpClass.findMethodByName(methodName);
65+
if(method == null) {
66+
return null;
6667
}
6768

68-
return null;
69+
return new ControllerAction(serviceId, method);
6970
}
7071

7172
@Nullable
@@ -190,6 +191,10 @@ public Method resolveShortcutName(String controllerName) {
190191
return null;
191192
}
192193

194+
private ContainerCollectionResolver.LazyServiceCollector getLazyServiceCollector(Project project) {
195+
return this.lazyServiceCollector == null ? this.lazyServiceCollector = new ContainerCollectionResolver.LazyServiceCollector(project) : this.lazyServiceCollector;
196+
}
197+
193198
static public List<LookupElement> getControllerLookupElements(Project project) {
194199
List<LookupElement> lookupElements = new ArrayList<LookupElement>();
195200

‎tests/fr/adrienbrault/idea/symfony2plugin/tests/routing/RoutingDefinitionTest.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.intellij.ide.highlighter.XmlFileType;
44
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase;
55
import org.jetbrains.yaml.YAMLFileType;
6+
import java.io.File;
67

78
/**
89
* @author Daniel Espendiller <daniel@espendiller.net>
@@ -13,6 +14,8 @@ public class RoutingDefinitionTest extends SymfonyLightCodeInsightFixtureTestCas
1314
public void setUp() throws Exception {
1415
super.setUp();
1516

17+
myFixture.copyFileToProject("services.yml", "services.yml");
18+
1619
myFixture.configureByText("classes.php", "<?php\n" +
1720
"namespace AppBundle;\n" +
1821
"class AppBundle extends \\Symfony\\Component\\HttpKernel\\Bundle\\Bundle {}" +
@@ -31,6 +34,10 @@ public void setUp() throws Exception {
3134
);
3235
}
3336

37+
protected String getTestDataPath() {
38+
return new File(this.getClass().getResource("fixtures").getFile()).getAbsolutePath();
39+
}
40+
3441
public void testYamlCompletion() {
3542

3643
assertCompletionContains(YAMLFileType.YML, "foo:\n" +
@@ -59,7 +66,6 @@ public void testYamlCompletion() {
5966

6067
}
6168

62-
6369
public void testYamlNavigation() {
6470

6571
assertNavigationContains(YAMLFileType.YML, "foo:\n" +
@@ -87,4 +93,14 @@ public void testXmlCompletion() {
8793

8894
}
8995

96+
public void testControllerAsServiceNavigation() {
97+
98+
assertNavigationContains(YAMLFileType.YML, "foo:\n" +
99+
" pattern: /\n" +
100+
" defaults: { _controller: app.hello_controller<caret>:indexAction }\n"
101+
, "AppBundle\\Controller\\DefaultController::indexAction"
102+
);
103+
104+
}
105+
90106
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
app.hello_controller:
3+
class: AppBundle\Controller\DefaultController

0 commit comments

Comments
 (0)
Please sign in to comment.