Skip to content

Commit 9c6bc14

Browse files
authored
Merge pull request #1926 from Haehnchen/feature/empty-annotation
#1029 fix route not indexed if the annotation is empty
2 parents 0da8a46 + 4e48d57 commit 9c6bc14

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/visitor/AnnotationRouteElementWalkingVisitor.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ private void visitPhpDocTag(@NotNull PhpDocTag phpDocTag) {
7676
return;
7777
}
7878

79-
PsiElement phpDocAttributeList = PsiElementUtils.getChildrenOfType(phpDocTag, PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList));
80-
if(!(phpDocAttributeList instanceof PhpPsiElement)) {
81-
return;
82-
}
83-
8479
String routeName = AnnotationUtil.getPropertyValue(phpDocTag, "name");
8580
if(routeName == null) {
8681
routeName = AnnotationBackportUtil.getRouteByMethod(phpDocTag);
@@ -104,11 +99,14 @@ private void visitPhpDocTag(@NotNull PhpDocTag phpDocTag) {
10499
}
105100

106101
// extract method path @Route("/foo") => "/foo"
107-
PhpPsiElement firstPsiChild = ((PhpPsiElement) phpDocAttributeList).getFirstPsiChild();
108-
if(firstPsiChild instanceof StringLiteralExpression) {
109-
String contents = ((StringLiteralExpression) firstPsiChild).getContents();
110-
if(StringUtils.isNotBlank(contents)) {
111-
path += contents;
102+
PsiElement phpDocAttributeList = PsiElementUtils.getChildrenOfType(phpDocTag, PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList));
103+
if (phpDocAttributeList != null) {
104+
PhpPsiElement firstPsiChild = ((PhpPsiElement) phpDocAttributeList).getFirstPsiChild();
105+
if(firstPsiChild instanceof StringLiteralExpression) {
106+
String contents = ((StringLiteralExpression) firstPsiChild).getContents();
107+
if(StringUtils.isNotBlank(contents)) {
108+
path += contents;
109+
}
112110
}
113111
}
114112

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/stubs/indexes/RoutesStubIndexTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public String getTestDataPath() {
3131
public void testRouteIdIndex() {
3232
assertIndexContains(RoutesStubIndex.KEY,
3333
"foo_yaml_pattern", "foo_yaml_path", "foo_yaml_path_only",
34-
"foo_xml_pattern", "foo_xml_path", "foo_xml_id_only", "attributes_action", "app_my_default_attributeswithoutname"
34+
"foo_xml_pattern", "foo_xml_path", "foo_xml_id_only", "attributes_action", "app_my_default_attributeswithoutname",
35+
"my_post_emptyannotation", "myattributesprefix_prefixdefaultparameter_emptyattribute"
3536
);
3637

3738
assertIndexNotContains(RoutesStubIndex.KEY,

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/stubs/indexes/fixtures/RoutesStubIndex.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public function getHeadAction()
3434
{
3535
}
3636

37+
/**
38+
* @Route
39+
*/
40+
public function emptyAnnotation()
41+
{
42+
}
43+
3744
/**
3845
* @Route("/")
3946
*/
@@ -236,6 +243,11 @@ class PrefixDefaultParameterController
236243
public function editAction()
237244
{
238245
}
246+
247+
#[Route]
248+
public function emptyAttribute()
249+
{
250+
}
239251
}
240252
}
241253

0 commit comments

Comments
 (0)