|
30 | 30 | import com.jetbrains.php.lang.psi.elements.impl.PhpDefineImpl; |
31 | 31 | import com.jetbrains.php.lang.psi.resolve.types.PhpType; |
32 | 32 | import com.jetbrains.php.lang.psi.stubs.indexes.expectedArguments.PhpExpectedFunctionArgument; |
33 | | -import com.jetbrains.php.lang.psi.stubs.indexes.expectedArguments.PhpExpectedFunctionArgumentsRegistry; |
34 | 33 | import com.jetbrains.php.lang.psi.stubs.indexes.expectedArguments.PhpExpectedFunctionScalarArgument; |
35 | 34 | import com.jetbrains.php.phpunit.PhpUnitUtil; |
36 | 35 | import com.jetbrains.php.refactoring.PhpAliasImporter; |
@@ -1521,35 +1520,26 @@ public static int getFunctionArgumentByName(@NotNull Function function, @NotNull |
1521 | 1520 | return -1; |
1522 | 1521 | } |
1523 | 1522 |
|
1524 | | - /** |
1525 | | - * Single resolve doesnt work if we have non unique class names in project context, |
1526 | | - * so try a multiResolve |
1527 | | - */ |
1528 | 1523 | @NotNull |
1529 | | - public static Method[] getMultiResolvedMethod(@NotNull PsiReference psiReference) { |
1530 | | - // class be unique in normal case, so try this first |
1531 | | - PsiElement resolvedReference = psiReference.resolve(); |
1532 | | - if (resolvedReference instanceof Method) { |
1533 | | - return new Method[] { (Method) resolvedReference }; |
1534 | | - } |
1535 | | - |
1536 | | - // try multiResolve if class exists twice in project |
1537 | | - if(psiReference instanceof PsiPolyVariantReference) { |
1538 | | - Collection<Method> methods = new HashSet<>(); |
1539 | | - for(ResolveResult resolveResult : ((PsiPolyVariantReference) psiReference).multiResolve(false)) { |
1540 | | - PsiElement element = resolveResult.getElement(); |
1541 | | - if(element instanceof Method) { |
1542 | | - methods.add((Method) element); |
1543 | | - } |
1544 | | - } |
| 1524 | + public static Collection<Method> getMultiResolvedMethod(@NotNull MethodReference methodReference) { |
| 1525 | + PhpIndex instance = PhpIndex.getInstance(methodReference.getProject()); |
| 1526 | + PhpType classType = (new PhpType()).add(methodReference.getClassReference()).global(methodReference.getProject()); |
1545 | 1527 |
|
1546 | | - if(methods.size() > 0) { |
1547 | | - return methods.toArray(new Method[methods.size()]); |
1548 | | - } |
| 1528 | + Collection<PhpClass> instanceClasses = classType.getTypes() |
| 1529 | + .stream() |
| 1530 | + .flatMap((fqn) -> instance.getAnyByFQN(fqn).stream()) |
| 1531 | + .distinct() |
| 1532 | + .collect(Collectors.toList()); |
1549 | 1533 |
|
| 1534 | + Set<Method> methods = new HashSet<>(); |
| 1535 | + for (PhpClass phpClass : instanceClasses) { |
| 1536 | + Method method = phpClass.findMethodByName(methodReference.getName()); |
| 1537 | + if (method != null) { |
| 1538 | + methods.add(method); |
| 1539 | + } |
1550 | 1540 | } |
1551 | 1541 |
|
1552 | | - return new Method[0]; |
| 1542 | + return methods; |
1553 | 1543 | } |
1554 | 1544 |
|
1555 | 1545 | /** |
|
0 commit comments