Skip to content

Commit 6a188e0

Browse files
committed
provide a global class::method[Action] yaml navigation, usable inside drupal
1 parent 489eb83 commit 6a188e0

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.intellij.patterns.PlatformPatterns;
77
import com.intellij.psi.PsiElement;
88
import com.intellij.psi.PsiFile;
9+
import com.jetbrains.php.lang.psi.elements.Method;
10+
import com.jetbrains.php.lang.psi.elements.PhpClass;
911
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
1012
import fr.adrienbrault.idea.symfony2plugin.TwigHelper;
1113
import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver;
@@ -18,10 +20,7 @@
1820
import org.jetbrains.yaml.YAMLLanguage;
1921
import org.jetbrains.yaml.YAMLTokenTypes;
2022

21-
import java.util.ArrayList;
22-
import java.util.Arrays;
23-
import java.util.Collection;
24-
import java.util.List;
23+
import java.util.*;
2524

2625
/**
2726
* @author Daniel Espendiller <daniel@espendiller.net>
@@ -61,7 +60,7 @@ public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Edit
6160
}
6261

6362
if(psiText.contains("\\")) {
64-
psiElements.addAll(Arrays.asList(classGoToDeclaration(psiElement, psiText))) ;
63+
psiElements.addAll(classGoToDeclaration(psiElement, psiText)) ;
6564
}
6665

6766
if(psiText.endsWith(".twig") || psiText.endsWith(".php")) {
@@ -71,8 +70,30 @@ public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Edit
7170
return psiElements.toArray(new PsiElement[psiElements.size()]);
7271
}
7372

74-
protected PsiElement[] classGoToDeclaration(PsiElement psiElement, String className) {
75-
return PhpElementsUtil.getClassInterfacePsiElements(psiElement.getProject(), className);
73+
protected Collection<PsiElement> classGoToDeclaration(PsiElement psiElement, String className) {
74+
75+
Collection<PsiElement> psiElements = new HashSet<PsiElement>();
76+
77+
// Class::method
78+
// Class::FooAction
79+
// Class:Foo
80+
if(className.contains(":")) {
81+
String[] split = className.replaceAll("(:)\\1", "$1").split(":");
82+
if(split.length == 2) {
83+
for(String append: new String[] {"", "Action"}) {
84+
Method classMethod = PhpElementsUtil.getClassMethod(psiElement.getProject(), split[0], split[1] + append);
85+
if(classMethod != null) {
86+
psiElements.add(classMethod);
87+
}
88+
}
89+
}
90+
91+
return psiElements;
92+
}
93+
94+
// ClassName
95+
psiElements.addAll(PhpElementsUtil.getClassesInterface(psiElement.getProject(), className));
96+
return psiElements;
7697
}
7798

7899
protected PsiElement[] serviceGoToDeclaration(PsiElement psiElement, String serviceId) {

src/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ static public PsiElement getPsiElementsBySignatureSingle(Project project, @Nulla
136136
return psiElements[0];
137137
}
138138

139+
@Deprecated
139140
static public PsiElement[] getClassInterfacePsiElements(Project project, String FQNClassOrInterfaceName) {
140141

141142
// convert ResolveResult to PsiElement
@@ -311,6 +312,16 @@ static public PhpClass getClassInterface(Project project, @NotNull String classN
311312
return phpClasses.size() == 0 ? null : phpClasses.iterator().next();
312313
}
313314

315+
static public Collection<PhpClass> getClassesInterface(Project project, @NotNull String className) {
316+
317+
// api workaround for at least interfaces
318+
if(!className.startsWith("\\")) {
319+
className = "\\" + className;
320+
}
321+
322+
return PhpIndex.getInstance(project).getAnyByFQN(className);
323+
}
324+
314325
static public void addClassPublicMethodCompletion(CompletionResultSet completionResultSet, PhpClass phpClass) {
315326
for(Method method: getClassPublicMethod(phpClass)) {
316327
completionResultSet.addElement(new PhpLookupElement(method));

0 commit comments

Comments
 (0)