PY-995 fix introduce* incorrectly working with assignment left part

This commit is contained in:
Dennis Ushakov
2010-05-16 15:29:11 +04:00
parent 1f56dab2e2
commit 655cd59f5b
4 changed files with 22 additions and 3 deletions
@@ -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<PsiElement> 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);
@@ -0,0 +1,4 @@
class ConferenceTest(TestCase):
def testSimple(self):
a = Conference()
c = a
@@ -0,0 +1,3 @@
class ConferenceTest(TestCase):
def testSimple(self):
<selection>c</selection> = Conference()
@@ -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");
}
}