From 655cd59f5bfa9b6008a59591abed35eb84bd4a83 Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Sun, 16 May 2010 15:29:11 +0400 Subject: [PATCH] PY-995 fix introduce* incorrectly working with assignment left part --- .../refactoring/introduce/IntroduceHandler.java | 6 +++++- .../refactoring/introduceVariable/py995.after.py | 4 ++++ .../testData/refactoring/introduceVariable/py995.py | 3 +++ .../python/refactoring/PyIntroduceVariableTest.java | 12 ++++++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 python/testData/refactoring/introduceVariable/py995.after.py create mode 100644 python/testData/refactoring/introduceVariable/py995.py diff --git a/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java b/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java index 0a573d939b92..50120ac11604 100644 --- a/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java +++ b/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java @@ -175,7 +175,10 @@ abstract public class IntroduceHandler implements RefactoringActionHandler { return; } - final PyExpression expression = (PyExpression)element; + final PsiElement parent = element.getParent(); + final PyExpression expression = parent instanceof PyAssignmentStatement ? + ((PyAssignmentStatement)parent).getAssignedValue() : + (PyExpression)element; final List occurrences; if (expression.getUserData(PyPsiUtils.SELECTION_BREAKS_AST_NODE) == null && !(expression instanceof PyCallExpression)) { @@ -185,6 +188,7 @@ abstract public class IntroduceHandler implements RefactoringActionHandler { occurrences = Collections.emptyList(); } String[] possibleNames = getSuggestedNames(expression); + replaceAll &= occurrences.size() > 0; boolean initInConstructor = false; if (name == null) { PyIntroduceDialog dialog = new PyIntroduceDialog(project, expression, myDialogTitle, myValidator, occurrences.size(), possibleNames, getHelpId(), hasConstructor); diff --git a/python/testData/refactoring/introduceVariable/py995.after.py b/python/testData/refactoring/introduceVariable/py995.after.py new file mode 100644 index 000000000000..617b9f339f69 --- /dev/null +++ b/python/testData/refactoring/introduceVariable/py995.after.py @@ -0,0 +1,4 @@ +class ConferenceTest(TestCase): + def testSimple(self): + a = Conference() + c = a \ No newline at end of file diff --git a/python/testData/refactoring/introduceVariable/py995.py b/python/testData/refactoring/introduceVariable/py995.py new file mode 100644 index 000000000000..090081ec0b3e --- /dev/null +++ b/python/testData/refactoring/introduceVariable/py995.py @@ -0,0 +1,3 @@ +class ConferenceTest(TestCase): + def testSimple(self): + c = Conference() \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceVariableTest.java b/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceVariableTest.java index 19d6cf72452d..f161ac20295f 100644 --- a/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceVariableTest.java +++ b/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceVariableTest.java @@ -13,9 +13,17 @@ public class PyIntroduceVariableTest extends PyLightFixtureTestCase { } public void testSimple() throws Exception { - myFixture.configureByFile("simple.py"); + doTest(); + } + + public void testPy995() throws Exception { + doTest(); + } + + private void doTest() throws Exception { + myFixture.configureByFile(getTestName(true) + ".py"); VariableIntroduceHandler handler = new VariableIntroduceHandler(); handler.performAction(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile(), "a", true, false); - myFixture.checkResultByFile("simple.after.py"); + myFixture.checkResultByFile(getTestName(true) + ".after.py"); } }