mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Update usages of PyClassImpl.isSubclass(PyClass, TypeEvalContext) and specify context where possible
This commit is contained in:
@@ -120,7 +120,8 @@ public class PyCallByClassInspection extends PyInspection {
|
||||
if (method != null) {
|
||||
PyClass calling_class = method.getContainingClass();
|
||||
assert calling_class != null; // it's a method
|
||||
if (first_arg_class.isSubclass(qual_class, null) && calling_class.isSubclass(qual_class, null)) {
|
||||
if (first_arg_class.isSubclass(qual_class, myTypeEvalContext) &&
|
||||
calling_class.isSubclass(qual_class, myTypeEvalContext)) {
|
||||
break;
|
||||
// TODO: might propose to switch to super() here
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class PyMethodParametersInspection extends PyInspection {
|
||||
PsiElement zope_interface = findZopeInterface(node);
|
||||
final PyClass cls = node.getContainingClass();
|
||||
if (zope_interface instanceof PyClass) {
|
||||
if (cls != null && cls.isSubclass((PyClass) zope_interface, null)) return; // it can have any params
|
||||
if (cls != null && cls.isSubclass((PyClass) zope_interface, myTypeEvalContext)) return; // it can have any params
|
||||
}
|
||||
// analyze function itself
|
||||
PyUtil.MethodFlags flags = PyUtil.MethodFlags.of(node);
|
||||
|
||||
@@ -141,12 +141,12 @@ public class PyProtectedMemberInspection extends PyInspection {
|
||||
if (parentClass != null) {
|
||||
if (PyTestUtil.isPyTestClass(parentClass, null) && ignoreTestFunctions) return;
|
||||
|
||||
if (parentClass.isSubclass(resolvedClass, null))
|
||||
if (parentClass.isSubclass(resolvedClass, myTypeEvalContext))
|
||||
return;
|
||||
|
||||
PyClass outerClass = getClassOwner(parentClass);
|
||||
while (outerClass != null) {
|
||||
if (outerClass.isSubclass(resolvedClass, null))
|
||||
if (outerClass.isSubclass(resolvedClass, myTypeEvalContext))
|
||||
return;
|
||||
|
||||
outerClass = getClassOwner(outerClass);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class PySuperArgumentsInspection extends PyInspection {
|
||||
PyClass firstClass = findClassOf(arguments[0]);
|
||||
PyClass secondClass = findClassOf(arguments[1]);
|
||||
if (firstClass != null && secondClass != null) {
|
||||
if (!secondClass.isSubclass(firstClass, null)) {
|
||||
if (!secondClass.isSubclass(firstClass, myTypeEvalContext)) {
|
||||
registerProblem(
|
||||
node.getArgumentList(),
|
||||
PyBundle.message("INSP.$0.is.not.superclass.of.$1",
|
||||
|
||||
@@ -96,8 +96,9 @@ public class AddMethodQuickFix implements LocalQuickFix {
|
||||
boolean madeInstance = false;
|
||||
if (callByClass) {
|
||||
if (args.length > 0) {
|
||||
PyType firstArgType = TypeEvalContext.userInitiated(cls.getProject(), cls.getContainingFile()).getType(args[0]);
|
||||
if (firstArgType instanceof PyClassType && ((PyClassType)firstArgType).getPyClass().isSubclass(cls, null)) {
|
||||
final TypeEvalContext context = TypeEvalContext.userInitiated(cls.getProject(), cls.getContainingFile());
|
||||
final PyType firstArgType = context.getType(args[0]);
|
||||
if (firstArgType instanceof PyClassType && ((PyClassType)firstArgType).getPyClass().isSubclass(cls, context)) {
|
||||
// class, first arg ok: instance method
|
||||
builder.parameter("self"); // NOTE: might use a name other than 'self', according to code style.
|
||||
madeInstance = true;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.jetbrains.python.psi.impl;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -367,7 +366,7 @@ public class PyCallExpressionHelper {
|
||||
PyClass resolvedParent = PsiTreeUtil.getStubOrPsiParentOfType(resolved, PyClass.class);
|
||||
if (resolvedParent != null) {
|
||||
final PyClass qualifierClass = ((PyClassType)qualifierType).getPyClass();
|
||||
if ((qualifierClass.isSubclass(resolvedParent, null) || resolvedParent.isSubclass(qualifierClass, null))) {
|
||||
if ((qualifierClass.isSubclass(resolvedParent, context) || resolvedParent.isSubclass(qualifierClass, context))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,8 +501,7 @@ public class PyQualifiedReference extends PyReferenceImpl {
|
||||
PyClass aClass = PsiTreeUtil.getParentOfType(resolveResult, PyClass.class);
|
||||
PyClass bClass = PsiTreeUtil.getParentOfType(element, PyClass.class);
|
||||
|
||||
if (isSubclass(aClass, bClass)
|
||||
|| (isSubclass(bClass, aClass))) {
|
||||
if (aClass != null && bClass != null && bClass.isSubclass(aClass, myContext.getTypeEvalContext())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -513,13 +512,6 @@ public class PyQualifiedReference extends PyReferenceImpl {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isSubclass(@Nullable PyClass aClass, @Nullable PyClass bClass) {
|
||||
if (aClass == null || bClass == null) {
|
||||
return false;
|
||||
}
|
||||
return bClass.isSubclass(aClass, null);
|
||||
}
|
||||
|
||||
private static boolean isLocalScope(PsiElement element) {
|
||||
if (element instanceof PyParameter) {
|
||||
return true;
|
||||
|
||||
@@ -530,7 +530,8 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference
|
||||
if (PyUtil.isClassAttribute(myElement) && (PyUtil.isClassAttribute(expr) || PyUtil.isInstanceAttribute(expr))) {
|
||||
final PyClass c1 = PsiTreeUtil.getParentOfType(element, PyClass.class);
|
||||
final PyClass c2 = PsiTreeUtil.getParentOfType(myElement, PyClass.class);
|
||||
if (c1 != null && c2 != null && (c1.isSubclass(c2, null) || c2.isSubclass(c1, null))) {
|
||||
final TypeEvalContext context = myContext.getTypeEvalContext();
|
||||
if (c1 != null && c2 != null && (c1.isSubclass(c2, context) || c2.isSubclass(c1, context))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class PySuperMethodsSearchExecutor implements QueryExecutor<PsiElement, P
|
||||
if (!queryParameters.isDeepSearch()) {
|
||||
boolean isAlreadyFound = false;
|
||||
for (PyClass alreadyFound : foundMethodContainingClasses) {
|
||||
if (alreadyFound.isSubclass(superClass, null)) {
|
||||
if (alreadyFound.isSubclass(superClass, context)) {
|
||||
isAlreadyFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user