Skip to content

Commit d6decda

Browse files
committed
add extension points to allow service collecting for external plugins
1 parent 3fcc879 commit d6decda

File tree

4 files changed

+124
-3
lines changed

4 files changed

+124
-3
lines changed

META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@
637637
<extensionPoint name="extension.TwigNamespaceExtension" interface="fr.adrienbrault.idea.symfony2plugin.extension.TwigNamespaceExtension"/>
638638
<extensionPoint name="extension.RoutingLoader" interface="fr.adrienbrault.idea.symfony2plugin.extension.RoutingLoader"/>
639639
<extensionPoint name="extension.CompiledServiceBuilderFactory" interface="fr.adrienbrault.idea.symfony2plugin.extension.CompiledServiceBuilderFactory"/>
640+
<extensionPoint name="extension.ServiceCollector" interface="fr.adrienbrault.idea.symfony2plugin.extension.ServiceCollector"/>
640641
</extensionPoints>
641642

642643
<extensions defaultExtensionNs="fr.adrienbrault.idea.symfony2plugin.extension">
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package fr.adrienbrault.idea.symfony2plugin.extension;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
/**
6+
* @author Daniel Espendiller <daniel@espendiller.net>
7+
*/
8+
public interface ServiceCollector {
9+
10+
/**
11+
* Warning expect high traffic, collector needs to be highly optimized
12+
*/
13+
void collectServices(@NotNull ServiceCollectorParameter.Service parameter);
14+
15+
/**
16+
* Warning expect high traffic, collector needs to be highly optimized
17+
*/
18+
void collectIds(@NotNull ServiceCollectorParameter.Id parameter);
19+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package fr.adrienbrault.idea.symfony2plugin.extension;
2+
3+
import com.intellij.openapi.project.Project;
4+
import fr.adrienbrault.idea.symfony2plugin.dic.container.SerializableService;
5+
import fr.adrienbrault.idea.symfony2plugin.dic.container.ServiceInterface;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import java.util.Collection;
9+
10+
/**
11+
* @author Daniel Espendiller <daniel@espendiller.net>
12+
*/
13+
public class ServiceCollectorParameter {
14+
15+
public static class Service {
16+
17+
@NotNull
18+
private final Project project;
19+
private final Collection<ServiceInterface> services;
20+
21+
public Service(@NotNull Project project, @NotNull Collection<ServiceInterface> services) {
22+
this.project = project;
23+
this.services = services;
24+
}
25+
26+
@NotNull
27+
public Project getProject() {
28+
return project;
29+
}
30+
31+
public void addService(@NotNull ServiceInterface service) {
32+
this.services.add(service);
33+
}
34+
35+
public void addServices(@NotNull Collection<ServiceInterface> services) {
36+
this.services.addAll(services);
37+
}
38+
39+
public void addService(@NotNull String id) {
40+
this.services.add(new SerializableService(id));
41+
}
42+
43+
public void addService(@NotNull String id, @NotNull String clazz) {
44+
this.services.add(new SerializableService(id).setClassName(clazz));
45+
}
46+
47+
public void addServices(@NotNull ServiceInterface service) {
48+
this.services.add(service);
49+
}
50+
51+
}
52+
53+
public static class Id {
54+
55+
@NotNull
56+
private final Project project;
57+
@NotNull
58+
private final Collection<String> names;
59+
60+
public Id(@NotNull Project project, @NotNull Collection<String> names) {
61+
this.project = project;
62+
this.names = names;
63+
}
64+
65+
@NotNull
66+
public Project getProject() {
67+
return project;
68+
}
69+
70+
public void addName(@NotNull String name) {
71+
this.names.add(name);
72+
}
73+
74+
public void addNames(@NotNull Collection<String> names) {
75+
this.names.addAll(names);
76+
}
77+
}
78+
}

src/fr/adrienbrault/idea/symfony2plugin/stubs/ContainerCollectionResolver.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.adrienbrault.idea.symfony2plugin.stubs;
22

3+
import com.intellij.openapi.extensions.ExtensionPointName;
34
import com.intellij.openapi.project.Project;
45
import com.intellij.openapi.util.Key;
56
import com.intellij.psi.search.GlobalSearchScope;
@@ -11,14 +12,12 @@
1112
import fr.adrienbrault.idea.symfony2plugin.dic.XmlServiceParser;
1213
import fr.adrienbrault.idea.symfony2plugin.dic.container.ServiceInterface;
1314
import fr.adrienbrault.idea.symfony2plugin.dic.container.dict.ContainerBuilderCall;
14-
import fr.adrienbrault.idea.symfony2plugin.dic.webDeployment.ServiceContainerRemoteFileStorage;
15-
import fr.adrienbrault.idea.symfony2plugin.routing.webDeployment.RoutingRemoteFileStorage;
15+
import fr.adrienbrault.idea.symfony2plugin.extension.ServiceCollectorParameter;
1616
import fr.adrienbrault.idea.symfony2plugin.stubs.cache.FileIndexCaches;
1717
import fr.adrienbrault.idea.symfony2plugin.stubs.indexes.ContainerBuilderStubIndex;
1818
import fr.adrienbrault.idea.symfony2plugin.stubs.indexes.ContainerParameterStubIndex;
1919
import fr.adrienbrault.idea.symfony2plugin.stubs.indexes.ServicesDefinitionStubIndex;
2020
import fr.adrienbrault.idea.symfony2plugin.util.service.ServiceXmlParserFactory;
21-
import fr.adrienbrault.idea.symfony2plugin.webDeployment.utils.RemoteWebServerUtil;
2221
import org.apache.commons.lang.StringUtils;
2322
import org.jetbrains.annotations.NotNull;
2423
import org.jetbrains.annotations.Nullable;
@@ -33,6 +32,10 @@ public class ContainerCollectionResolver {
3332
private static final Key<CachedValue<Set<String>>> SERVICE_CONTAINER_INDEX_NAMES = new Key<CachedValue<Set<String>>>("SYMFONY_SERVICE_CONTAINER_INDEX_NAMES");
3433
private static final Key<CachedValue<Set<String>>> SERVICE_PARAMETER_INDEX_NAMES = new Key<CachedValue<Set<String>>>("SERVICE_PARAMETER_INDEX_NAMES");
3534

35+
private static final ExtensionPointName<fr.adrienbrault.idea.symfony2plugin.extension.ServiceCollector> EXTENSIONS = new ExtensionPointName<>(
36+
"fr.adrienbrault.idea.symfony2plugin.extension.ServiceCollector"
37+
);
38+
3639
public static enum Source {
3740
INDEX, COMPILER
3841
}
@@ -199,6 +202,16 @@ public Map<String, ContainerService> getServices() {
199202

200203
Collection<ServiceInterface> aliases = new ArrayList<ServiceInterface>();
201204

205+
// Extension points
206+
ServiceCollectorParameter.Service parameter = null;
207+
for (fr.adrienbrault.idea.symfony2plugin.extension.ServiceCollector collectorEx : EXTENSIONS.getExtensions()) {
208+
if(parameter == null) {
209+
parameter = new ServiceCollectorParameter.Service(project, aliases);
210+
}
211+
212+
collectorEx.collectServices(parameter);
213+
}
214+
202215
for (Map.Entry<String, List<ServiceInterface>> entry : FileIndexCaches.getSetDataCache(project, SERVICE_CONTAINER_INDEX, SERVICE_CONTAINER_INDEX_NAMES, ServicesDefinitionStubIndex.KEY, ServiceIndexUtil.getRestrictedFileTypesScope(project)).entrySet()) {
203216

204217
// dont work twice on service;
@@ -298,6 +311,16 @@ private Set<String> getNames() {
298311

299312
if(this.sources.contains(Source.INDEX)) {
300313

314+
// Extension points
315+
ServiceCollectorParameter.Id parameter = null;
316+
for (fr.adrienbrault.idea.symfony2plugin.extension.ServiceCollector collectorEx : EXTENSIONS.getExtensions()) {
317+
if(parameter == null) {
318+
parameter = new ServiceCollectorParameter.Id(project, serviceNames);
319+
}
320+
321+
collectorEx.collectIds(parameter);
322+
}
323+
301324
serviceNames.addAll(
302325
FileIndexCaches.getIndexKeysCache(project, SERVICE_CONTAINER_INDEX_NAMES, ServicesDefinitionStubIndex.KEY)
303326
);

0 commit comments

Comments
 (0)