mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Removed redundant PyClass.getSuperClassElements() method
This commit is contained in:
@@ -132,4 +132,8 @@ public class PyJavaClassType implements PyClassLikeType {
|
||||
public boolean isValid() {
|
||||
return myClass.isValid();
|
||||
}
|
||||
|
||||
public PsiClass getPsiClass() {
|
||||
return myClass;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -9,6 +9,8 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.search.PySuperMethodsSearch;
|
||||
import com.jetbrains.python.psi.types.PyClassLikeType;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -19,10 +21,9 @@ public class PyJavaSuperMethodsSearchExecutor implements QueryExecutor<PsiElemen
|
||||
PyFunction func = queryParameters.getDerivedMethod();
|
||||
PyClass containingClass = func.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
PsiElement[] superClassElements = containingClass.getSuperClassElements();
|
||||
for(PsiElement element: superClassElements) {
|
||||
if (element instanceof PsiClass) {
|
||||
PsiClass psiClass = (PsiClass) element;
|
||||
for (PyClassLikeType type : containingClass.getSuperClassTypes(TypeEvalContext.codeInsightFallback())) {
|
||||
if (type instanceof PyJavaClassType) {
|
||||
final PsiClass psiClass = ((PyJavaClassType)type).getPsiClass();
|
||||
PsiMethod[] methods = psiClass.findMethodsByName(func.getName(), true);
|
||||
// the Python method actually does override/implement all of Java super methods with the same name
|
||||
if (!ContainerUtil.process(methods, consumer)) return false;
|
||||
|
||||
@@ -95,14 +95,6 @@ public interface PyClass extends PsiNameIdentifierOwner, PyStatement, NameDefine
|
||||
@NotNull
|
||||
PyExpression[] getSuperClassExpressions();
|
||||
|
||||
/**
|
||||
* Returns resolved elements representing super classes from the super classes list.
|
||||
*
|
||||
* Operates at the AST level.
|
||||
*/
|
||||
@NotNull
|
||||
PsiElement[] getSuperClassElements();
|
||||
|
||||
@NotNull
|
||||
PyFunction[] getMethods();
|
||||
|
||||
|
||||
@@ -2,11 +2,12 @@ package com.jetbrains.python.inspections;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionToolSession;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.types.PyClassLikeType;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -57,12 +58,21 @@ public class PyOldStyleClassesInspection extends PyInspection {
|
||||
public void visitPyCallExpression(final PyCallExpression node) {
|
||||
PyClass klass = PsiTreeUtil.getParentOfType(node, PyClass.class);
|
||||
if (klass != null && !klass.isNewStyleClass()) {
|
||||
PyExpression[] superClassExprs = klass.getSuperClassExpressions();
|
||||
PsiElement[] superClasses = klass.getSuperClassElements();
|
||||
if (superClasses.length != superClassExprs.length) return;
|
||||
if (hasUnknownAncestors(klass, myTypeEvalContext)) {
|
||||
return;
|
||||
}
|
||||
if (PyUtil.isSuperCall(node))
|
||||
registerProblem(node.getCallee(), "Old-style class contains call for super method");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasUnknownAncestors(@NotNull PyClass cls, @NotNull TypeEvalContext context) {
|
||||
for (PyClassLikeType type : cls.getAncestorTypes(context)) {
|
||||
if (type == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
|
||||
import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil;
|
||||
import com.jetbrains.python.documentation.DocStringUtil;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveContext;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveUtil;
|
||||
import com.jetbrains.python.psi.resolve.QualifiedNameFinder;
|
||||
import com.jetbrains.python.psi.stubs.PropertyStubStorage;
|
||||
@@ -159,31 +158,6 @@ public class PyClassImpl extends PyPresentableElementImpl<PyClassStub> implement
|
||||
return PyExpression.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiElement[] getSuperClassElements() {
|
||||
final PyExpression[] superExpressions = getSuperClassExpressions();
|
||||
List<PsiElement> superClasses = new ArrayList<PsiElement>();
|
||||
for (PyExpression expr : superExpressions) {
|
||||
if (expr instanceof PyKeywordArgument) {
|
||||
continue;
|
||||
}
|
||||
superClasses.add(classElementFromExpression(expr));
|
||||
}
|
||||
return PsiUtilCore.toPsiElementArray(superClasses);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement classElementFromExpression(@NotNull PyExpression expression) {
|
||||
expression = unfoldClass(expression);
|
||||
if (expression instanceof PyReferenceExpression) {
|
||||
final PsiPolyVariantReference ref = ((PyReferenceExpression)expression).getReference(PyResolveContext.noProperties());
|
||||
if (ref != null) {
|
||||
return ref.resolve();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PyExpression unfoldClass(@NotNull PyExpression expression) {
|
||||
if (expression instanceof PyCallExpression) {
|
||||
|
||||
Reference in New Issue
Block a user