Skip to content

Commit 1814d43

Browse files
committed
#1767 replace method reference resolving with core way
1 parent 3fb23cb commit 1814d43

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

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

+15-24
Original file line numberDiff line numberDiff line change
@@ -1521,35 +1521,26 @@ public static int getFunctionArgumentByName(@NotNull Function function, @NotNull
15211521
return -1;
15221522
}
15231523

1524-
/**
1525-
* Single resolve doesnt work if we have non unique class names in project context,
1526-
* so try a multiResolve
1527-
*/
15281524
@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-
}
1525+
public static Collection<Method> getMultiResolvedMethod(@NotNull MethodReference methodReference) {
1526+
PhpIndex instance = PhpIndex.getInstance(methodReference.getProject());
1527+
PhpType classType = (new PhpType()).add(methodReference.getClassReference()).global(methodReference.getProject());
15451528

1546-
if(methods.size() > 0) {
1547-
return methods.toArray(new Method[methods.size()]);
1548-
}
1529+
Collection<PhpClass> instanceClasses = classType.getTypes()
1530+
.stream()
1531+
.flatMap((fqn) -> instance.getAnyByFQN(fqn).stream())
1532+
.distinct()
1533+
.collect(Collectors.toList());
15491534

1535+
Set<Method> methods = new HashSet<>();
1536+
for (PhpClass phpClass : instanceClasses) {
1537+
Method method = phpClass.findMethodByName(methodReference.getName());
1538+
if (method != null) {
1539+
methods.add(method);
1540+
}
15501541
}
15511542

1552-
return new Method[0];
1543+
return methods;
15531544
}
15541545

15551546
/**

0 commit comments

Comments
 (0)