mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Use TypeEvalContext for getting ancestor classes if it's available
This commit is contained in:
@@ -65,7 +65,7 @@ public class PyAttributeOutsideInitInspection extends PyInspection {
|
||||
collectAttributesFromSuper(attributesInInit, initMethod);
|
||||
}
|
||||
else {
|
||||
for (PyClass superClass : containingClass.getAncestorClasses()) {
|
||||
for (PyClass superClass : containingClass.getAncestorClasses(myTypeEvalContext)) {
|
||||
final PyFunction superInit = superClass.findMethodByName(PyNames.INIT, false);
|
||||
if (superInit != null)
|
||||
PyClassImpl.collectInstanceAttributes(superInit, attributesInInit);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class PyClassHasNoInitInspection extends PyInspection {
|
||||
registerProblem(node.getNameIdentifier(), PyBundle.message("INSP.class.has.no.init"),
|
||||
new AddMethodQuickFix("__init__", new PyClassTypeImpl(node, false), false));
|
||||
}
|
||||
for (PyClass ancestor : node.getAncestorClasses()) {
|
||||
for (PyClass ancestor : node.getAncestorClasses(myTypeEvalContext)) {
|
||||
final PyFunction ancestorInit = ancestor.findInitOrNew(false);
|
||||
if (ancestorInit == null) {
|
||||
registerProblem(node.getNameIdentifier(), PyBundle.message("INSP.parent.$0.has.no.init", ancestor.getName()),
|
||||
|
||||
@@ -61,8 +61,8 @@ public class PyMissingConstructorInspection extends PyInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean superHasConstructor(@NotNull PyClass cls) {
|
||||
for (PyClass c : cls.getAncestorClasses()) {
|
||||
private boolean superHasConstructor(@NotNull PyClass cls) {
|
||||
for (PyClass c : cls.getAncestorClasses(myTypeEvalContext)) {
|
||||
final String name = c.getName();
|
||||
final String className = cls.getName();
|
||||
if (!OBJECT.equals(name) && !FAKE_OLD_BASE.equals(name) && className != null &&
|
||||
@@ -77,7 +77,7 @@ public class PyMissingConstructorInspection extends PyInspection {
|
||||
if (PyBroadExceptionInspection.equalsException(cls, context)) {
|
||||
return true;
|
||||
}
|
||||
for (PyClass baseClass : cls.getAncestorClasses()) {
|
||||
for (PyClass baseClass : cls.getAncestorClasses(myTypeEvalContext)) {
|
||||
if (PyBroadExceptionInspection.equalsException(baseClass, context)) {
|
||||
return true;
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class PyMissingConstructorInspection extends PyInspection {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean hasConstructorCall(PyClass node, PyFunction initMethod) {
|
||||
private boolean hasConstructorCall(PyClass node, PyFunction initMethod) {
|
||||
PyStatementList statementList = initMethod.getStatementList();
|
||||
CallVisitor visitor = new CallVisitor(node);
|
||||
if (statementList != null) {
|
||||
@@ -95,7 +95,7 @@ public class PyMissingConstructorInspection extends PyInspection {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class CallVisitor extends PyRecursiveElementVisitor {
|
||||
private class CallVisitor extends PyRecursiveElementVisitor {
|
||||
private boolean myHasConstructorCall = false;
|
||||
private PyClass myClass;
|
||||
CallVisitor(PyClass node) {
|
||||
@@ -108,7 +108,7 @@ public class PyMissingConstructorInspection extends PyInspection {
|
||||
myHasConstructorCall = true;
|
||||
}
|
||||
|
||||
private static boolean isConstructorCall(PyCallExpression expression, PyClass cl) {
|
||||
private boolean isConstructorCall(PyCallExpression expression, PyClass cl) {
|
||||
PyExpression callee = expression.getCallee();
|
||||
if (callee instanceof PyQualifiedExpression) {
|
||||
PyExpression qualifier = ((PyQualifiedExpression)callee).getQualifier();
|
||||
@@ -127,7 +127,7 @@ public class PyMissingConstructorInspection extends PyInspection {
|
||||
if (firstArg.equals(cl.getName()) || firstArg.equals(CANONICAL_SELF+"."+ CLASS) ||
|
||||
(qualifiedName != null && qualifiedName.endsWith(firstArg)))
|
||||
return true;
|
||||
for (PyClass s : cl.getAncestorClasses()) {
|
||||
for (PyClass s : cl.getAncestorClasses(myTypeEvalContext)) {
|
||||
if (firstArg.equals(s.getName()))
|
||||
return true;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class PyMissingConstructorInspection extends PyInspection {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isSuperClassCall(PyClass cl, PyExpression qualifier) {
|
||||
private boolean isSuperClassCall(PyClass cl, PyExpression qualifier) {
|
||||
PsiElement callingClass = null;
|
||||
if (qualifier instanceof PyCallExpression) {
|
||||
PyExpression innerCallee = ((PyCallExpression)qualifier).getCallee();
|
||||
@@ -159,7 +159,7 @@ public class PyMissingConstructorInspection extends PyInspection {
|
||||
if (ref != null)
|
||||
callingClass = ref.resolve();
|
||||
}
|
||||
for (PyClass s : cl.getAncestorClasses()) {
|
||||
for (PyClass s : cl.getAncestorClasses(myTypeEvalContext)) {
|
||||
if (s.equals(callingClass)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
final List<String> slots = pyClass.getSlots();
|
||||
final String attrName = node.getReferencedName();
|
||||
if (slots != null && !slots.contains(attrName) && !slots.contains(PyNames.DICT)) {
|
||||
for (PyClass ancestor : pyClass.getAncestorClasses()) {
|
||||
for (PyClass ancestor : pyClass.getAncestorClasses(myTypeEvalContext)) {
|
||||
if (ancestor == null) {
|
||||
return;
|
||||
}
|
||||
@@ -628,7 +628,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean ignoreUnresolvedMemberForType(@NotNull PyType qtype, PsiReference reference, String refText) {
|
||||
private boolean ignoreUnresolvedMemberForType(@NotNull PyType qtype, PsiReference reference, String refText) {
|
||||
if (qtype instanceof PyNoneType || PyTypeChecker.isUnknown(qtype)) {
|
||||
// this almost always means that we don't know the type, so don't show an error in this case
|
||||
return true;
|
||||
@@ -667,12 +667,12 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isDecoratedAsDynamic(@NotNull PyClass cls, boolean inherited) {
|
||||
private boolean isDecoratedAsDynamic(@NotNull PyClass cls, boolean inherited) {
|
||||
if (inherited) {
|
||||
if (isDecoratedAsDynamic(cls, false)) {
|
||||
return true;
|
||||
}
|
||||
for (PyClass base : cls.getAncestorClasses()) {
|
||||
for (PyClass base : cls.getAncestorClasses(myTypeEvalContext)) {
|
||||
if (base != null && isDecoratedAsDynamic(base, false)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -505,7 +505,7 @@ public class PyCallExpressionHelper {
|
||||
return getSuperClassUnionType(firstClass);
|
||||
}
|
||||
if (secondClass.isSubclass(firstClass)) {
|
||||
final Iterator<PyClass> iterator = firstClass.getAncestorClasses().iterator();
|
||||
final Iterator<PyClass> iterator = firstClass.getAncestorClasses(context).iterator();
|
||||
if (iterator.hasNext()) {
|
||||
return new PyClassTypeImpl(iterator.next(), false); // super(Foo, self) has type of Foo, modulo __get__()
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference
|
||||
it.set(rrr.replace(init));
|
||||
}
|
||||
else { // init not found; maybe it's ancestor's
|
||||
for (PyClass ancestor : cls.getAncestorClasses()) {
|
||||
for (PyClass ancestor : cls.getAncestorClasses(myContext.getTypeEvalContext())) {
|
||||
init = ancestor.findMethodByName(PyNames.INIT, false);
|
||||
if (init != null) {
|
||||
// add to results as low priority
|
||||
|
||||
@@ -155,7 +155,7 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType {
|
||||
PyType first_arg_type = context.getType(first_arg);
|
||||
if (first_arg_type instanceof PyClassType) {
|
||||
PyClass derived_class = ((PyClassType)first_arg_type).getPyClass();
|
||||
final Iterator<PyClass> base_it = derived_class.getAncestorClasses().iterator();
|
||||
final Iterator<PyClass> base_it = derived_class.getAncestorClasses(context).iterator();
|
||||
if (base_it.hasNext()) {
|
||||
return new PyClassTypeImpl(base_it.next(), true).resolveMember(name, location, direction, resolveContext);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user