From 66fb8155a1c819b2579724902b6ead3d27ed86e0 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Thu, 6 Mar 2014 18:15:35 +0400 Subject: [PATCH] renamed resolveWithoutImplicits to getResolveContext (which is more meaningfull) --- .../PyArgumentEqualDefaultInspection.java | 8 +++---- .../inspections/PyArgumentListInspection.java | 2 +- .../inspections/PyCallByClassInspection.java | 2 +- .../inspections/PyDeprecationInspection.java | 2 +- .../PyExceptClausesOrderInspection.java | 2 +- .../PyExceptionInheritInspection.java | 2 +- .../inspections/PyInspectionVisitor.java | 2 +- .../PyPropertyDefinitionInspection.java | 4 ++-- .../PyProtectedMemberInspection.java | 22 ++++++++++--------- .../PyRaisingNewStyleClassInspection.java | 2 +- .../PyStatementEffectInspection.java | 6 ++--- .../PySuperArgumentsInspection.java | 2 +- .../PyTupleItemAssignmentInspection.java | 2 +- .../PyUnboundLocalVariableInspection.java | 2 +- 14 files changed, 31 insertions(+), 29 deletions(-) diff --git a/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java b/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java index 9b8b0891764d..2f694b69179b 100644 --- a/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java @@ -73,11 +73,11 @@ public class PyArgumentEqualDefaultInspection extends PyInspection { if (list == null) { return; } - Callable func = node.resolveCalleeFunction(resolveWithoutImplicits()); + Callable func = node.resolveCalleeFunction(getResolveContext()); if (func != null && hasSpecialCasedDefaults(func, node)) { return; } - CallArgumentsMapping result = list.analyzeCall(resolveWithoutImplicits()); + CallArgumentsMapping result = list.analyzeCall(getResolveContext()); checkArguments(result, node.getArguments()); } @@ -141,10 +141,10 @@ public class PyArgumentEqualDefaultInspection extends PyInspection { } else { PsiReference keyRef = key instanceof PyReferenceExpression - ? ((PyReferenceExpression) key).getReference(resolveWithoutImplicits()) + ? ((PyReferenceExpression) key).getReference(getResolveContext()) : key.getReference(); PsiReference defRef = defaultValue instanceof PyReferenceExpression - ? ((PyReferenceExpression) defaultValue).getReference(resolveWithoutImplicits()) + ? ((PyReferenceExpression) defaultValue).getReference(getResolveContext()) : defaultValue.getReference(); if (keyRef != null && defRef != null) { PsiElement keyResolve = keyRef.resolve(); diff --git a/python/src/com/jetbrains/python/inspections/PyArgumentListInspection.java b/python/src/com/jetbrains/python/inspections/PyArgumentListInspection.java index 9a87959396fe..1edb6ef56b67 100644 --- a/python/src/com/jetbrains/python/inspections/PyArgumentListInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyArgumentListInspection.java @@ -71,7 +71,7 @@ public class PyArgumentListInspection extends PyInspection { PyDecorator[] decorators = node.getDecorators(); for (PyDecorator deco : decorators) { if (deco.hasArgumentList()) continue; - final PyCallExpression.PyMarkedCallee markedCallee = deco.resolveCallee(resolveWithoutImplicits()); + final PyCallExpression.PyMarkedCallee markedCallee = deco.resolveCallee(getResolveContext()); if (markedCallee != null && !markedCallee.isImplicitlyResolved()) { final Callable callable = markedCallee.getCallable(); int firstParamOffset = markedCallee.getImplicitOffset(); diff --git a/python/src/com/jetbrains/python/inspections/PyCallByClassInspection.java b/python/src/com/jetbrains/python/inspections/PyCallByClassInspection.java index 38128487234d..9b0526881b27 100644 --- a/python/src/com/jetbrains/python/inspections/PyCallByClassInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyCallByClassInspection.java @@ -90,7 +90,7 @@ public class PyCallByClassInspection extends PyInspection { PyClass qual_class = qual_class_type.getPyClass(); final PyArgumentList arglist = call.getArgumentList(); if (arglist != null) { - CallArgumentsMapping analysis = arglist.analyzeCall(resolveWithoutImplicits()); + CallArgumentsMapping analysis = arglist.analyzeCall(getResolveContext()); final PyCallExpression.PyMarkedCallee markedCallee = analysis.getMarkedCallee(); if (markedCallee != null && markedCallee.getModifier() != STATICMETHOD) { final List params = PyUtil.getParameters(markedCallee.getCallable(), myTypeEvalContext); diff --git a/python/src/com/jetbrains/python/inspections/PyDeprecationInspection.java b/python/src/com/jetbrains/python/inspections/PyDeprecationInspection.java index 368b893e80a4..fc60616b5fe7 100644 --- a/python/src/com/jetbrains/python/inspections/PyDeprecationInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyDeprecationInspection.java @@ -58,7 +58,7 @@ public class PyDeprecationInspection extends PyInspection { final PyExpression exceptClass = exceptPart.getExceptClass(); if (exceptClass != null && "ImportError".equals(exceptClass.getText())) return; } - PsiElement resolveResult = node.getReference(resolveWithoutImplicits()).resolve(); + PsiElement resolveResult = node.getReference(getResolveContext()).resolve(); String deprecationMessage = null; if (resolveResult instanceof PyFunction) { deprecationMessage = ((PyFunction) resolveResult).getDeprecationMessage(); diff --git a/python/src/com/jetbrains/python/inspections/PyExceptClausesOrderInspection.java b/python/src/com/jetbrains/python/inspections/PyExceptClausesOrderInspection.java index 4d8ffa75de7a..f945a8c6f56b 100644 --- a/python/src/com/jetbrains/python/inspections/PyExceptClausesOrderInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyExceptClausesOrderInspection.java @@ -58,7 +58,7 @@ public class PyExceptClausesOrderInspection extends PyInspection { for (PyExceptPart exceptPart : exceptParts) { PyExpression exceptClass = exceptPart.getExceptClass(); if (exceptClass instanceof PyReferenceExpression) { - PsiElement element = ((PyReferenceExpression) exceptClass).followAssignmentsChain(resolveWithoutImplicits()).getElement(); + PsiElement element = ((PyReferenceExpression) exceptClass).followAssignmentsChain(getResolveContext()).getElement(); if (element instanceof PyClass) { PyClass pyClass = (PyClass)element; if (exceptClasses.contains(pyClass)) { diff --git a/python/src/com/jetbrains/python/inspections/PyExceptionInheritInspection.java b/python/src/com/jetbrains/python/inspections/PyExceptionInheritInspection.java index f89d530bb9b0..6ece46395030 100644 --- a/python/src/com/jetbrains/python/inspections/PyExceptionInheritInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyExceptionInheritInspection.java @@ -60,7 +60,7 @@ public class PyExceptionInheritInspection extends PyInspection { if (expression instanceof PyCallExpression) { PyExpression callee = ((PyCallExpression)expression).getCallee(); if (callee instanceof PyReferenceExpression) { - PsiElement psiElement = ((PyReferenceExpression)callee).getReference(resolveWithoutImplicits()).resolve(); + PsiElement psiElement = ((PyReferenceExpression)callee).getReference(getResolveContext()).resolve(); if (psiElement instanceof PyClass) { PyClass aClass = (PyClass) psiElement; for (PyClassLikeType type : aClass.getAncestorTypes(myTypeEvalContext)) { diff --git a/python/src/com/jetbrains/python/inspections/PyInspectionVisitor.java b/python/src/com/jetbrains/python/inspections/PyInspectionVisitor.java index 3b8d499dcc68..4584f06ae8d9 100644 --- a/python/src/com/jetbrains/python/inspections/PyInspectionVisitor.java +++ b/python/src/com/jetbrains/python/inspections/PyInspectionVisitor.java @@ -52,7 +52,7 @@ public abstract class PyInspectionVisitor extends PyElementVisitor { myTypeEvalContext = context; } - protected PyResolveContext resolveWithoutImplicits() { + protected PyResolveContext getResolveContext() { return PyResolveContext.noImplicits().withTypeEvalContext(myTypeEvalContext); } diff --git a/python/src/com/jetbrains/python/inspections/PyPropertyDefinitionInspection.java b/python/src/com/jetbrains/python/inspections/PyPropertyDefinitionInspection.java index 967e6a47c26d..08cfe9d168b1 100644 --- a/python/src/com/jetbrains/python/inspections/PyPropertyDefinitionInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyPropertyDefinitionInspection.java @@ -124,7 +124,7 @@ public class PyPropertyDefinitionInspection extends PyInspection { assert call != null : "Property has a null call assigned to it"; final PyArgumentList arglist = call.getArgumentList(); assert arglist != null : "Property call has null arglist"; - CallArgumentsMapping analysis = arglist.analyzeCall(resolveWithoutImplicits()); + CallArgumentsMapping analysis = arglist.analyzeCall(getResolveContext()); // we assume fget, fset, fdel, doc names for (Map.Entry entry: analysis.getPlainMappedParams().entrySet()) { final String param_name = entry.getValue().getName(); @@ -150,7 +150,7 @@ public class PyPropertyDefinitionInspection extends PyInspection { assert argument != null : "Parameter mapped to null argument"; Callable callable = null; if (argument instanceof PyReferenceExpression) { - PsiElement resolved = ((PyReferenceExpression)argument).getReference(resolveWithoutImplicits()).resolve(); + PsiElement resolved = ((PyReferenceExpression)argument).getReference(getResolveContext()).resolve(); if (resolved instanceof Callable) { callable = (Callable)resolved; } diff --git a/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java b/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java index fe9ac7f9159e..cf4fc7976ce2 100644 --- a/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java @@ -70,18 +70,20 @@ public class PyProtectedMemberInspection extends PyInspection { if (name != null && name.startsWith("_") && !name.startsWith("__") && !name.endsWith("__")) { final PyClass parentClass = getClassOwner(node); if (parentClass != null) { - final PsiReference reference = node.getReference(); - final PsiElement resolvedExpression = reference.resolve(); - final PyClass resolvedClass = getClassOwner(resolvedExpression); - if (parentClass.isSubclass(resolvedClass)) - return; - - PyClass outerClass = getClassOwner(parentClass); - while (outerClass != null) { - if (outerClass.isSubclass(resolvedClass)) + final PsiReference reference = node.getReference(getResolveContext()); + if (reference != null) { + final PsiElement resolvedExpression = reference.resolve(); + final PyClass resolvedClass = getClassOwner(resolvedExpression); + if (parentClass.isSubclass(resolvedClass)) return; - outerClass = getClassOwner(outerClass); + PyClass outerClass = getClassOwner(parentClass); + while (outerClass != null) { + if (outerClass.isSubclass(resolvedClass)) + return; + + outerClass = getClassOwner(outerClass); + } } } final PyType type = myTypeEvalContext.getType(qualifier); diff --git a/python/src/com/jetbrains/python/inspections/PyRaisingNewStyleClassInspection.java b/python/src/com/jetbrains/python/inspections/PyRaisingNewStyleClassInspection.java index 40adf777e664..15c4c42f2c01 100644 --- a/python/src/com/jetbrains/python/inspections/PyRaisingNewStyleClassInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyRaisingNewStyleClassInspection.java @@ -67,7 +67,7 @@ public class PyRaisingNewStyleClassInspection extends PyInspection { if (expression instanceof PyCallExpression) { final PyExpression callee = ((PyCallExpression)expression).getCallee(); if (callee instanceof PyReferenceExpression) { - final PsiElement psiElement = ((PyReferenceExpression)callee).getReference(resolveWithoutImplicits()).resolve(); + final PsiElement psiElement = ((PyReferenceExpression)callee).getReference(getResolveContext()).resolve(); if (psiElement instanceof PyClass) { if (((PyClass)psiElement).isNewStyleClass()) { registerProblem(expression, "Raising a new style class"); diff --git a/python/src/com/jetbrains/python/inspections/PyStatementEffectInspection.java b/python/src/com/jetbrains/python/inspections/PyStatementEffectInspection.java index 28ccafd5aa12..2e519b566a94 100644 --- a/python/src/com/jetbrains/python/inspections/PyStatementEffectInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyStatementEffectInspection.java @@ -112,14 +112,14 @@ public class PyStatementEffectInspection extends PyInspection { PyType type = myTypeEvalContext.getType(leftExpression); if (type != null && !type.isBuiltin(myTypeEvalContext) && - type.resolveMember(method, null, AccessDirection.READ, resolveWithoutImplicits()) != null) { + type.resolveMember(method, null, AccessDirection.READ, getResolveContext()) != null) { return true; } if (rightExpression != null) { type = myTypeEvalContext.getType(rightExpression); if (type != null) { String rmethod = "__r" + method.substring(2); // __add__ -> __radd__ - if (!type.isBuiltin(myTypeEvalContext) && type.resolveMember(rmethod, null, AccessDirection.READ, resolveWithoutImplicits()) != null) { + if (!type.isBuiltin(myTypeEvalContext) && type.resolveMember(rmethod, null, AccessDirection.READ, getResolveContext()) != null) { return true; } } @@ -136,7 +136,7 @@ public class PyStatementEffectInspection extends PyInspection { } else if (expression instanceof PyReferenceExpression) { PyReferenceExpression referenceExpression = (PyReferenceExpression)expression; - ResolveResult[] results = referenceExpression.getReference(resolveWithoutImplicits()).multiResolve(true); + ResolveResult[] results = referenceExpression.getReference(getResolveContext()).multiResolve(true); for (ResolveResult res : results) { if (res.getElement() instanceof PyFunction) { registerProblem(expression, "Statement seems to have no effect and can be replaced with function call to have effect", new StatementEffectFunctionCallQuickFix()); diff --git a/python/src/com/jetbrains/python/inspections/PySuperArgumentsInspection.java b/python/src/com/jetbrains/python/inspections/PySuperArgumentsInspection.java index b47650711078..c5dbb79aac81 100644 --- a/python/src/com/jetbrains/python/inspections/PySuperArgumentsInspection.java +++ b/python/src/com/jetbrains/python/inspections/PySuperArgumentsInspection.java @@ -81,7 +81,7 @@ public class PySuperArgumentsInspection extends PyInspection { @Nullable private PyClass findClassOf(PyExpression argument) { - PsiElement firstElement = ((PyReferenceExpression)argument).followAssignmentsChain(resolveWithoutImplicits()).getElement(); + PsiElement firstElement = ((PyReferenceExpression)argument).followAssignmentsChain(getResolveContext()).getElement(); PyClass firstClass = null; if (firstElement instanceof PyClass) firstClass = (PyClass)firstElement; else if (firstElement instanceof PyExpression) { diff --git a/python/src/com/jetbrains/python/inspections/PyTupleItemAssignmentInspection.java b/python/src/com/jetbrains/python/inspections/PyTupleItemAssignmentInspection.java index 256783326dde..3416b5076ca4 100644 --- a/python/src/com/jetbrains/python/inspections/PyTupleItemAssignmentInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyTupleItemAssignmentInspection.java @@ -59,7 +59,7 @@ public class PyTupleItemAssignmentInspection extends PyInspection { PySubscriptionExpression subscriptionExpression = (PySubscriptionExpression)targets[0]; if (subscriptionExpression.getOperand() instanceof PyReferenceExpression) { PyReferenceExpression referenceExpression = (PyReferenceExpression)subscriptionExpression.getOperand(); - PsiElement element = referenceExpression.followAssignmentsChain(resolveWithoutImplicits()).getElement(); + PsiElement element = referenceExpression.followAssignmentsChain(getResolveContext()).getElement(); if (element instanceof PyExpression) { PyExpression expression = (PyExpression)element; PyType type = myTypeEvalContext.getType(expression); diff --git a/python/src/com/jetbrains/python/inspections/PyUnboundLocalVariableInspection.java b/python/src/com/jetbrains/python/inspections/PyUnboundLocalVariableInspection.java index 9e0031afec84..a3411f3976c3 100644 --- a/python/src/com/jetbrains/python/inspections/PyUnboundLocalVariableInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyUnboundLocalVariableInspection.java @@ -127,7 +127,7 @@ public class PyUnboundLocalVariableInspection extends PyInspection { if (!isFirstUnboundRead(node, owner)) { return; } - final PsiPolyVariantReference ref = node.getReference(resolveWithoutImplicits()); + final PsiPolyVariantReference ref = node.getReference(getResolveContext()); if (ref == null) { return; }