mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
update usages after converting method to function
This commit is contained in:
@@ -6,11 +6,15 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.refactoring.PyRefactoringUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: ktisha
|
||||
*/
|
||||
@@ -36,6 +40,7 @@ public class PyMakeFunctionFromMethodQuickFix implements LocalQuickFix {
|
||||
final PyClass containingClass = problemFunction.getContainingClass();
|
||||
if (containingClass == null) return;
|
||||
|
||||
final List<UsageInfo> usages = PyRefactoringUtil.findUsages(problemFunction, false);
|
||||
PyUtil.deleteParameter(problemFunction, 0);
|
||||
|
||||
final PsiElement copy = problemFunction.copy();
|
||||
@@ -46,5 +51,12 @@ public class PyMakeFunctionFromMethodQuickFix implements LocalQuickFix {
|
||||
}
|
||||
final PsiFile file = containingClass.getContainingFile();
|
||||
file.addAfter(copy, containingClass);
|
||||
|
||||
for (UsageInfo usage : usages) {
|
||||
final PsiElement usageElement = usage.getElement();
|
||||
if (usageElement instanceof PyReferenceExpression) {
|
||||
PyUtil.removeQualifier((PyReferenceExpression)usageElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,6 +656,15 @@ public class PyUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void removeQualifier(PyReferenceExpression element) {
|
||||
final PyExpression qualifier = element.getQualifier();
|
||||
if (qualifier != null) {
|
||||
final PsiElement dot = qualifier.getNextSibling();
|
||||
if (dot != null) dot.delete();
|
||||
qualifier.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static class KnownDecoratorProviderHolder {
|
||||
public static PyKnownDecoratorProvider[] KNOWN_DECORATOR_PROVIDERS = Extensions.getExtensions(PyKnownDecoratorProvider.EP_NAME);
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
__author__ = 'ktisha'
|
||||
|
||||
class A:
|
||||
def fo<caret>o(self):
|
||||
print("Hello Pycharm!")
|
||||
|
||||
A().foo()
|
||||
@@ -0,0 +1,10 @@
|
||||
__author__ = 'ktisha'
|
||||
|
||||
class A: pass
|
||||
|
||||
|
||||
def foo():
|
||||
print("Hello Pycharm!")
|
||||
|
||||
|
||||
foo()
|
||||
@@ -32,4 +32,8 @@ public class PyMakeFunctionFromMethodQuickFixTest extends PyQuickFixTestCase {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
}
|
||||
|
||||
public void testUpdateUsage() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user