fixed PY-15437 Exception when converting method to function

This commit is contained in:
Ekaterina Tuzova
2015-04-23 15:33:33 +03:00
parent 96c8dd942c
commit b0384b7f67
4 changed files with 17 additions and 3 deletions
@@ -67,17 +67,17 @@ public class PyMakeFunctionFromMethodQuickFix implements LocalQuickFix {
PsiElement copy = problemFunction.copy();
problemFunction.delete();
final PsiFile file = containingClass.getContainingFile();
final PsiElement parent = containingClass.getParent();
PyClass aClass = PsiTreeUtil.getTopmostParentOfType(containingClass, PyClass.class);
if (aClass == null)
aClass = containingClass;
copy = file.addBefore(copy, aClass);
copy = parent.addBefore(copy, aClass);
for (UsageInfo usage : usages) {
final PsiElement usageElement = usage.getElement();
if (usageElement instanceof PyReferenceExpression) {
final PsiFile usageFile = usageElement.getContainingFile();
updateUsage(copy, (PyReferenceExpression)usageElement, usageFile, !usageFile.equals(file));
updateUsage(copy, (PyReferenceExpression)usageElement, usageFile, !usageFile.equals(parent));
}
}
}
@@ -0,0 +1,4 @@
def make_server(config):
class Handler(object):
def method_<caret>name2(self, x):
x.send_error(404, 'File not found')
@@ -0,0 +1,6 @@
def make_server(config):
def method_name2(x):
x.send_error(404, 'File not found')
class Handler(object):
pass
@@ -75,4 +75,8 @@ public class PyMakeFunctionFromMethodQuickFixTest extends PyQuickFixTestCase {
public void testUsageSelf() {
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
}
public void testLocalClass() {
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
}
}