|
10 | 10 | import com.intellij.psi.PsiElement; |
11 | 11 | import com.intellij.psi.PsiFile; |
12 | 12 | import com.intellij.psi.tree.IElementType; |
| 13 | +import com.intellij.psi.util.PsiTreeUtil; |
13 | 14 | import com.jetbrains.php.PhpIndex; |
14 | 15 | import com.jetbrains.php.lang.psi.elements.Method; |
15 | 16 | import com.jetbrains.php.lang.psi.elements.Parameter; |
@@ -54,8 +55,8 @@ public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Edit |
54 | 55 | // only string values like "foo", foo |
55 | 56 | if (elementType == YAMLTokenTypes.TEXT || elementType == YAMLTokenTypes.SCALAR_DSTRING || elementType == YAMLTokenTypes.SCALAR_STRING) { |
56 | 57 | String psiText = PsiElementUtils.getText(psiElement); |
57 | | - if(psiText != null && psiText.length() > 0) { |
58 | | - if(psiText.startsWith("@") && psiText.length() > 1) { |
| 58 | + if (psiText.length() > 0) { |
| 59 | + if (psiText.startsWith("@") && psiText.length() > 1) { |
59 | 60 | targets.addAll(serviceGoToDeclaration(psiElement, psiText.substring(1))); |
60 | 61 | } |
61 | 62 |
|
@@ -104,9 +105,9 @@ public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Edit |
104 | 105 | } |
105 | 106 |
|
106 | 107 | // yaml Plugin BC: "!php/const:" is a tag |
107 | | - if(elementType == YAMLTokenTypes.TAG) { |
| 108 | + if (elementType == YAMLTokenTypes.TAG) { |
108 | 109 | String psiText = PsiElementUtils.getText(psiElement); |
109 | | - if(psiText != null && psiText.length() > 0 && psiText.startsWith("!php/const:")) { |
| 110 | + if (psiText.startsWith("!php/const:")) { |
110 | 111 | targets.addAll(constantGoto(psiElement, psiText)); |
111 | 112 | } |
112 | 113 | } |
@@ -193,6 +194,19 @@ public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Edit |
193 | 194 | targets.addAll(attachResourceOrExcludeGlobNamespaceElements(psiElement)); |
194 | 195 | } |
195 | 196 |
|
| 197 | + // !tagged_iterator app.handler |
| 198 | + if (PlatformPatterns.psiElement(YAMLTokenTypes.TEXT).accepts(psiElement) || PlatformPatterns.psiElement(YAMLTokenTypes.TAG).accepts(psiElement)) { |
| 199 | + targets.addAll(attachTaggedIteratorClasses(psiElement)); |
| 200 | + } |
| 201 | + |
| 202 | + // !tagged_iterator { tag: app.handler, default_priority_method: getPriority } |
| 203 | + if (YamlElementPatternHelper.getSingleLineScalarKey("tag").accepts(psiElement)) { |
| 204 | + String tag = psiElement.getText(); |
| 205 | + if (StringUtils.isNotBlank(tag)) { |
| 206 | + targets.addAll(ServiceUtil.getTaggedClassesWithCompiled(psiElement.getProject(), tag)); |
| 207 | + } |
| 208 | + } |
| 209 | + |
196 | 210 | return targets.toArray(new PsiElement[0]); |
197 | 211 | } |
198 | 212 |
|
@@ -512,6 +526,56 @@ private Collection<PsiElement> attachResourceOnPathGoto(@NotNull PsiElement psiE |
512 | 526 | return new ArrayList<>(FileResourceUtil.getFileResourceTargetsInDirectoryScope(containingFile, text)); |
513 | 527 | } |
514 | 528 |
|
| 529 | + /** |
| 530 | + * Both elements are clickable, as parent element does not allow navigation |
| 531 | + * |
| 532 | + * "!tagged_iterator app.handler" |
| 533 | + */ |
| 534 | + @NotNull |
| 535 | + private Collection<PsiElement> attachTaggedIteratorClasses(@NotNull PsiElement psiElement) { |
| 536 | + if (psiElement.getNode().getElementType() == YAMLTokenTypes.TEXT) { |
| 537 | + PsiElement prevLeaf = PsiTreeUtil.prevCodeLeaf(psiElement); |
| 538 | + if (prevLeaf != null && prevLeaf.getNode().getElementType() == YAMLTokenTypes.TAG) { |
| 539 | + if ("!tagged_iterator".equals(prevLeaf.getText())) { |
| 540 | + String tag = psiElement.getText(); |
| 541 | + if (StringUtils.isNotBlank(tag)) { |
| 542 | + return new ArrayList<>(ServiceUtil.getTaggedClassesWithCompiled(psiElement.getProject(), tag)); |
| 543 | + } |
| 544 | + } |
| 545 | + } |
| 546 | + } else if (psiElement.getNode().getElementType() == YAMLTokenTypes.TAG) { |
| 547 | + // - !tagged_iterator ... |
| 548 | + |
| 549 | + if ("!tagged_iterator".equals(psiElement.getText())) { |
| 550 | + PsiElement nextLeaf = PsiTreeUtil.nextCodeLeaf(psiElement); |
| 551 | + |
| 552 | + if (nextLeaf != null && nextLeaf.getNode().getElementType() == YAMLTokenTypes.TEXT) { |
| 553 | + // - !tagged_iterator app.handler |
| 554 | + String tag = nextLeaf.getText(); |
| 555 | + if (StringUtils.isNotBlank(tag)) { |
| 556 | + return new ArrayList<>(ServiceUtil.getTaggedClassesWithCompiled(psiElement.getProject(), tag)); |
| 557 | + } |
| 558 | + } else { |
| 559 | + // - !tagged_iterator { tag: app.handler, default_priority_method: getPriority } |
| 560 | + YAMLKeyValue tagKeyValue = PsiElementUtils.getNextSiblingOfTypes(psiElement, YAMLKeyValue.class) |
| 561 | + .stream() |
| 562 | + .filter(yamlKeyValue -> "tag".equals(yamlKeyValue.getKeyText())) |
| 563 | + .findFirst() |
| 564 | + .orElse(null); |
| 565 | + |
| 566 | + if (tagKeyValue != null) { |
| 567 | + String tag = tagKeyValue.getValueText(); |
| 568 | + if (StringUtils.isNotBlank(tag)) { |
| 569 | + return new ArrayList<>(ServiceUtil.getTaggedClassesWithCompiled(psiElement.getProject(), tag)); |
| 570 | + } |
| 571 | + } |
| 572 | + } |
| 573 | + } |
| 574 | + } |
| 575 | + |
| 576 | + return Collections.emptyList(); |
| 577 | + } |
| 578 | + |
515 | 579 | @NotNull |
516 | 580 | private Collection<PsiElement> getControllerGoto(@NotNull PsiElement psiElement) { |
517 | 581 | String text = PsiElementUtils.trimQuote(psiElement.getText()); |
|
0 commit comments