Commit 19680623 authored by abragin's avatar abragin
Browse files

PY-4813 PySuperMethodSearchExecutor refactored

MRO and findFirst / findAll inconsistencies fixed.
parent ff72b10e
Showing with 4 additions and 34 deletions
+4 -34
......@@ -5,14 +5,9 @@ import com.intellij.psi.PsiElement;
import com.intellij.util.Processor;
import com.intellij.util.QueryExecutor;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.types.PyClassLikeType;
import com.jetbrains.python.psi.types.PyTypeUtil;
import com.jetbrains.python.psi.types.TypeEvalContext;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
/**
* @author yole
*/
......@@ -23,22 +18,11 @@ public class PySuperMethodsSearchExecutor implements QueryExecutor<PsiElement, P
final PyFunction func = queryParameters.getDerivedMethod();
final String name = func.getName();
final PyClass containingClass = func.getContainingClass();
final Set<PyClass> foundMethodContainingClasses = new HashSet<>();
final TypeEvalContext context = queryParameters.getContext();
if (name != null && containingClass != null) {
for (PyClass superClass : containingClass.getAncestorClasses(context)) {
if (!queryParameters.isDeepSearch()) {
boolean isAlreadyFound = false;
for (PyClass alreadyFound : foundMethodContainingClasses) {
if (alreadyFound.isSubclass(superClass, context)) {
isAlreadyFound = true;
}
}
if (isAlreadyFound) {
continue;
}
}
PyFunction superMethod = superClass.findMethodByName(name, false, context);
if (superMethod != null) {
final Property property = func.getProperty();
final Property superProperty = superMethod.getProperty();
......@@ -47,27 +31,13 @@ public class PySuperMethodsSearchExecutor implements QueryExecutor<PsiElement, P
final PyCallable callable = superProperty.getByDirection(direction).valueOrNull();
superMethod = (callable instanceof PyFunction) ? (PyFunction)callable : null;
}
}
if (superMethod == null && context != null) {
// If super method still not found and we have context, we may use it to find method
final PyClassLikeType classLikeType = PyUtil.as(context.getType(superClass), PyClassLikeType.class);
if (classLikeType != null) {
for (final PyFunction function : PyTypeUtil.getMembersOfType(classLikeType.toInstance(), PyFunction.class, true, context)) {
final String elemName = function.getName();
if (elemName != null && elemName.equals(func.getName())) {
consumer.process(function);
}
}
}
}
if (superMethod != null) {
foundMethodContainingClasses.add(superClass);
if (!consumer.process(superMethod)) {
boolean consumerWantsMore = consumer.process(superMethod);
if (!queryParameters.isDeepSearch() || !consumerWantsMore) {
return false;
}
}
}
}
return true;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment