Skip to content

Commit

Permalink
Merge pull request #1926 from Haehnchen/feature/empty-annotation
Browse files Browse the repository at this point in the history
#1029 fix route not indexed if the annotation is empty
  • Loading branch information
Haehnchen committed May 9, 2022
2 parents 0da8a46 + 4e48d57 commit 9c6bc14
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ private void visitPhpDocTag(@NotNull PhpDocTag phpDocTag) {
return;
}

PsiElement phpDocAttributeList = PsiElementUtils.getChildrenOfType(phpDocTag, PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList));
if(!(phpDocAttributeList instanceof PhpPsiElement)) {
return;
}

String routeName = AnnotationUtil.getPropertyValue(phpDocTag, "name");
if(routeName == null) {
routeName = AnnotationBackportUtil.getRouteByMethod(phpDocTag);
Expand All @@ -104,11 +99,14 @@ private void visitPhpDocTag(@NotNull PhpDocTag phpDocTag) {
}

// extract method path @Route("/foo") => "/foo"
PhpPsiElement firstPsiChild = ((PhpPsiElement) phpDocAttributeList).getFirstPsiChild();
if(firstPsiChild instanceof StringLiteralExpression) {
String contents = ((StringLiteralExpression) firstPsiChild).getContents();
if(StringUtils.isNotBlank(contents)) {
path += contents;
PsiElement phpDocAttributeList = PsiElementUtils.getChildrenOfType(phpDocTag, PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList));
if (phpDocAttributeList != null) {
PhpPsiElement firstPsiChild = ((PhpPsiElement) phpDocAttributeList).getFirstPsiChild();
if(firstPsiChild instanceof StringLiteralExpression) {
String contents = ((StringLiteralExpression) firstPsiChild).getContents();
if(StringUtils.isNotBlank(contents)) {
path += contents;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public String getTestDataPath() {
public void testRouteIdIndex() {
assertIndexContains(RoutesStubIndex.KEY,
"foo_yaml_pattern", "foo_yaml_path", "foo_yaml_path_only",
"foo_xml_pattern", "foo_xml_path", "foo_xml_id_only", "attributes_action", "app_my_default_attributeswithoutname"
"foo_xml_pattern", "foo_xml_path", "foo_xml_id_only", "attributes_action", "app_my_default_attributeswithoutname",
"my_post_emptyannotation", "myattributesprefix_prefixdefaultparameter_emptyattribute"
);

assertIndexNotContains(RoutesStubIndex.KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public function getHeadAction()
{
}

/**
* @Route
*/
public function emptyAnnotation()
{
}

/**
* @Route("/")
*/
Expand Down Expand Up @@ -236,6 +243,11 @@ class PrefixDefaultParameterController
public function editAction()
{
}

#[Route]
public function emptyAttribute()
{
}
}
}

Expand Down

0 comments on commit 9c6bc14

Please sign in to comment.