mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-15437 Exception when converting method to function
This commit is contained in:
+3
-3
@@ -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
|
||||
+4
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user