Skip to content

Commit 92c347e

Browse files
authored
Merge pull request #1641 from adamwojs/issue_1640
Fixed #1640: Go to declaration throws ArrayIndexOutOfBoundsException on empty class const name
2 parents 1f80674 + c8388e2 commit 92c347e

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,11 @@ public static Collection<PsiElement> getTargetsForConstant(@NotNull Project proj
731731
contents = contents.replaceAll(":+", ":");
732732
String[] split = contents.split(":");
733733

734+
if (split.length < 2) {
735+
// Empty const name e.g. "\\App\\Foo::"
736+
return Collections.emptyList();
737+
}
738+
734739
Collection<PsiElement> psiElements = new ArrayList<>();
735740
for (PhpClass phpClass : PhpElementsUtil.getClassesInterface(project, split[0])) {
736741
Field fieldByName = phpClass.findFieldByName(split[1], true);

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/dic/container/util/ServiceContainerUtilTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ public void testVisitNamedArguments() {
357357
assertFalse(arguments.contains("private"));
358358
}
359359

360+
public void testGetTargetsForConstantForEmptyClassConstName() {
361+
assertEmpty(ServiceContainerUtil.getTargetsForConstant(getProject(), "\\App\\Service\\FooService::"));
362+
}
363+
360364
private static class MyStringServiceInterfaceCondition implements Condition<ServiceInterface> {
361365

362366
@NotNull

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/dic/container/util/fixtures/classes.php

+8
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,12 @@ private function fooPrivate($private)
2626
{
2727
}
2828
}
29+
}
30+
31+
namespace App\Service
32+
{
33+
class FooService
34+
{
35+
public const FOO = "foo";
36+
}
2937
}

0 commit comments

Comments
 (0)