mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
update usages after converting static method to function
This commit is contained in:
+12
-1
@@ -6,12 +6,16 @@ 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.intellij.util.IncorrectOperationException;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.refactoring.PyRefactoringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: ktisha
|
||||
*/
|
||||
@@ -49,7 +53,7 @@ public class PyConvertStaticMethodToFunctionIntention extends BaseIntentionActio
|
||||
if (problemFunction == null) return;
|
||||
final PyClass containingClass = problemFunction.getContainingClass();
|
||||
if (containingClass == null) return;
|
||||
|
||||
final List<UsageInfo> usages = PyRefactoringUtil.findUsages(problemFunction, false);
|
||||
final PyDecoratorList decoratorList = problemFunction.getDecoratorList();
|
||||
if (decoratorList != null) {
|
||||
final PyDecorator decorator = decoratorList.findDecorator(PyNames.STATICMETHOD);
|
||||
@@ -64,5 +68,12 @@ public class PyConvertStaticMethodToFunctionIntention extends BaseIntentionActio
|
||||
classStatementList.add(generator.createPassStatement());
|
||||
}
|
||||
file.addAfter(copy, containingClass);
|
||||
|
||||
for (UsageInfo usage : usages) {
|
||||
final PsiElement usageElement = usage.getElement();
|
||||
if (usageElement instanceof PyReferenceExpression) {
|
||||
PyUtil.removeQualifier((PyReferenceExpression)usageElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
class MyClass(object):
|
||||
"""
|
||||
My class to show intention.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.a = 1
|
||||
|
||||
|
||||
def my_static_method():
|
||||
import code
|
||||
import time
|
||||
|
||||
time.sleep(100)
|
||||
print code
|
||||
|
||||
|
||||
my_static_method()
|
||||
@@ -0,0 +1,17 @@
|
||||
class MyClass(object):
|
||||
"""
|
||||
My class to show intention.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.a = 1
|
||||
|
||||
@staticmethod
|
||||
def my_<caret>static_method():
|
||||
import code
|
||||
import time
|
||||
|
||||
time.sleep(100)
|
||||
print code
|
||||
|
||||
MyClass().my_static_method()
|
||||
@@ -402,6 +402,10 @@ public class PyIntentionTest extends PyTestCase {
|
||||
doTest(PyBundle.message("INTN.convert.static.method.to.function"));
|
||||
}
|
||||
|
||||
public void testConvertStaticMethodToFunctionUsage() {
|
||||
doTest(PyBundle.message("INTN.convert.static.method.to.function"));
|
||||
}
|
||||
|
||||
private void doDocStubTest(LanguageLevel languageLevel) {
|
||||
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), languageLevel);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user