8000 Merge pull request #1558 from Haehnchen/feature/resources-array · SylApps/idea-php-symfony2-plugin@564bdfa · GitHub
[go: up one dir, main page]

Skip to content

Commit 564bdfa

Browse files
authored
Merge pull request Haehnchen#1558 from Haehnchen/feature/resources-array
support arrays for "resource" and "exclude" on autowrite which is use on Symfony >= 5 as default instead of global pattern
2 parents c826464 + 60069ef commit 564bdfa

19 files changed

+246
-94
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,9 @@ public static Collection<PsiElement> getClassesForServiceKey(@NotNull YAMLKeyVal
514514
// resource: '....'
515515
// exclude: '....'
516516
if (valueText.endsWith("\\")) {
517-
String resource = YamlHelper.getYamlKeyValueAsString(yamlKeyValue, "resource");
518-
if (resource != null) {
519-
String exclude = YamlHelper.getYamlKeyValueAsString(yamlKeyValue, "exclude");
517+
Collection<String> resource = YamlHelper.getYamlKeyValueStringOrArray(yamlKeyValue, "resource");
518+
if (!resource.isEmpty()) {
519+
Collection<String> exclude = YamlHelper.getYamlKeyValueStringOrArray(yamlKeyValue, "exclude");
520520
targets.addAll(getPhpClassFromResources(yamlKeyValue.getProject(), valueText, yamlKeyValue.getContainingFile().getVirtualFile(), resource, exclude));
521521
}
522522
}
@@ -527,7 +527,7 @@ public static Collection<PsiElement> getClassesForServiceKey(@NotNull YAMLKeyVal
527527
}
528528

529529
@NotNull
530-
private static Collection<PhpClass> getPhpClassFromResources(@NotNull Project project, @NotNull String namespace, @NotNull VirtualFile source, @NotNull String resource, @Nullable String exclude) {
530+
private static Collection<PhpClass> getPhpClassFromResources(@NotNull Project project, @NotNull String namespace, @NotNull VirtualFile source, @NotNull Collection<String> resource, @NotNull Collection<String> exclude) {
531531
Collection<PhpClass> phpClasses = new HashSet<>();
532532

533533
for (PhpClass phpClass : PhpIndexUtil.getPhpClassInsideNamespace(project, "\\" + StringUtils.strip(namespace, "\\"))) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,10 @@ public String getString(@NotNull String key, @Nullable String defaultValue) {
5959
public PsiElement getPsiElement() {
6060
return this.psiElement;
6161
}
62+
63+
@NotNull
64+
@Override
65+
public Collection<String> getStringArray(@NotNull String key) {
66+
return Collections.emptyList();
67+
}
6268
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public interface AttributeValueInterface {
1414
@Nullable
1515
String getString(@NotNull String key);
1616

17+
@NotNull
18+
Collection<String> getStringArray(@NotNull String key);
19+
1720
@Nullable
1821
Boolean getBoolean(@NotNull String key);
1922

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public String getString(@NotNull String key) {
2525
return null;
2626
}
2727

28+
@NotNull
29+
@Override
30+
public Collection<String> getStringArray(@NotNull String key) {
31+
return Collections.emptySet();
32+
}
33+
2834
@Nullable
2935
@Override
3036
public Boolean getBoolean(@NotNull String key) {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.Arrays;
99
import java.util.Collection;
10+
import java.util.Collections;
1011
import java.util.stream.Collectors;
1112

1213
/**
@@ -21,6 +22,16 @@ public XmlTagAttributeValue(@NotNull XmlTag xmlTag) {
2122
this.xmlTag = xmlTag;
2223
}
2324

25+
@NotNull
26+
@Override
27+
public Collection<String> getStringArray(@NotNull String key) {
28+
String string = getString(key);
29+
30+
return string != null
31+
? Collections.singleton(string)
32+
: Collections.emptyList();
33+
}
34+
2435
@Nullable
2536
@Override
2637
public String getString(@NotNull String key) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ public String getString(@NotNull String key) {
3737
public Collection<String> getTags() {
3838
return YamlHelper.collectServiceTags(yamlKeyValue);
3939
}
40+
41+
@NotNull
42+
@Override
43+
public Collection<String> getStringArray(@NotNull String key) {
44+
return YamlHelper.getYamlKeyValueStringOrArray(yamlKeyValue, key);
45+
}
4046
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ public String getDecorationInnerName() {
7979
return service.getDecorationInnerName();
8080
}
8181

82-
@Nullable
82+
@NotNull
8383
@Override
84-
public String getResource() {
84+
public Collection<String> getResource() {
8585
return service.getResource();
8686
}
8787

88-
@Nullable
88+
@NotNull
8989
@Override
90-
public String getExclude() {
90+
public Collection<String> getExclude() {
9191
return service.getExclude();
9292
}
9393

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ public class SerializableService implements ServiceSerializable {
5656
@Nullable
5757
private String parent;
5858

59-
@Nullable
59+
@NotNull
6060
@SerializedName("resource")
61-
private String resource;
61+
private Collection<String> resource = new HashSet<>();
6262

63-
@Nullable
63+
@NotNull
6464
@SerializedName("exclude")
65-
private String exclude;
65+
private Collection<String> exclude = new HashSet<>();
6666

6767
@NotNull
6868
@SerializedName("tags")
@@ -183,15 +183,15 @@ public SerializableService setDecorationInnerName(@Nullable String decorationInn
183183
return this;
184184
}
185185

186-
@Nullable
186+
@NotNull
187187
@Override
188-
public String getResource() {
188+
public Collection<String> getResource() {
189189
return this.resource;
190190
}
191191

192-
@Nullable
192+
@NotNull
193193
@Override
194-
public String getExclude() {
194+
public Collection<String> getExclude() {
195195
return this.exclude;
196196
}
197197

@@ -206,12 +206,12 @@ public SerializableService setTags(@NotNull Collection<String> tags) {
206206
return this;
207207
}
208208

209-
public SerializableService setResource(@Nullable String resource) {
209+
public SerializableService setResource(@NotNull Collection<String> resource) {
210210
this.resource = resource;
211211
return this;
212212
}
213213

214-
public SerializableService setExclude(@Nullable String exclude) {
214+
public SerializableService setExclude(@NotNull Collection<String> exclude) {
215215
this.exclude = exclude;
216216
return this;
217217
}
@@ -231,8 +231,8 @@ public int hashCode() {
231231
.append(this.decorates)
232232
.append(this.decorationInnerName)
233233
.append(this.parent)
234-
.append(this.resource)
235-
.append(this.exclude)
234+
.append(new HashSet<>(this.resource))
235+
.append(new HashSet<>(this.exclude))
236236
.append(new HashSet<>(this.tags))
237237
.toHashCode()
238238
;
@@ -244,7 +244,6 @@ public boolean equals(Object obj) {
244244
Objects.equals(((SerializableService) obj).id, this.id) &&
245245
Objects.equals(((SerializableService) obj).className, this.className) &&
246246
Objects.equals(((SerializableService) obj).isPublic, this.isPublic) &&
247-
Objects.equals(((SerializableService) obj).isDeprecated, this.isDeprecated) &&
248247
Objects.equals(((SerializableService) obj).isLazy, this.isLazy) &&
249248
Objects.equals(((SerializableService) obj).isAbstract, this.isAbstract) &&
250249
Objects.equals(((SerializableService) obj).isAutowire, this.isAutowire) &&
@@ -253,8 +252,8 @@ public boolean equals(Object obj) {
253252
Objects.equals(((SerializableService) obj).decorates, this.decorates) &&
254253
Objects.equals(((SerializableService) obj).decorationInnerName, this.decorationInnerName) &&
255254
Objects.equals(((SerializableService) obj).parent, this.parent) &&
256-
Objects.equals(((SerializableService) obj).resource, this.resource) &&
257-
Objects.equals(((SerializableService) obj).exclude, this.exclude) &&
255+
Objects.equals(new HashSet<>(((SerializableService) obj).resource), new HashSet<>(this.resource)) &&
256+
Objects.equals(new HashSet<>(((SerializableService) obj).exclude), new HashSet<>(this.exclude)) &&
258257
Objects.equals(new HashSet<>(((SerializableService) obj).tags), new HashSet<>(this.tags))
259258
;
260259
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public interface ServiceInterface {
3838
@Nullable
3939
String getDecorationInnerName();
4040

41-
@Nullable
42-
String getResource();
41+
@NotNull
42+
Collection<String> getResource();
4343

44-
@Nullable
45-
String getExclude();
44+
@NotNull
45+
Collection<String> getExclude();
4646

4747
@NotNull
4848
Collection<String> getTags();

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.w3c.dom.NodeList;
88

99
import java.util.Collection;
10+
import java.util.Collections;
1011
import java.util.HashSet;
1112

1213
/**
@@ -94,16 +95,16 @@ public String getDecorationInnerName() {
9495
return null;
9596
}
9697

97-
@Nullable
98+
@NotNull
9899
@Override
99-
public String getResource() {
100-
return null;
100+
public Collection<String> getResource() {
101+
return Collections.emptyList();
101102
}
102103

103-
@Nullable
104+
@NotNull
104105
@Override
105-
public String getExclude() {
106-
return null;
106+
public Collection<String> getExclude() {
107+
return Collections.emptyList();
107108
}
108109

109110
@NotNull

0 commit comments

Comments
 (0)
0