|
1 | 1 | package fr.adrienbrault.idea.symfony2plugin.templating.util;
|
2 | 2 |
|
3 | 3 | import com.intellij.openapi.project.Project;
|
4 |
| -import com.intellij.openapi.util.Condition; |
5 | 4 | import com.intellij.openapi.util.Key;
|
6 | 5 | import com.intellij.patterns.PlatformPatterns;
|
7 | 6 | import com.intellij.psi.PsiElement;
|
@@ -153,29 +152,45 @@ private static String getCallableSignature(PsiElement psiElement, Method method)
|
153 | 152 | // array($this, 'getUrl')
|
154 | 153 | if(psiElement instanceof ArrayCreationExpression) {
|
155 | 154 | List<PsiElement> arrayValues = (List<PsiElement>) PsiElementUtils.getChildrenOfTypeAsList(psiElement, PlatformPatterns.psiElement(PhpElementTypes.ARRAY_VALUE));
|
156 |
| - if(arrayValues.size() > 1) { |
| 155 | + if (arrayValues.size() > 1) { |
157 | 156 | PsiElement firstChild = arrayValues.get(0).getFirstChild();
|
158 |
| - if(firstChild instanceof Variable && "this".equals(((Variable) firstChild).getName())) { |
| 157 | + if (firstChild instanceof Variable && "this".equals(((Variable) firstChild).getName())) { |
159 | 158 | String methodName = PhpElementsUtil.getStringValue(arrayValues.get(1).getFirstChild());
|
160 |
| - if(StringUtils.isNotBlank(methodName)) { |
| 159 | + if (StringUtils.isNotBlank(methodName)) { |
161 | 160 | PhpClass phpClass = method.getContainingClass();
|
162 |
| - if(phpClass != null) { |
| 161 | + if (phpClass != null) { |
163 | 162 | return String.format("#M#C\\%s.%s", phpClass.getPresentableFQN(), methodName);
|
164 | 163 | }
|
165 | 164 | }
|
166 | 165 | } else if (firstChild instanceof ClassConstantReference) {
|
167 | 166 | String classConstantPhpFqn = PhpElementsUtil.getClassConstantPhpFqn((ClassConstantReference) firstChild);
|
168 | 167 | if (StringUtils.isNotEmpty(classConstantPhpFqn)) {
|
169 | 168 | String methodName = PhpElementsUtil.getStringValue(arrayValues.get(1).getFirstChild());
|
170 |
| - if(StringUtils.isNotBlank(methodName)) { |
| 169 | + if (StringUtils.isNotBlank(methodName)) { |
171 | 170 | PhpClass phpClass = method.getContainingClass();
|
172 |
| - if(phpClass != null) { |
| 171 | + if (phpClass != null) { |
173 | 172 | return String.format("#M#C\\%s.%s", classConstantPhpFqn, methodName);
|
174 | 173 | }
|
175 | 174 | }
|
176 | 175 | }
|
177 | 176 | }
|
178 | 177 | }
|
| 178 | + } else if(psiElement instanceof PhpCallableMethod) { |
| 179 | + // we need to resolve the type, no api support |
| 180 | + // $this->foobar(...) |
| 181 | + PsiElement firstChild = ((PhpCallableMethod) psiElement).getFirstPsiChild(); |
| 182 | + if (firstChild instanceof Variable && "this".equals(((Variable) firstChild).getName())) { |
| 183 | + PhpClass phpClass = method.getContainingClass(); |
| 184 | + if (phpClass != null) { |
| 185 | + return String.format("#M#C\\%s.%s", phpClass.getPresentableFQN(), ((PhpCallableMethod) psiElement).getName()); |
| 186 | + } |
| 187 | + } |
| 188 | + } else if(psiElement instanceof PhpCallableFunction) { |
| 189 | + // foobar(...) |
| 190 | + String name = ((PhpCallableFunction) psiElement).getName(); |
| 191 | + if (StringUtils.isNotBlank(name)) { |
| 192 | + return "#F" + name; |
| 193 | + } |
179 | 194 | } else {
|
180 | 195 | String funcTargetName = PhpElementsUtil.getStringValue(psiElement);
|
181 | 196 | if(funcTargetName != null) {
|
@@ -470,7 +485,7 @@ private void visitNewExpression(@NotNull NewExpression element) {
|
470 | 485 | }
|
471 | 486 |
|
472 | 487 | // creation options like: needs_environment
|
473 |
| - Map<String, String> options; |
| 488 | + Map<String, String> options = new HashMap<>(); |
474 | 489 | if(psiElement.length > 2 && psiElement[2] instanceof ArrayCreationExpression) {
|
475 | 490 | options = getOptions((ArrayCreationExpression) psiElement[2]);
|
476 | 491 | } else {
|
|
0 commit comments