|
2 | 2 |
|
3 | 3 | import com.intellij.openapi.project.Project; |
4 | 4 | import com.intellij.psi.PsiElement; |
| 5 | +import com.intellij.psi.PsiPolyVariantReference; |
5 | 6 | import com.intellij.psi.PsiReference; |
| 7 | +import com.intellij.psi.ResolveResult; |
6 | 8 | import com.jetbrains.php.PhpIndex; |
7 | 9 | import com.jetbrains.php.lang.psi.elements.Method; |
8 | 10 | import com.jetbrains.php.lang.psi.elements.MethodReference; |
@@ -148,25 +150,58 @@ protected boolean isCallTo(PsiElement e, Method[] expectedMethods, int deepness) |
148 | 150 | return false; |
149 | 151 | } |
150 | 152 |
|
151 | | - PsiElement resolvedReference = psiReference.resolve(); |
152 | | - if (!(resolvedReference instanceof Method)) { |
| 153 | + Method method = getMultiResolvedMethod(psiReference); |
| 154 | + if (method == null) { |
153 | 155 | return false; |
154 | 156 | } |
155 | 157 |
|
156 | | - Method method = (Method) resolvedReference; |
157 | 158 | PhpClass methodClass = method.getContainingClass(); |
| 159 | + if(methodClass == null) { |
| 160 | + return false; |
| 161 | + } |
158 | 162 |
|
159 | | - for (Method expectedMethod : Arrays.asList(expectedMethods)) { |
160 | | - if (null != expectedMethod |
161 | | - && expectedMethod.getName().equals(method.getName()) |
162 | | - && isInstanceOf(methodClass, expectedMethod.getContainingClass())) { |
| 163 | + for (Method expectedMethod : expectedMethods) { |
| 164 | + |
| 165 | + // @TODO: its stuff from beginning times :) |
| 166 | + if(expectedMethod == null) { |
| 167 | + continue; |
| 168 | + } |
| 169 | + |
| 170 | + PhpClass containingClass = expectedMethod.getContainingClass(); |
| 171 | + if (null != containingClass && expectedMethod.getName().equals(method.getName()) && isInstanceOf(methodClass, containingClass)) { |
163 | 172 | return true; |
164 | 173 | } |
165 | 174 | } |
166 | 175 |
|
167 | 176 | return false; |
168 | 177 | } |
169 | 178 |
|
| 179 | + /** |
| 180 | + * Single resolve doesnt work if we have non unique class names in project context, |
| 181 | + * so try a multiResolve and use first matched method |
| 182 | + */ |
| 183 | + @Nullable |
| 184 | + protected static Method getMultiResolvedMethod(PsiReference psiReference) { |
| 185 | + |
| 186 | + // class be unique in normal case, so try this first |
| 187 | + PsiElement resolvedReference = psiReference.resolve(); |
| 188 | + if (resolvedReference instanceof Method) { |
| 189 | + return (Method) resolvedReference; |
| 190 | + } |
| 191 | + |
| 192 | + // try multiResolve if class exists twice in project |
| 193 | + if(psiReference instanceof PsiPolyVariantReference) { |
| 194 | + for(ResolveResult resolveResult : ((PsiPolyVariantReference) psiReference).multiResolve(false)) { |
| 195 | + PsiElement element = resolveResult.getElement(); |
| 196 | + if(element instanceof Method) { |
| 197 | + return (Method) element; |
| 198 | + } |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + return null; |
| 203 | + } |
| 204 | + |
170 | 205 | protected boolean isMatchingMethodName(MethodReference methodRef, Method[] expectedMethods) { |
171 | 206 | for (Method expectedMethod : Arrays.asList(expectedMethods)) { |
172 | 207 | if(expectedMethod != null && expectedMethod.getName().equals(methodRef.getName())) { |
|
0 commit comments