mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Partial fix for PY-1438
This commit is contained in:
@@ -10,9 +10,12 @@ import com.jetbrains.python.psi.PyCallExpression;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyExpression;
|
||||
import com.jetbrains.python.psi.PyReferenceExpression;
|
||||
import com.jetbrains.python.psi.types.PyClassType;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Alexey.Ivanov
|
||||
@@ -39,23 +42,41 @@ public class PySuperArgumentsInspection extends PyInspection {
|
||||
|
||||
@Override
|
||||
public void visitPyCallExpression(PyCallExpression node) {
|
||||
if (PyNames.SUPER.equals(node.getCallee().getName())) {
|
||||
PyExpression[] arguments = node.getArguments();
|
||||
if (arguments.length == 2) {
|
||||
if (arguments[0] instanceof PyReferenceExpression && arguments[1] instanceof PyReferenceExpression) {
|
||||
PsiElement firstElement = ((PyReferenceExpression) arguments[0]).followAssignmentsChain(myTypeEvalContext).getElement();
|
||||
PsiElement secondElement = ((PyReferenceExpression) arguments[1]).followAssignmentsChain(myTypeEvalContext).getElement();
|
||||
if (firstElement instanceof PyClass && secondElement instanceof PyClass) {
|
||||
PyClass firstClass = (PyClass) firstElement;
|
||||
PyClass secondClass = (PyClass) secondElement;
|
||||
if (!secondClass.isSubclass(firstClass)) {
|
||||
registerProblem(node.getArgumentList(), PyBundle.message("INSP.$0.is.not.superclass.of.$1",
|
||||
secondClass.getName(), firstClass.getName()));
|
||||
final PyExpression callee = node.getCallee();
|
||||
if (callee != null) {
|
||||
if (PyNames.SUPER.equals(callee.getName())) {
|
||||
PyExpression[] arguments = node.getArguments();
|
||||
if (arguments.length == 2) {
|
||||
if (arguments[0] instanceof PyReferenceExpression && arguments[1] instanceof PyReferenceExpression) {
|
||||
PyClass firstClass = findClassOf(arguments[0]);
|
||||
PyClass secondClass = findClassOf(arguments[1]);
|
||||
if (firstClass != null && secondClass != null) {
|
||||
if (!secondClass.isSubclass(firstClass)) {
|
||||
registerProblem(
|
||||
node.getArgumentList(),
|
||||
PyBundle.message("INSP.$0.is.not.superclass.of.$1",
|
||||
secondClass.getName(), firstClass.getName())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PyClass findClassOf(PyExpression argument) {
|
||||
PsiElement firstElement = ((PyReferenceExpression)argument).followAssignmentsChain(myTypeEvalContext).getElement();
|
||||
PyClass firstClass = null;
|
||||
if (firstElement instanceof PyClass) firstClass = (PyClass)firstElement;
|
||||
else if (firstElement instanceof PyExpression) {
|
||||
PyType first_type = ((PyExpression)firstElement).getType(TypeEvalContext.fast());
|
||||
if (first_type instanceof PyClassType) {
|
||||
firstClass = ((PyClassType)first_type).getPyClass();
|
||||
}
|
||||
}
|
||||
return firstClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user