Skip to content

Commit ea34a7c

Browse files
committed
also index tag attributes of services
1 parent 82bc31c commit ea34a7c

File tree

16 files changed

+165
-6
lines changed

16 files changed

+165
-6
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/config/ServiceLineMarkerProvider.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ private void classNameMarker(PsiElement psiElement, Collection<? super RelatedIt
111111
ContainerCollectionResolver.ServiceCollector serviceCollector = ContainerCollectionResolver.ServiceCollector.create(psiElement.getProject());
112112
for (String convertClassNameToService : serviceCollector.convertClassNameToServices(((PhpClass) phpClassContext).getFQN())) {
113113
tags.addAll(ServiceUtil.getServiceTags(phpClassContext.getProject(), convertClassNameToService));
114+
115+
ContainerService containerService = serviceCollector.getServices().get(convertClassNameToService);
116+
if (containerService != null) {
117+
ServiceInterface service = containerService.getService();
118+
if (service != null) {
119+
tags.addAll(service.getTags());
120+
}
121+
}
114122
}
115123
}
116124

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/attribute/value/AttributeValueAbstract.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import org.jetbrains.annotations.NotNull;
55
import org.jetbrains.annotations.Nullable;
66

7+
import java.util.Collection;
8+
import java.util.Collections;
9+
710
/**
811
* @author Daniel Espendiller <daniel@espendiller.net>
912
*/
@@ -39,6 +42,12 @@ public Boolean getBoolean(@NotNull String key, @Nullable Boolean defaultValue) {
3942
return aBoolean != null ? aBoolean : defaultValue;
4043
}
4144

