|
30 | 30 | import com.jetbrains.php.lang.psi.elements.*;
|
31 | 31 | import fr.adrienbrault.idea.symfony2plugin.Settings;
|
32 | 32 | import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
|
33 |
| -import fr.adrienbrault.idea.symfony2plugin.Symfony2InterfacesUtil; |
34 | 33 | import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
|
35 | 34 | import fr.adrienbrault.idea.symfony2plugin.extension.RoutingLoader;
|
36 | 35 | import fr.adrienbrault.idea.symfony2plugin.extension.RoutingLoaderParameter;
|
|
56 | 55 | import org.jetbrains.annotations.NotNull;
|
57 | 56 | import org.jetbrains.annotations.Nullable;
|
58 | 57 | import org.jetbrains.yaml.YAMLFileType;
|
| 58 | +import org.jetbrains.yaml.YAMLUtil; |
59 | 59 | import org.jetbrains.yaml.psi.*;
|
60 | 60 |
|
61 | 61 | import java.io.File;
|
@@ -599,55 +599,54 @@ public boolean process(VirtualFile virtualFile) {
|
599 | 599 | }
|
600 | 600 |
|
601 | 601 | @NotNull
|
602 |
| - public static Collection<StubIndexedRoute> getYamlRouteDefinitions(YAMLDocument yamlDocument) { |
603 |
| - |
| 602 | + public static Collection<StubIndexedRoute> getYamlRouteDefinitions(@NotNull YAMLDocument yamlDocument) { |
604 | 603 | Collection<StubIndexedRoute> indexedRoutes = new ArrayList<StubIndexedRoute>();
|
605 | 604 |
|
606 |
| - // get services or parameter key |
607 |
| - YAMLKeyValue[] yamlKeys = PsiTreeUtil.getChildrenOfType(yamlDocument, YAMLKeyValue.class); |
608 |
| - if(yamlKeys == null) { |
609 |
| - return Collections.emptyList(); |
610 |
| - } |
| 605 | + for(YAMLKeyValue yamlKeyValue : YamlHelper.getTopLevelKeyValues((YAMLFile) yamlDocument.getContainingFile())) { |
611 | 606 |
|
612 |
| - for(YAMLKeyValue yamlKeyValue : yamlKeys) { |
| 607 | + YAMLValue element = yamlKeyValue.getValue(); |
613 | 608 |
|
614 |
| - PsiElement element = yamlKeyValue.getValue(); |
615 |
| - if(element instanceof YAMLCompoundValue) { |
616 |
| - Set<String> keySet = YamlHelper.getYamlCompoundValueKeyNames((YAMLCompoundValue) element); |
| 609 | + YAMLKeyValue path = YAMLUtil.findKeyInProbablyMapping(element, "path"); |
617 | 610 |
|
618 |
| - if((keySet.contains("path") || keySet.contains("pattern"))) { |
619 |
| - // cleanup: 'foo', "foo" |
620 |
| - String keyText = StringUtils.strip(StringUtils.strip(yamlKeyValue.getKeyText(), "'"), "\""); |
621 |
| - if(StringUtils.isNotBlank(keyText)) { |
622 |
| - StubIndexedRoute route = new StubIndexedRoute(keyText); |
| 611 | + // Symfony bc |
| 612 | + if(path == null) { |
| 613 | + path = YAMLUtil.findKeyInProbablyMapping(element, "pattern"); |
| 614 | + } |
623 | 615 |
|
624 |
| - String routePath = YamlHelper.getYamlKeyValueAsString((YAMLCompoundValue) element, "path", false); |
625 |
| - if(routePath == null) { |
626 |
| - routePath = YamlHelper.getYamlKeyValueAsString((YAMLCompoundValue) element, "pattern", false); |
627 |
| - } |
| 616 | + if(path == null) { |
| 617 | + continue; |
| 618 | + } |
628 | 619 |
|
629 |
| - if(routePath != null && StringUtils.isNotBlank(routePath)) { |
630 |
| - route.setPath(routePath); |
631 |
| - } |
| 620 | + // cleanup: 'foo', "foo" |
| 621 | + String keyText = StringUtils.strip(StringUtils.strip(yamlKeyValue.getKeyText(), "'"), "\""); |
| 622 | + if(StringUtils.isBlank(keyText)) { |
| 623 | + continue; |
| 624 | + } |
632 | 625 |
|
633 |
| - String methods = YamlHelper.getYamlKeyValueAsString((YAMLCompoundValue) element, "methods", false); |
634 |
| - if(methods != null) { |
635 |
| - // value: [GET, POST, |
636 |
| - String[] split = methods.replace("[", "").replace("]", "").replaceAll(" +", "").split(","); |
637 |
| - if(split.length > 0) { |
638 |
| - route.addMethod(split); |
639 |
| - } |
640 |
| - } |
| 626 | + StubIndexedRoute route = new StubIndexedRoute(keyText); |
641 | 627 |
|
642 |
| - String controller = getYamlController(yamlKeyValue); |
643 |
| - if(controller != null) { |
644 |
| - route.setController(controller); |
645 |
| - } |
| 628 | + String routePath = path.getValueText(); |
| 629 | + if(StringUtils.isNotBlank(routePath)) { |
| 630 | + route.setPath(routePath); |
| 631 | + } |
646 | 632 |
|
647 |
| - indexedRoutes.add(route); |
648 |
| - } |
| 633 | + String methods = YamlHelper.getStringValueOfKeyInProbablyMapping(element, "methods"); |
| 634 | + if(methods != null) { |
| 635 | + // value: [GET, POST, |
| 636 | + String[] split = methods.replace("[", "").replace("]", "").replaceAll(" +", "").split(","); |
| 637 | + if(split.length > 0) { |
| 638 | + route.addMethod(split); |
649 | 639 | }
|
650 | 640 | }
|
| 641 | + |
| 642 | + String controller = getYamlController(yamlKeyValue); |
| 643 | + if(controller != null) { |
| 644 | + route.setController(controller); |
| 645 | + } |
| 646 | + |
| 647 | + indexedRoutes.add(route); |
| 648 | + |
| 649 | + |
651 | 650 | }
|
652 | 651 |
|
653 | 652 | return indexedRoutes;
|
|
0 commit comments