Skip to content

Commit 3b71e6c

Browse files
authored
Merge pull request #1560 from Haehnchen/feature/bind-resource
support autowired resources services inside "argument bind" navigation
2 parents 564bdfa + ba00c4f commit 3b71e6c

File tree

3 files changed

+60
-26
lines changed

3 files changed

+60
-26
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/config/yaml/YamlGoToDeclarationHandler.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -514,38 +514,14 @@ public static Collection<PsiElement> getClassesForServiceKey(@NotNull YAMLKeyVal
514514
// resource: '....'
515515
// exclude: '....'
516516
if (valueText.endsWith("\\")) {
517-
Collection<String> resource = YamlHelper.getYamlKeyValueStringOrArray(yamlKeyValue, "resource");
518-
if (!resource.isEmpty()) {
519-
Collection<String> exclude = YamlHelper.getYamlKeyValueStringOrArray(yamlKeyValue, "exclude");
520-
targets.addAll(getPhpClassFromResources(yamlKeyValue.getProject(), valueText, yamlKeyValue.getContainingFile().getVirtualFile(), resource, exclude));
521-
}
517+
targets.addAll(YamlHelper.getNamespaceResourcesClasses(yamlKeyValue));
522518
}
523519

524520
targets.addAll(PhpElementsUtil.getClassesInterface(yamlKeyValue.getProject(), valueText));
525521

526522
return targets;
527523
}
528524

529-
@NotNull
530-
private static Collection<PhpClass> getPhpClassFromResources(@NotNull Project project, @NotNull String namespace, @NotNull VirtualFile source, @NotNull Collection<String> resource, @NotNull Collection<String> exclude) {
531-
Collection<PhpClass> phpClasses = new HashSet<>();
532-
533-
for (PhpClass phpClass : PhpIndexUtil.getPhpClassInsideNamespace(project, "\\" + StringUtils.strip(namespace, "\\"))) {
534-
boolean classMatchesGlob = ServiceIndexUtil.matchesResourcesGlob(
535-
source,
536-
phpClass.getContainingFile().getVirtualFile(),
537-
resource,
538-
exclude
539-
);
540-
541-
if (classMatchesGlob) {
542-
phpClasses.add(phpClass);
543-
}
544-
}
545-
546-
return phpClasses;
547-
}
548-
549525
@Nullable
550526
@Override
551527
public String getActionText(DataContext dataContext) {

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/container/util/ServiceContainerUtil.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import fr.adrienbrault.idea.symfony2plugin.dic.container.dict.ServiceTypeHint;
2828
import fr.adrienbrault.idea.symfony2plugin.dic.container.visitor.ServiceConsumer;
2929
import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver;
30+
import fr.adrienbrault.idea.symfony2plugin.stubs.ServiceIndexUtil;
3031
import fr.adrienbrault.idea.symfony2plugin.stubs.indexes.ContainerIdUsagesStubIndex;
3132
import fr.adrienbrault.idea.symfony2plugin.util.*;
3233
import fr.adrienbrault.idea.symfony2plugin.util.dict.ServiceUtil;
@@ -821,6 +822,33 @@ public static Collection<String> getContainerFiles(@NotNull Project project) {
821822
);
822823
}
823824

825+
/**
826+
* All class that matched against this pattern
827+
*
828+
* My<caret>Class\:
829+
* resource: '....'
830+
* exclude: '....'
831+
*/
832+
@NotNull
833+
public static Collection<PhpClass> getPhpClassFromResources(@NotNull Project project, @NotNull String namespace, @NotNull VirtualFile containerFile, @NotNull Collection<String> resource, @NotNull Collection<String> exclude) {
834+
Collection<PhpClass> phpClasses = new HashSet<>();
835+
836+
for (PhpClass phpClass : PhpIndexUtil.getPhpClassInsideNamespace(project, "\\" + StringUtils.strip(namespace, "\\"))) {
837+
boolean classMatchesGlob = ServiceIndexUtil.matchesResourcesGlob(
838+
containerFile,
839+
phpClass.getContainingFile().getVirtualFile(),
840+
resource,
841+
exclude
842+
);
843+
844+
if (classMatchesGlob) {
845+
phpClasses.add(phpClass);
846+
}
847+
}
848+
849+
return phpClasses;
850+
}
851+
824852
/**
825853
* Find possible compiled service file with seconds cache
826854
*

src/main/java/fr/adrienbrault/idea/symfony2plugin/util/yaml/YamlHelper.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ public boolean accepts(@NotNull PsiElement psiElement, ProcessingContext process
12631263

12641264
@NotNull
12651265
public static Collection<PhpClass> getPhpClassesInYamlFile(@NotNull YAMLFile yamlFile, @NotNull ContainerCollectionResolver.LazyServiceCollector lazyServiceCollector) {
1266-
Collection<PhpClass> phpClasses = new HashSet<>();
1266+
Collection<PhpClass> phpClasses = new HashSet<>(); //TODO
12671267

12681268
for (YAMLKeyValue keyValue : YamlHelper.getQualifiedKeyValuesInFile(yamlFile, "services")) {
12691269
YAMLValue value = keyValue.getValue();
@@ -1277,6 +1277,10 @@ public static Collection<PhpClass> getPhpClassesInYamlFile(@NotNull YAMLFile yam
12771277
phpClasses.add(serviceClass);
12781278
}
12791279
}
1280+
1281+
// My<caret>Class\:
1282+
// resource: ...
1283+
phpClasses.addAll(YamlHelper.getNamespaceResourcesClasses(keyValue));
12801284
} else if(value instanceof YAMLPlainTextImpl) {
12811285
// Foo\Bar: ~
12821286
String text = keyValue.getKeyText();
@@ -1290,6 +1294,32 @@ public static Collection<PhpClass> getPhpClassesInYamlFile(@NotNull YAMLFile yam
12901294
return phpClasses;
12911295
}
12921296

1297+
/**
1298+
* My<caret>Class\:
1299+
* resource: '....'
1300+
* exclude: '....'
1301+
*/
1302+
@NotNull
1303+
public static Collection<PhpClass> getNamespaceResourcesClasses(@NotNull YAMLKeyValue yamlKeyValue) {
1304+
String valueText = yamlKeyValue.getKeyText();
1305+
if (StringUtils.isBlank(valueText)) {
1306+
return Collections.emptyList();
1307+
}
1308+
1309+
Collection<PhpClass> phpClasses = new HashSet<>();
1310+
1311+
if (valueText.endsWith("\\")) {
1312+
Collection<String> resource = YamlHelper.getYamlKeyValueStringOrArray(yamlKeyValue, "resource");
1313+
if (!resource.isEmpty()) {
1314+
phpClasses.addAll(ServiceContainerUtil.getPhpClassFromResources(
1315+
yamlKeyValue.getProject(), valueText, yamlKeyValue.getContainingFile().getVirtualFile(), resource, YamlHelper.getYamlKeyValueStringOrArray(yamlKeyValue, "exclude"))
1316+
);
1317+
}
1318+
}
1319+
1320+
return phpClasses;
1321+
}
1322+
12931323
/**
12941324
* key: !my_tag <caret>
12951325
*/

0 commit comments

Comments
 (0)