45+
@NotNull
46+
@Override
47+
public Collection<String> getTags() {
48+
return Collections.emptyList();
49+
}
50+
4251
@Nullable
4352
@Override
4453
public String getString(@NotNull String key, @Nullable String defaultValue) {

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/attribute/value/AttributeValueInterface.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.jetbrains.annotations.NotNull;
55
import org.jetbrains.annotations.Nullable;
66

7+
import java.util.Collection;
8+
79
/**
810
* @author Daniel Espendiller <daniel@espendiller.net>
911
*/
@@ -21,6 +23,9 @@ public interface AttributeValueInterface {
2123
@Nullable
2224
Boolean getBoolean(@NotNull String key, @Nullable Boolean defaultValue);
2325

26+
@NotNull
27+
Collection<String> getTags();
28+
2429
@NotNull
2530
PsiElement getPsiElement();
2631
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/attribute/value/DummyAttributeValue.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import org.jetbrains.annotations.NotNull;
55
import org.jetbrains.annotations.Nullable;
66

7+
import java.util.Collection;
8+
import java.util.Collections;
9+
710
/**
811
* @author Daniel Espendiller <daniel@espendiller.net>
912
*/
@@ -40,6 +43,12 @@ public Boolean getBoolean(@NotNull String key, Boolean defaultValue) {
4043
return defaultValue;
4144
}
4245

46+
@NotNull
47+
@Override
48+
public Collection<String> getTags() {
49+
return Collections.emptySet();
50+
}
51+
4352
@NotNull
4453
@Override
4554
public PsiElement getPsiElement() {

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/attribute/value/XmlTagAttributeValue.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
import org.jetbrains.annotations.NotNull;
66
import org.jetbrains.annotations.Nullable;
77

8+
import java.util.Arrays;
9+
import java.util.Collection;
10+
import java.util.stream.Collectors;
11+
812
/**
913
* @author Daniel Espendiller <daniel@espendiller.net>
1014
*/
1115
public class XmlTagAttributeValue extends AttributeValueAbstract {
12-
1316
@NotNull
1417
private final XmlTag xmlTag;
1518

@@ -28,4 +31,14 @@ public String getString(@NotNull String key) {
2831

2932
return value;
3033
}
34+
35+
@NotNull
36+
@Override
37+
public Collection<String> getTags() {
38+
return Arrays.stream(xmlTag.getSubTags())
39+
.filter(subTag -> "tag".equals(subTag.getName()))
40+
.map(subTag -> subTag.getAttributeValue("name"))
41+
.filter(StringUtils::isNotBlank)
42+
.collect(Collectors.toSet());
43+
}
3144
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/attribute/value/YamlKeyValueAttributeValue.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.jetbrains.annotations.Nullable;
77
import org.jetbrains.yaml.psi.YAMLKeyValue;
88

9+
import java.util.Collection;
10+
911
/**
1012
* @author Daniel Espendiller <daniel@espendiller.net>
1113
*/
@@ -29,4 +31,10 @@ public String getString(@NotNull String key) {
2931

3032
return value;
3133
}
34+
35+
@NotNull
36+
@Override
37+
public Collection<String> getTags() {
38+
return YamlHelper.collectServiceTags(yamlKeyValue);
39+
}
3240
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/container/ImmutableDecoratorService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import org.jetbrains.annotations.NotNull;
44
import org.jetbrains.annotations.Nullable;
55

6+
import java.util.Collection;
7+
68
/**
79
* @author Daniel Espendiller <daniel@espendiller.net>
810
*
@@ -88,4 +90,10 @@ public String getResource() {
8890
public String getExclude() {
8991
return service.getExclude();
9092
}
93+
94+
@NotNull
95+
@Override
96+
public Collection<String> getTags() {
97+
return service.getTags();
98+
}
9199
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/container/SerializableService.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.jetbrains.annotations.NotNull;
66
import org.jetbrains.annotations.Nullable;
77

8+
import java.util.Collection;
9+
import java.util.HashSet;
810
import java.util.Objects;
911

1012
/**
@@ -62,6 +64,10 @@ public class SerializableService implements ServiceSerializable {
6264
@SerializedName("exclude")
6365
private String exclude;
6466

67+
@NotNull
68+
@SerializedName("tags")
69+
private Collection<String> tags = new HashSet<>();
70+
6571
public SerializableService(@NotNull String id) {
6672
this.id = id;
6773
}
@@ -189,6 +195,17 @@ public String getExclude() {
189195
return this.exclude;
190196
}
191197

198+
@NotNull
199+
@Override
200+
public Collection<String> getTags() {
201+
return tags;
202+
}
203+
204+
public SerializableService setTags(@NotNull Collection<String> tags) {
205+
this.tags = tags;
206+
return this;
207+
}
208+
192209
public SerializableService setResource(@Nullable String resource) {
193210
this.resource = resource;
194211
return this;
@@ -216,6 +233,7 @@ public int hashCode() {
216233
.append(this.parent)
217234
.append(this.resource)
218235
.append(this.exclude)
236+
.append(new HashSet<>(this.tags))
219237
.toHashCode()
220238
;
221239
}
@@ -236,7 +254,8 @@ public boolean equals(Object obj) {
236254
Objects.equals(((SerializableService) obj).decorationInnerName, this.decorationInnerName) &&
237255
Objects.equals(((SerializableService) obj).parent, this.parent) &&
238256
Objects.equals(((SerializableService) obj).resource, this.resource) &&
239-
Objects.equals(((SerializableService) obj).exclude, this.exclude)
257+
Objects.equals(((SerializableService) obj).exclude, this.exclude) &&
258+
Objects.equals(new HashSet<>(((SerializableService) obj).tags), new HashSet<>(this.tags))
240259
;
241260
}
242261
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/container/ServiceInterface.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import org.jetbrains.annotations.NotNull;
44
import org.jetbrains.annotations.Nullable;
55

6+
import java.util.Collection;
7+
68
/**
79
* @author Daniel Espendiller <daniel@espendiller.net>
810
*/
@@ -41,4 +43,7 @@ public interface ServiceInterface {
4143

4244
@Nullable
4345
String getExclude();
46+
47+
@NotNull
48+
Collection<String> getTags();
4449
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/container/XmlService.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import org.jetbrains.annotations.NotNull;
55
import org.jetbrains.annotations.Nullable;
66
import org.w3c.dom.Element;
7+
import org.w3c.dom.NodeList;
8+
9+
import java.util.Collection;
10+
import java.util.HashSet;
711

812
/**
913
* Create a service definition on a compiled debug xml file
@@ -22,6 +26,9 @@ public class XmlService implements ServiceInterface {
2226

2327
private String alias = null;
2428

29+
@NotNull
30+
private Collection<String> tags = new HashSet<>();
31+
2532
private XmlService(@NotNull String id) {
2633
this.id = id;
2734
}
@@ -99,6 +106,12 @@ public String getExclude() {
99106
return null;
100107
}
101108

109+
@NotNull
110+
@Override
111+
public Collection<String> getTags() {
112+
return this.tags;
113+
}
114+
102115
@Nullable
103116
public static XmlService createFromXml(@NotNull Element node) {
104117
// empty id does not interest us
@@ -143,6 +156,21 @@ public static XmlService createFromXml(@NotNull Element node) {
143156
xmlService.alias = alias;
144157
}
145158

159+
// <tag name="xml_type_tag"/>
160+
Collection<String> myTags = new HashSet<>();
161+
NodeList tags = node.getElementsByTagName("tag");
162+
int numTags = tags.getLength();
163+
for (int i = 0; i < numTags; i++) {
164+
Element section = (Element) tags.item(i);
165+
166+
String name = section.getAttribute("name");
167+
if (StringUtils.isNotBlank(name)) {
168+
myTags.add(name);
169+
}
170+
}
171+
172+
xmlService.tags = myTags;
173+
146174
return xmlService;
147175
}
148176

0 commit comments

Comments
 (0)